I downloaded and installed the quick scripts from the IBFX website. They work fine in their default settings. The problem is they don't work when I alter them to enter trades with a specific lot size per trade rather than the script determining lot sizing based on percentage of margin.
Here is the complete code:
//+-------------------------------------------------------------------------+
//| IBFX - Quick Sell.mq4 |
//+-------------------------------------------------------------------------+
#property copyright "Copyright 2008, ibfx.com"
#property link "www.ibfx.com"
//----
int start()
{
/*+-------------------------------------------------------------------+
Because these scripts are meant to execute fast there are no user
external inputs. Make sure to modify the settings below, then compile
the script before assigning a hot key to it and using it.
The magicNumber HAS TO TO BE THE SAME ON ALL SCRIPTS if you change it
here make sure to change it on all scripts!!!
Do not forget to click on COMPILE once your changes have been made!!!
+-------------------------------------------------------------------+*/
int MagicNumber = 915;
double Risk = 1.0;
int StopLoss = 20; // Number in Pips ie: 50 for 50 pips.
int ProfitTarget = 0; // Number in Pips ie: 50 for 50 pips.
int Slippage = 1;
bool MiniLots = True; // Does your broker offer mini micro lots such as 0.01 lot?
string Commentary = " IBFX - Quick Sell ";
string FontName = "Arial";
int FontSize = 12;
//+-------------------------------------------------------------------------+
//| DO NOT MODIFY ANYTHING BELOW THIS LINE!!! |
//+-------------------------------------------------------------------------+
//---- A few checks before we get started
if( !IsConnected() ) { Alert( Commentary + " - No Connection!!" ); return(0); }
//---- Specific Vars
int Action = OP_SELL;
double InitPrice = Bid;
//---- Global Vars
bool Done = False;
string Symbole = Symbol();
int Ticket = 0;
int ErrorCode = 0;
double MaxLots = MarketInfo( Symbole, MODE_MAXLOT );
double Lots = MM( Symbole, Risk, MiniLots );
Comment( "IBFX - QuickSell | Placing Short Order, please wait ..." );
//---- Let's place the order.
while( !Done )
{
double FillPrice = Bid;
double StopPrice = Ask;
if( MathAbs( InitPrice - FillPrice ) > Slippage * Point ) { Done = true; }
Wait();
Ticket = OrderSend( Symbole, Action, Lots, FillPrice, Slippage * Point, StopShort( StopPrice, StopLoss ), TakeShort(FillPrice, ProfitTarget), Commentary, MagicNumber, 0, CLR_NONE );
if( Ticket >= 0 ) { Done = true; }
else
{
ErrorCode = GetLastError();
if( ErrorCode == 4109 ) { Alert( Commentary + " - You did not allow live trading!" ); Done = true; }
else if( ErrorCode == 134 ) { Alert( Commentary + " - Not enough Money!" ); Done = true; }
else if( ErrorCode == 138 || ErrorCode == 136 || ErrorCode == 135 ) { Alert( Commentary + " - Requote/Slippage, run the script again" ); Done = true; }
else { Alert( Commentary + " Error: " + ErrorCode ); }
}
}
Comment("");
//----
return(0);
}
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//+ Wait +
//+-------------------------------------------------------------------------+
void Wait() { while( IsTradeContextBusy() ) { Sleep(50); } }
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//| Calculate Stop Short |
//+-------------------------------------------------------------------------+
double StopShort(double price,int stop)
{
if(stop==0) { return(0); }
else { return(price+(stop*Point)); }
}
//+-------------------------------------------------------------------------+
//| Calculate Profit Target Short |
//+-------------------------------------------------------------------------+
double TakeShort(double price,int take)
{
if(take==0) { return(0);}
else { return(price-(take*Point));}
}
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//| Money Managment |
//+-------------------------------------------------------------------------+
double MM( string Sym, double Risk, bool BrokerAllowsFractionalLots )
{
double MinLots = MarketInfo(Sym,MODE_MINLOT);
double MaxLots = MarketInfo(Sym,MODE_MAXLOT);
double Leverage = AccountLeverage();
double LotSize = MarketInfo(Sym,MODE_LOTSIZE);
double LotStep = MarketInfo(Sym,MODE_LOTSTEP);
double FinalAccountBalance = MathMin( AccountBalance(), AccountEquity() );
int NormalizationFactor = 0;
double Lots = 0.0;
if(LotStep == 0.01) { NormalizationFactor = 2; }
if(LotStep == 0.1) { NormalizationFactor = 1; }
if( BrokerAllowsFractionalLots == true)
{
Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);
Lots = StrToDouble(DoubleToStr(Lots, NormalizationFactor));
if (Lots < MinLots) { Lots = MinLots; }
if (Lots > MaxLots) { Lots = MaxLots; }
}
else if(BrokerAllowsFractionalLots == false)
{
Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);
Lots = MathRound(Lots);
if (Lots < MinLots) { Lots = MinLots; }
if (Lots > MaxLots) { Lots = MaxLots; }
}
return( Lots );
}
The part in bold is where the IBFX video says to adjust if I want to adjust it to enter specific trades. In its default mode it is:
double Lots = MM( Symbole, Risk, MiniLots );
I want to risk .2 lots per trade so I change the code to:
double Lots = .20; //MM( Symbole, Risk, MiniLots );
This gives me an error when I compile that says, "Function MM is not referenced and will be removed from the exp-file."
I tried running the script anyways on a demo account and it kept giving me an 'error 2' message. Eventually it froze my platform.
How do I fix this? I followed the instructions on IBFX's website at http://www.ibfx.com/tools/quickscripts/default.aspx
Please help.
Thanks,
Matt
Here is the complete code:
//+-------------------------------------------------------------------------+
//| IBFX - Quick Sell.mq4 |
//+-------------------------------------------------------------------------+
#property copyright "Copyright 2008, ibfx.com"
#property link "www.ibfx.com"
//----
int start()
{
/*+-------------------------------------------------------------------+
Because these scripts are meant to execute fast there are no user
external inputs. Make sure to modify the settings below, then compile
the script before assigning a hot key to it and using it.
The magicNumber HAS TO TO BE THE SAME ON ALL SCRIPTS if you change it
here make sure to change it on all scripts!!!
Do not forget to click on COMPILE once your changes have been made!!!
+-------------------------------------------------------------------+*/
int MagicNumber = 915;
double Risk = 1.0;
int StopLoss = 20; // Number in Pips ie: 50 for 50 pips.
int ProfitTarget = 0; // Number in Pips ie: 50 for 50 pips.
int Slippage = 1;
bool MiniLots = True; // Does your broker offer mini micro lots such as 0.01 lot?
string Commentary = " IBFX - Quick Sell ";
string FontName = "Arial";
int FontSize = 12;
//+-------------------------------------------------------------------------+
//| DO NOT MODIFY ANYTHING BELOW THIS LINE!!! |
//+-------------------------------------------------------------------------+
//---- A few checks before we get started
if( !IsConnected() ) { Alert( Commentary + " - No Connection!!" ); return(0); }
//---- Specific Vars
int Action = OP_SELL;
double InitPrice = Bid;
//---- Global Vars
bool Done = False;
string Symbole = Symbol();
int Ticket = 0;
int ErrorCode = 0;
double MaxLots = MarketInfo( Symbole, MODE_MAXLOT );
double Lots = MM( Symbole, Risk, MiniLots );
Comment( "IBFX - QuickSell | Placing Short Order, please wait ..." );
//---- Let's place the order.
while( !Done )
{
double FillPrice = Bid;
double StopPrice = Ask;
if( MathAbs( InitPrice - FillPrice ) > Slippage * Point ) { Done = true; }
Wait();
Ticket = OrderSend( Symbole, Action, Lots, FillPrice, Slippage * Point, StopShort( StopPrice, StopLoss ), TakeShort(FillPrice, ProfitTarget), Commentary, MagicNumber, 0, CLR_NONE );
if( Ticket >= 0 ) { Done = true; }
else
{
ErrorCode = GetLastError();
if( ErrorCode == 4109 ) { Alert( Commentary + " - You did not allow live trading!" ); Done = true; }
else if( ErrorCode == 134 ) { Alert( Commentary + " - Not enough Money!" ); Done = true; }
else if( ErrorCode == 138 || ErrorCode == 136 || ErrorCode == 135 ) { Alert( Commentary + " - Requote/Slippage, run the script again" ); Done = true; }
else { Alert( Commentary + " Error: " + ErrorCode ); }
}
}
Comment("");
//----
return(0);
}
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//+ Wait +
//+-------------------------------------------------------------------------+
void Wait() { while( IsTradeContextBusy() ) { Sleep(50); } }
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//| Calculate Stop Short |
//+-------------------------------------------------------------------------+
double StopShort(double price,int stop)
{
if(stop==0) { return(0); }
else { return(price+(stop*Point)); }
}
//+-------------------------------------------------------------------------+
//| Calculate Profit Target Short |
//+-------------------------------------------------------------------------+
double TakeShort(double price,int take)
{
if(take==0) { return(0);}
else { return(price-(take*Point));}
}
//+-------------------------------------------------------------------------+
//+-------------------------------------------------------------------------+
//| Money Managment |
//+-------------------------------------------------------------------------+
double MM( string Sym, double Risk, bool BrokerAllowsFractionalLots )
{
double MinLots = MarketInfo(Sym,MODE_MINLOT);
double MaxLots = MarketInfo(Sym,MODE_MAXLOT);
double Leverage = AccountLeverage();
double LotSize = MarketInfo(Sym,MODE_LOTSIZE);
double LotStep = MarketInfo(Sym,MODE_LOTSTEP);
double FinalAccountBalance = MathMin( AccountBalance(), AccountEquity() );
int NormalizationFactor = 0;
double Lots = 0.0;
if(LotStep == 0.01) { NormalizationFactor = 2; }
if(LotStep == 0.1) { NormalizationFactor = 1; }
if( BrokerAllowsFractionalLots == true)
{
Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);
Lots = StrToDouble(DoubleToStr(Lots, NormalizationFactor));
if (Lots < MinLots) { Lots = MinLots; }
if (Lots > MaxLots) { Lots = MaxLots; }
}
else if(BrokerAllowsFractionalLots == false)
{
Lots = (FinalAccountBalance*(Risk/100.0))/(LotSize/Leverage);
Lots = MathRound(Lots);
if (Lots < MinLots) { Lots = MinLots; }
if (Lots > MaxLots) { Lots = MaxLots; }
}
return( Lots );
}
The part in bold is where the IBFX video says to adjust if I want to adjust it to enter specific trades. In its default mode it is:
double Lots = MM( Symbole, Risk, MiniLots );
I want to risk .2 lots per trade so I change the code to:
double Lots = .20; //MM( Symbole, Risk, MiniLots );
This gives me an error when I compile that says, "Function MM is not referenced and will be removed from the exp-file."
I tried running the script anyways on a demo account and it kept giving me an 'error 2' message. Eventually it froze my platform.
How do I fix this? I followed the instructions on IBFX's website at http://www.ibfx.com/tools/quickscripts/default.aspx
Please help.
Thanks,
Matt