Hi All,
I am testing my EA and I am having an issue with OrderClose() in one of the functions, so I figured there may be a fancier way of getting it done. It is closing out most of the trades in the 'basket', but it is not closing out all of them. Please help.
The following code is a function and all that you would need I think:
Thank you for any assistance!
I am testing my EA and I am having an issue with OrderClose() in one of the functions, so I figured there may be a fancier way of getting it done. It is closing out most of the trades in the 'basket', but it is not closing out all of them. Please help.
The following code is a function and all that you would need I think:
Inserted Code
//+------------------------------------------------------------------+ double ProfitProtection() //+------------------------------------------------------------------+ { bool ClosedInProfit = 0; string OrderSymbolClosedInProfit; double TP; double ProfitThisOrder; TakeProfit = OneSixthOfChart*2; TotalBasketProfit = 0; CurrentOrderProfit = 0; int OT = OrdersTotal(); for(int bp=0; bp < OT; bp++) //cycle throug the open market orders { if (OrderSelect(bp, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) { TotalBasketProfit += OrderProfit() + OrderCommission() + OrderSwap(); CurrentOrderProfit = OrderProfit() + OrderCommission() + OrderSwap(); if(OrderLots() != Lots && TotalBasketProfit >= MinimumProfitOfBasket) { ClosedInProfit = OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Center); OrderSymbolClosedInProfit = Symbol(); } } } if(ClosedInProfit) { for(int co = 0; co < OrdersTotal(); co++) { if (OrderSelect(co, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == OrderSymbolClosedInProfit) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Center); } } } } } //Comment("Basket: ", TotalBasketProfit); }
Thank you for any assistance!
We are our own best indicator.