
The advantage of the trades method is that you could theoretically trade for 6 years with only starting the EA up once at the start and as long as closed trade history and global variables are saved (no idea when it gets reset/deleted) and then get the accountbalance from every day down to the hour from all 6 years. The only case where this messes up is when you deposit or withdraw (I don't believe deposits or withdrawals get counted as profit or loss lol, certainly wouldn't work with the method of looping through closed trades). The problem with using accountprofit is that it isn't fool proof by always having the correct accountvalue and exact times can't be used (trades have an open and close time that can be checked, so you can always get exactly those profits made in the exact time period you specify). 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 ) ) Example: 0.05%0.01=0 BUT "if" condition says otherwise
