

Save accountprofit along with accountbalance and time and you can compare current accountprofit with last account profit IF the time is correct (1 daily global variable that updates if last value is 24 hours or more ago, 1 weekly that updates if last value is 7 days or more ago, etc).

Then you can adjust the accountbalance by profit/loss.Īn easy way out but which I am not sure if it would work for all instances (I'm not sure when this gets reset) which is to use AccountProfit().
MATHMOD MQL4 HOW TO
I might be going about this completely wrong, but I think I have an idea how to get it to work.įirst save the current accountbalance and time in a global variable (yes I know, let me get to it.), then check with a loop for closed trades (Either yesterday,last week or last month, be sure to check if there is a valid time/balance stored in global variable and abort the checks if not and simply save current accountbalance and time) check the profit or loss on these trades as long as they are from the timeframe you need (you take current time, substract the time in global variable and you have the timeframe over which the accountbalance is not updated). This is what i am using for lot size which works already but instead of CompoundingToUse i have AccountBalance() in its place, Just adding it so you can see how i am trying to do this: GlobalVariableSet( "MonthlyOpenBalance", BalanceToUse ) GlobalVariableSet( "MonthStartTime", dtCurr ) GlobalVariableSet( "WeeklyOpenBalance", BalanceToUse ) ĭatetime dtSaved = GlobalVariableGet( "MonthStartTime" ) ĭatetime dtCurr = iTime( Symbol(), PERIOD_MN1, 1 ) GlobalVariableSet( "WeekStartTime", dtCurr ) GlobalVariableSet( "DailyOpenBalance", BalanceToUse ) ĭatetime dtSaved = GlobalVariableGet( "WeekStartTime" ) ĭatetime dtCurr = iTime( Symbol(), PERIOD_W1, 1 ) GlobalVariableSet( "DayStartTime", dtCurr ) If ( ( dtSaved = 0 ) || ( dtCurr > dtSaved ) )
