I have build and EA, and want to add more trade protection into it,
what I need is a function than i can integrate with my previous code by just calling it
The strategy are :
If daily profit is equal or more than target profit (by precentege of ballance) , than trading stop for that day
Or if loss more than 2 times or equal more than target loss (by precentage of ballance) than trading stop for that day
Logic something like this
Balance = 1000; //account balance
TargetProfit = 0.05; // 5%
TargetLoss = 0.05; // 5%
LossTime = 2; //maximum loss time
void onTick ()
{
LimitTrade() ;
}
void LimitTrade()
TodayTradeProfit = CheckTodayTradeProfit();
TodayTradeLoss = CheckTodayTradeLoss();
If (TodayTradeProfit == False)
{
MyTradingLogic(); // call trading function
}
Else
{
//stop trading
}
If (TodayTradeLoss == False)
{
MyTradingLogic();
}
Else
{
//stop trading
}
bool CheckTodayTradeProfit()
profit = balance * TargetProfit;
If (todayprofit > profit)
return True;
Else
return false;
bool CheckTodayTradeLoss()
loss = balance * TargetLoss;
losstime // calculate how many loss on this day
todayloss // calculate total loss on this day
If (todayloss > loss or losstime > 2 )
return True;
Else
return false;
Can you help me sample code how to do it?
- Questions from Beginners MQL4 MT4 MetaTrader 4
- Looking for something to secure trades when they've reached a daily level.
- Building A Function I need your help !!!

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register