Can't seem to figure out why this isn't working, any help would be appreciated. I want to close all orders under that specific symbol with MagicNumber_3 if their total floating profit is greater than DollarTakeProfit_s3.
Perhaps the problem lies in function CloseThisSymbolAll_s3() ? can you show the code for that ?
void CloseThisSymbolAll_s3() { for (int trade_s3 = OrdersTotal() - 1; trade_s3 >= 0; trade_s3--) { OrderSelect(trade_s3, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol()) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber_3) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, (Slippage_s3*PipValue)*Point, DarkGray); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, (Slippage_s3*PipValue)*Point, YellowGreen); } Sleep(1000); } } }
kinitex:
CloseThisSymbolAll_s3()
You haven't exactly said what isn't working, is it sometimes working or not working at all ?
Some general comments:
- you should check that the OrderSelect() has worked otherwise everything that follows it is not valid, for example Orderticket(), OrderLots(), etc
- you should check the return value from the OrderClose() and report the error to the log if it fails, more info here: What are Function return values ? How do I use them ?
- your EA sleeps for a second before trying to close the next order, the Bid and Ask may be out of date by that time, either do a RefreshRates() or use OrderClosePrice() in place of Bid and Ask
- there is no need to check OrderSymbol() twice, once will suffice
if (UseStoplossPct_s3) { if (CurrentPairProfit_s3 < 0.0 && MathAbs(CurrentPairProfit_s3) > StoplossPct_s3 / 100.0 * AccountEquityHigh_s3()) { CloseThisSymbolAll_s3(); Print("Closed all trades under this pair because StoplossPCT was met"); NewOrdersPlaced_s3 = FALSE; } }
This one works fine for me, so I dont see why the DollarTakeProfit wont.
By doesn't work I mean I see no sign of it working at all, even if I set the amount to close at $1.00
This one works fine for me, so I dont see why the DollarTakeProfit wont.
By doesn't work I mean I see no sign of it working at all, even if I set the amount to close at $1.00
Thanks for the help Raptor, I figured it out. It was kind of working, but I added a line of code that screwed up some nested if statements which is what was causing not only this to function wrong but the way my entire EA trades. Thanks for the extra suggestions as well, really helped me clean up a lot of my code :)
Thanks for the help Raptor, I figured it out. It was kind of working, but I added a line of code that screwed up some nested if statements which is what was causing not only this to function wrong but the way my entire EA trades. Thanks for the extra suggestions as well, really helped me clean up a lot of my code :)
One problem I noticed though is that it can take awhile for it to notice that CurrentPairProfit_s3 is greater than DollarTakeProfit_s3 and it sometimes won't close the trades until minutes later.
One problem I noticed though is that it can take awhile for it to notice that CurrentPairProfit_s3 is greater than DollarTakeProfit_s3 and it sometimes won't close the trades until minutes later.
No on a demo account as we speak, I have the profit being displayed on chart and it updates every tick.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can't seem to figure out why this isn't working, any help would be appreciated. I want to close all orders under that specific symbol with MagicNumber_3 if their total floating profit is greater than DollarTakeProfit_s3.