double initial_deposit=AccountEquity();
extern int ProfitPerc=10;
i have defined this in start of the trade.
Then i have the following line for closing the trade of earning 10% Growth in Equity. I want to
if ((AccountEquity()-initial_deposit>=(ProfitPerc*initial_deposit)/100))
{
if (AccountEquity()>initial_deposit){ initial_deposit=AccountEquity();}
CloseOrder(); //This function closes all open positions in that Chart
initial_deposit=AccountEquity() // initial_deposit gets updated to new AccountEquity()
}
Here i have a problem.
Case 1
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 110
The above case all trades will get closed and initial balance will be updated to 110. Perfect
Case 2
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 105
At this Point if we deposit money to our account. say 50 $
Initial Deposit = 100 (remain same at the time of deposit)
Account Balance = 190 (increases from 140)
Profit/Loss = -30 (Remain Same)
Current Account Equity = 155 (increases from 105)
Here is the real problem. As per the above order close condition, the Equity has been increased by 55% which is more than the 10% close condition. All Trades are closed.
I am really stuck here. The Orders should be closed on earning 10% profit and should not close while doing deposit.
Please help me friends
I dont want the trades to getting close when we add deposit to the account. How to handle this deposit issue here
I dont want the trades to getting close when we add deposit to the account. How to handle this deposit issue here
@Fabio Cavalloni has given you the solution - AccountProfit() will not change when you make deposit, so use it instead of AccountEquity().
@Fabio Cavalloni has given you the solution - AccountProfit() will not change when you make deposit, so use it instead of AccountEquity().
yes AccountProfit() i agree.
I want to close all trades in all open charts of reaching a 10% increase in Equity. That is Starting Equity 100, I want to close and restart all the trades fresh when the equity increases to 110.
Even When AccountProfit is negative, i still managed to increase the equity by 10%. Fresh Start over so that we stay with trend.
At this juncture if i deposit to my account, the EA treats that as an increase in equity and closes all trades.
I dont want the trades to getting close when we add deposit to the account. How to handle this deposit issue here
yes AccountProfit() i agree.
I want to close all trades in all open charts of reaching a 10% increase in Equity. That is Starting Equity 100, I want to close and restart all the trades fresh when the equity increases to 110.
Even When AccountProfit is negative, i still managed to increase the equity by 10%. Fresh Start over so that we stay with trend.
At this juncture if i deposit to my account, the EA treats that as an increase in equity and closes all trades.
I don't think AccountEquity() can increase by 10% (from the StartupEquity) when AccountProfit() is negative, if you stick to these steps:
if (OrdersTotal()==0) StartupEquity = AccountEquity(); // : // Do whatever necessary to open new trades, if so desired. // : if (OrdersTotal()>0) { if (AccountProfit()>0.1*StartupEquity) CloseAllOrders(); }
Unless your algorithm closes individual trades due to other conditions? In which case you should also be looking into history orders and extract their profit/loss before comparing for the 10% increase.
I don't think AccountEquity() can increase by 10% (from the StartupEquity) when AccountProfit() is negative, if you stick to these steps:
Unless your algorithm closes individual trades due to other conditions? In which case you should also be looking into history orders and extract their profit/loss before comparing for the 10% increase.
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 110
this case the equity is increased by 10% from the Initial deposit even though the Account Profit is -30. At This Point i want to close all orders and restart.
After REstarting
Initial Deposit = 110
Account Balance = 110
Profit/Loss = 0
Current Account Equity = 110
----------------------------------------------------
My real problem is
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 110
At this point if i add deposit to my account it will close all trades assuming an equity increase by certain percentage. Hope you understand my problem
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 110
this case the equity is increased by 10% from the Initial deposit even though the Account Profit is -30. At This Point i want to close all orders and restart.
After REstarting
Initial Deposit = 110
Account Balance = 110
Profit/Loss = 0
Current Account Equity = 110
----------------------------------------------------
My real problem is
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 110
At this point if i add deposit to my account it will close all trades assuming an equity increase by certain percentage. Hope you understand my problem
Sorry, I don't.
If your code follows proper steps (see my earlier post), this situation should not happen. So if my guess is right, you do close certain trades due to other conditions... then you should start looking into your trade history and extract those trades' profit/loss (filter by time period which you want to consider your 10%), rather than focusing here on balance/equity/profit alone.
Hope somebody will understand your problem.
Sorry, I don't.
If your code follows proper steps (see my earlier post), this situation should not happen. So if my guess is right, you do close certain trades due to other conditions... then you should start looking into your trade history and extract those trades' profit/loss (filter by time period which you want to consider your 10%), rather than focusing here on balance/equity/profit alone.
Hope somebody will understand your problem.
can you please give the code lines for this
start looking into your trade history and extract those trades' profit/loss (filter by time period which you want to consider your 10%
can you please give the code lines for this
start looking into your trade history and extract those trades' profit/loss (filter by time period which you want to consider your 10%
Here's what I extracted/modified from https://www.mql5.com/en/docs/trading/historyselect (just sum up all profits from deals that lie within the time period of your interest, and you'll be able to add that to your startup equity and determine whether 10% has been met...):
//--- request trade history HistorySelect(0,TimeCurrent()); //--- create objects string name; uint total=HistoryDealsTotal(); ulong ticket=0; double price; double profit; datetime time; string symbol; long type; long entry; //--- for all deals for(uint i=0;i<total;i++) { //--- try to get deals ticket if((ticket=HistoryDealGetTicket(i))>0) { //--- get deals properties price =HistoryDealGetDouble(ticket,DEAL_PRICE); time =(datetime)HistoryDealGetInteger(ticket,DEAL_TIME); symbol=HistoryDealGetString(ticket,DEAL_SYMBOL); type =HistoryDealGetInteger(ticket,DEAL_TYPE); entry =HistoryDealGetInteger(ticket,DEAL_ENTRY); profit=HistoryDealGetDouble(ticket,DEAL_PROFIT); //--- only for current symbol if(price && time) { Print ("Symbol = ", symbol, ", Time = ", time, ", Price = ", price, ", Profit = ", profit, ", Type = ", EnumToString(ENUM_DEAL_TYPE(type)), ", Entry = ", EnumToString(ENUM_TRADE_TRANSACTION_TYPE(entry))); } } }

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
double initial_deposit=AccountEquity();
extern int ProfitPerc=10;
i have defined this in start of the trade.
Then i have the following line for closing the trade of earning 10% Growth in Equity. I want to
if ((AccountEquity()-initial_deposit>=(ProfitPerc*initial_deposit)/100))
{
if (AccountEquity()>initial_deposit){ initial_deposit=AccountEquity();}
CloseOrder(); //This function closes all open positions in that Chart
initial_deposit=AccountEquity() // initial_deposit gets updated to new AccountEquity()
}
Here i have a problem.
Case 1
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 110
The above case all trades will get closed and initial balance will be updated to 110. Perfect
Case 2
Initial Deposit = 100
Account Balance = 140
Profit/Loss = -30 (Loss)
Current Account Equity = 105
At this Point if we deposit money to our account. say 50 $
Initial Deposit = 100 (remain same at the time of deposit)
Account Balance = 190 (increases from 140)
Profit/Loss = -30 (Remain Same)
Current Account Equity = 155 (increases from 105)
Here is the real problem. As per the above order close condition, the Equity has been increased by 55% which is more than the 10% close condition. All Trades are closed.
I am really stuck here. The Orders should be closed on earning 10% profit and should not close while doing deposit.
Please help me friends