OrderModify intermitent error. - page 2

 
chrisbenjy:

It's because it causes things to mess up when you have two EA's working side by side. If one of the EA's is in the loop and the other EA opens a trade or closes a trade, while the other is still in the loop, the position number of each trade changes, which could cause a trade to be skipped or to be calculated twice.

It is better to work with ticket numbers so that you know the EA will be reliable. Another reason to use ticket numbers is because when you open a trade sometimes there is a lag between when it appears in the trade window and when it was opened, which could cause multiple trades to be opened if not using ticket numbers.

Chris

Right, but you've got to loop through the order pool index from OrdersTotal()-1 down to zero to retrieve the ticket number in the first place. The reason to count backwards is the index locations of all elements with a higher index than the one you are deleting will all shufflue down... so if you have 10 orders and close #5, index 6-10 all change... 6 becomes the new 5, 7 the new 6 and so on. if you do i++ i now becomes 6 which now contains the old 7 and you skip the old 6 completely becasue it is now sitting in position 5 but your EA thinks it's already dealt with 5. So count backwards i-- becomes 4 you've already checked the order then was in 6 and is now in 5 so it doesn't matter what it's index is and you go on to succesfully check the next order which is in position 4. Rambling a bit but hopefully you get what I mean.

V

 
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,0);
You can not move the stop closer to the market than stoplevel. For long:
double minGapStop = MarketInfo(Symbol(), MODE_STOPLEVEL)*Point,
       SLmax      = Bid - minGapStop;
if ( SL.max > OrderOpenPrice() )
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,0);
 
Viffer:

Right, but you've got to loop through the order pool index from OrdersTotal()-1 down to zero to retrieve the ticket number in the first place.

You got the ticket number when you opened, remember it, just select by ticket. If the select fails the order has closed.

But,

I only count down so I don't have to remember. Then I don't have to have persistent storage (files) to remember the tickets in case the platform reboots or terminal restarts. It also means trailing stops will resume on the next tick on any error this tick (like context busy.)

    for(int 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 period and symbol
 
ubzen:

It's clearly still trying to modify the order even though the Stop_Loss and Order Open price is Equal. My guess is it's got something to do with the Points and Digits. But I cannot explain it. So we'll just have to wait til someone more knowledgeable comes along.

One other thing you can try in the meantime is adjusting the digits

Put the above code in the int() function at the beginning of the code. Within your code where ever you have *points replace with *vPoint. Also I'll recommend turning the && statements into single arguments.

From

To:

Good Luck, I wish I could be more helpful. But I'm in the same shoes as you.


Thank you for all the help ubzen and Viffer and everyone else. Problem with the backtest persists but basically confirmed what I had originally thought in it being a backtest error.

Thank you also for the pointers on the loop and for setting proper point = pip. I had been putting in the 3rd digit and it was on my to do list to get it from 500 being 50 pips to 50 being 50 pips.

I have that in and working now and starting to look at more additions. =)

 

https://www.mql5.com/en/forum/124153, "Error 1 and I don't know why"

 
Thank you also for the pointers on the loop and for setting proper point = pip. I had been putting in the 3rd digit and it was on my to do list to get it from 500 being 50 pips to 50 being 50 pips.
You must change TP, SL, and slippage
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        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