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.
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 :-
Inserted Code
//+------------------------------------------------------------------+ Get 1st Order
datetime Old1Tm=TimeCurrent(); // Get 1st Ord's Open Time
double Old1TmPx=0; // Get 1st 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()<=Old1Tm) {
Old1Tm=OrderOpenTime();
Old1TmPx=OrderOpenPrice();}}}
//+------------------------------------------------------------------+ Get 2nd Order
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 && Old2Tm>Old1Tm) {
Old2Tm=OrderOpenTime();
Old2TmPx=OrderOpenPrice();}}}
if(sym=="AUDNZD" || sym=="NZDUSD" || sym=="USDCAD") {
Print(sym+" /Old1TmPx "+DoubleToStr(Old1TmPx,cDigits)+" ("+TimeToStr(Old1Tm)+
") /Old2TmPx "+DoubleToStr(Old2TmPx,cDigits)+" ("+TimeToStr(Old2Tm)+") /Pips "+
DoubleToStr(MathAbs(Old1TmPx-Old2TmPx)/cPnt/10,3));} 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.