-
You haven't tried anything. Your loop selects all orders (of Symbol). It does not exclude the last, it does not exclude the first.
-
//for(int i = OrdersTotal()-1; i >= 0; i--)
This remove the last opened order, not the last opened order of symbol.
-
I have no idea why you want to exclude the last. The result will be meaningless.
-
If you really want that, change the ordering of the loop from last to first and exclude the initial selected order.
double averageprice=-1,size=0,out=0; for(int i = OrdersTotal() - 1; i >= 0; --i) if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) && OrderSymbol()==Symbol() ){ if(averageprice < 0){ averageprice=0; continue; } // Exclude the latest order. ⋮
-
You haven't tried anything. Your loop selects all orders (of Symbol). It does not exclude the last, it does not exclude the first.
-
This remove the last opened order, not the last opened order of symbol.
-
I have no idea why you want to exclude the last. The result will be meaningless.
-
If you really want that, change the ordering of the loop from last to first and exclude the initial selected order.
thank you for you comment.
3. the actual idea is to get the average price that also exclude the breakeven opened position and also the last opened order.
The solution you suggest did exclude the last opened order but it will fixed the value to the 1st opened position.
I tried to add the condition for it to exclude the breakeven opened position but there is something wrong with my condition to exclude the breakeven opened position?
appreciate all of your suggestion.
double AverageBuyPrice() { double lots=0,LotsPrice = 0,average = 0; int temp=-1,count=0; for (int i = OrdersTotal() - 1; i >= 0; --i) { if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue; if(OrderType()!=OP_BUY|| OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber)continue; { if(temp<0){temp=0;continue;} //exclude last opened order if(MarketInfo(OrderSymbol(),MODE_BID)- OrderOpenPrice() < 4 * MarketInfo(OrderSymbol(), MODE_POINT)) //if(OrderStopLoss()==0) // exclude breakeven opened order { count++; lots = lots + OrderLots(); LotsPrice = LotsPrice + OrderLots()*OrderOpenPrice(); } } } if(count>0) average = NormalizeDouble(LotsPrice/lots,Digits); return(average); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have tried change the for loop but seems it not exclude the last open order but the first open order instead