English

## Error OrderSend 4051

 1 Tarkunian 2015.03.24 19:52   Hi guys!Here is the simple EA. When I am trying to test the strategy it gives me an error OrderSend 4051, however my OrderVolume is normalized. Can you help me to find what is wrong? ```extern int SingleOrderRisk = 10; // in percents extern int PeriodMA1 = 5; // period of the first MA extern int PeriodMA2 = 7; // period of the second MA extern int StopLoss = 100; extern int TakeProfit = 100; double OrderVolume = 1; // in lots double OrdersArrayOld[50][8]; double OrdersArrayNew[50][8]; double OrdersType[2]; // ------------------------------------------------------------------------------- int start() // Main Function                                      {      int signal = 0;      Terminal();      signal = TradeCriteria();      OrderVolumeCalc();      if (signal==11)       OpenOrder(0);      if (signal==10)       CloseAllOrders(0);      return;                              }    // Function for calculating order volume using user defined percentage without credit margin bool OrderVolumeCalc()    {     string Symb = Symbol();     double One_Lot = MarketInfo(Symb,MODE_MARGINREQUIRED);     double Min_Lot = MarketInfo(Symb,MODE_MINLOT);     double Step = MarketInfo(Symb,MODE_LOTSTEP);     double Free = AccountFreeMargin();     if (SingleOrderRisk > 100)       SingleOrderRisk = 100;     if (SingleOrderRisk == 0)       OrderVolume = Min_Lot;     else       OrderVolume = NormalizeDouble((Free*SingleOrderRisk/100/One_Lot/Step)*Step,1);     if (OrderVolume < Min_Lot)       {       Alert ("Insufficient funds!");       return(false);       }     else       return(true);     } // Function for checking trading criteria int TradeCriteria()    {     if (Ask>iMA(NULL,0,PeriodMA1,0,MODE_SMA,PRICE_CLOSE,0))     {       return(11);     }     if (Bid0)    {    for(int i = 1; i <= OrdersArrayNew[0][0]; i++)       {       if (OrdersArrayNew[i][6]==Type && OrdersArrayNew[i][5] > Lot)          {          Lot = OrdersArrayNew[i][5];          Ticket = OrdersArrayNew[i][4];          }         }    if (Type==0)ClosePrice = Bid;    if (Type==1)ClosePrice = Ask;    OrderClose(Ticket,Lot,ClosePrice,2);    Terminal();    }   return; }```
 Moderator3406 GumRai 2015.03.24 23:17 #   `      OrderVolume = NormalizeDouble((Free*SingleOrderRisk/100/One_Lot/Step)*Step,1);`Why divide by Step and then multiply by Step?What if Step is 0.25 ? If the calculation calculates 0.25, it will then be normalised to 0.3 - an invalid lot size. What if Step is 0.01 ? If the calculation calculates anything less than 0.05, it will then be normalised to 0.0 - an invalid lot size.`bool OrderVolumeCalc() ` If this function returns false, you still carry on and try to use the calculated (too small) lot sizeIf the OrderSend fails, print out the lot size, that will help you to find your error