Hello. I am looking for how can I write a code that will simply allow me to close all positions incurred with an average profit of $ 10 for example, for all sets of negative or positive trades. THANK YOU
***
Hello, this should do the trick
if (AccountEquity()<AccountBalance()-Risk) { int count=0; for(int i=0; i < OrdersTotal(); ){ if(OrderSelect(i, SELECT_BY_POS) && OrderType() == OrderType() && OrderSymbol() == Symbol() && OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 10) ){ RefreshRates(); // Update OrderClosePrice for next select. i=0; // Reprocess all orders, possible race condition. ++count; } else ++i; } return count; } if (AccountEquity()>AccountBalance()+Reward) { int count=0; for(int i=0; i < OrdersTotal(); ){ if(OrderSelect(i, SELECT_BY_POS) && OrderType() == OrderType() && OrderSymbol() == Symbol() && OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 10) ){ RefreshRates(); // Update OrderClosePrice for next select. i=0; // Reprocess all orders, possible race condition. ++count; } else ++i; } return count;
Of course, you need to enter what is risk and what is reward
Hello. I am looking for how can I write a code that will simply allow me to close all positions incurred with an average profit of $ 10 for example, for all sets of negative or positive trades. THANK YOU
***
double AvProfit=10; if(TotalProfit>=PositionsTotal()*AvProfit){ if(!trade.PositionClose(iTicket,ULONG_MAX)){ Print("PositionClose error ",trade.ResultRetcode(); return; } }
Quite easy, hope this helps.
Hello. I am looking for how can I write a code that will simply allow me to close all positions incurred with an average profit of $ 10 for example, for all sets of negative or positive trades. THANK YOU
***
double balance = AccountInfoDouble (ACCOUNT_BALANCE); double equity = AccountInfoDouble (ACCOUNT_EQUITY); double AvgProfit = m_position.Profit()/PositionsTotal(); if(equity >= balance + 10 && equity >= balance + AvgProfit) { CloseAllPositions(); return; }
double balance = AccountInfoDouble (ACCOUNT_BALANCE); double equity = AccountInfoDouble (ACCOUNT_EQUITY); double profit = equity - balance; double average = profit / PositionsTotal(); if(average >= 10) { CloseAllPositions(); }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello. I am looking for how can I write a code that will simply allow me to close all positions incurred with an average profit of $ 10 for example, for all sets of negative or positive trades. THANK YOU
***