Issues with first Trade Operations EA - page 2

 

And what happens if MT4 should be shut down after the first partial scale, or the second parital scale? You're tracking scale levels with variables set at the time you perform the close operation. This information gets lost if the terminal should happen to close This may work nicely in Strategy Tester but fails to address real trading issues such as a reboot or MT4 crash. On a casual glance of the code, it looks like if you close your 1st partial target, are forced to re-load the EA, it will then scale level 1 again if price warrants it. Same can be said for scale level 2.

 
dlewisfl:

And what happens if MT4 should be shut down after the first partial scale, or the second parital scale? You're tracking scale levels with variables set at the time you perform the close operation. This information gets lost if the terminal should happen to close

Exactly, EA's must be coded to recover from terminal shutdown, Windoze crash, power failures, etc.

Option 1) Persistent storage

Option 2) Multiple orders with different TPs

    double  lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP),   //IBFX= 0.01
            maxLot          = MarketInfo(Symbol(), MODE_MAXLOT );   //IBFX=50.00
    #define PAIRS 3 // Open three orders, one third lot size each.
    for(int split=MathCeil(lots.new/(PAIRS*maxLot))*PAIRS; split>0; split--) {
        // 100.01=33.34+33.33+33.33
        double size=MathCeil(lotsNew/split/lotStep)*lotStep;
        lotsNew -= size;
        orderSend(... size...
    }
    int newCount=0;
    for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
    &&  OrderMagicNumber()  == magic.number             // my magic number
    &&  OrderSymbol()       == Symbol() ){              // and my pair.
        if (OrderTakeProfit() == 0){
            newCount++;
            double tp = OrderOpenPrice() +DIR* newCount*TP.pips*pips2dbl;
            ordermodify(...
        }
    }
Reason: