Help for Function on How to limit daily trade losses and profits

To add comments, please log in or register
ADAM YUSFAN EDWIN Yusfan
116
ADAM YUSFAN EDWIN Yusfan  
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? 
To add comments, please log in or register