strange for cicle

 
ope_rec += increm;
Print("ope_rec ", ope_rec);
if (ope_rec > increm*3)
{inversione = 1;}
close_all = 0;
for (k=0;k < ope_rec;k++)
{ //for
Print("k ",k);
if (inversione == 0)
{OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"rec",16384,0,Magenta);}
else
{OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"rec",16384,0,Blue);}
aperte ++;

} //for

This for cicle with ope_rec = 5 (displayed) in test opens correctly five trades, in real mode opens only one trade.

Wath's the solution?

Thanks


 

  1. Opening orders in a real account takes time, by then the market may move, but you're not updating Bid/Ask with RefreshRates() inside the loop.
  2. Always test return codes so you know WHY it doesn't work
    int ticket = OrderSend(...);
    if (ticket < 0) Alert("OrderSend failed: ", GetLastError());
    

  3. EA's must adjust for 5 digit brokers, TP, SL, AND slippage. On a 5 digit broker you're using 0.3 pips for slippage, thus #2
    //++++ These are adjusted for 5 digit brokers.
    int     pips2points;    // slippage  3 pips    3=points    30=points
    double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
    int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
    int     init(){
        if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                    pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
        } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
        // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl