- Right Approach?
- EA to close pending and open orders!!
- Universal Basic MA Cross
Yes. Code it to do that.
How To Ask Questions The Smart Way. (2004)
Only ask questions with yes/no answers if you want “yes” or “no” as the answer.
void CloseProfit() { double MAXprofit=0; for(int i=OrdersTotal()-1; i>=0; i--) if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==InpMagicNumber) { MAXprofit=MathMax(MAXprofit,OrderProfit()+OrderSwap()+OrderCommission()); if(MAXprofit==OrderProfit()) int close = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 0); } }
void CloseProfit() { double MAXprofit=0; double OrdProfit=0; double OrdTicket=0; for(int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) if(OrderMagicNumber()==InpMagicNumber) { OrdProfit=OrderProfit()+OrderSwap()+OrderCommission(); if(OrdProfit>0 && OrdProfit>=MAXprofit) { MAXprofit=OrdProfit; OrdTicket=OrderTicket(); } //int close = OrderClose(, OrderLots(), OrderClosePrice(), 0); } } if (MAXprofit>0 && OrdTicket>0) { if(OrderSelect(OrdTicket,SELECT_BY_POS,MODE_TRADES)) bool close = OrderClose(OrdTicket, OrderLots(), OrderClosePrice(), 0); } }
hi, i've compared the codes that i've made to yours. to my surprise your code is much better but there is a problem to your code and mine. my problem with my code is that it closes too many trades after that max trade is reach that's why the EA will open many trades and if the EA reach the max trade it will close the most profitable trade again and so on but the strategy is that if the EA reach the MAX trade that is allowed it must remove the most profitable trade in order to open new trades again. the problem that i saw to your code after i backtested it is that after it reach the max trade the EA will wait for the most profitable trade on all of the order that is open that's why it does not open new trades it just wait and it does not use MathMax to filter out the most profitable trade (just correct me if i'm wrong hehe). here's the result on my code and yours(it can have higher profit and lower drawdown if i complete the EA because this strategy is day trading)
StrategyTester is my code
StrategyTester2 is your code
thanks for the idea mate i will try that and btw do you have any example that i can use tnx again :)
Still don’t understand the idea… because for loop will run and close the highest profit order… and at the next tick will run again… and close the highest profit order…. Until it is nothing left open… 😁
Still don’t understand the idea… because for loop will run and close the highest profit order… and at the next tick will run again… and close the highest profit order…. Until it is nothing left open… 😁

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use