Hi
Here on the second loop you need to also check if the oldest trade is not this already found Old1Trade as you tried to do.But you need to compare Ordertime and not Old2Tm, because it’s not yet updated (when you compare times). So simply add this small change:
datetime Old2Tm=TimeCurrent(); // Get 2nd Ord's Open Time double Old2TmPx=0; // Get 2nd Ord's OpPx for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) && OrderSymbol()==sym && (OrderMagicNumber()==mnBUY || OrderMagicNumber()==mnSEL)) { if((OrderType()==OP_BUY || OrderType()==OP_SELL) && OrderOpenTime()<=Old2Tm && OrderOpenTime()>Old1Tm) { Old2Tm=OrderOpenTime(); Old2TmPx=OrderOpenPrice();}}}
Best Regards
Marzena Maria Szmit #:
Thanks so much Marzena, yes, I tested, this is the correct solution.
Hi
Here on the second loop you need to also check if the oldest trade is not this already found Old1Trade as you tried to do.But you need to compare Ordertime and not Old2Tm, because it’s not yet updated (when you compare times). So simply add this small change:
Best Regards

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi coders, I need your help for my learning process.
I'm using a Multi-Symbol EA which it can run sizeable pairs and it was written by someone else.
My Mission :-
1) To get the 1st OrderOpenPrice
2) To get the 2nd OrderOpenPrice
3) Finally, get the difference MathAbs( 1 - 2 )
I have written the following codes :-
For the (1 - 1st OrderOpenPrice), I can prettily get the correct output, the only problem is to get the (2 - 2nd OrderOpenPrice), I failed to get the correct output.
I've 3 pairs that with open orders :-
1) AUDNZD, total 2 open orders :-
1st OrderOpenPrice : 1.07610 (correct)
2nd OrderOpenPrice : 1.07590 (but EA output was incorrect, exactly the same as 1st OrderOpenPrice)
2) NZDUSD, total 2 open orders :-
1st OrderOpenPrice : 0.61787 (correct)
2nd OrderOpenPrice : 0.61794 (but EA output was incorrect, exactly the same as 1st OrderOpenPrice)
3) USDCAD, total 4 open orders :-
1st OrderOpenPrice : 1.36799 (correct)
2nd OrderOpenPrice : 1.36779 (but EA output was incorrect, exactly the same as 1st OrderOpenPrice)
FYI, I suspect when come to the 2nd loop, the Old1Tm turns into 0 (datetime), therefore the output for 2nd OrderOpenPrice will always be the same as the 1st OrderOpenPrice.
Is there any way to get the correct output for 2nd OrderOpenPrice ? FYI, I do not want to use Array as it would be make my strategy very much more complicated. Secondly, my EA is a Multi-Symbol EA, using Array is not so suitable for my case, therefore I would like to avoid it.
Could you please check my loops, is there any way to improve the loops so that I can get the correct output for 2nd OrderOpenPrice, thank you.