I have been trying to add the compounding rate to an EA with no luck. I have had some help from others but they say i need to use a GlobalVariable which i have never messed with and kind of lost on how to use it.
What i need to do is find the accountbalance() from the start of the day,week, and month. It could be the accountbalance() at the close of yesterday,last week or last month since it would be the same as the opening balance and would not change.
Is there not a way to say: DailyOpenBalance = (AccountBalance(),Period_D1,1)
I know that will not work...but there has to be some simple code to find yesterdays closing balance.
Any help would be greatly appreciated.
This is at the top of the code so i can choose what i want to use:
This is what i have to switch what i want to use:
This is what another member has told me i should use:
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:
If this code will work as is....someone please tell me how to get it to work. I have tried everything i can think of...but with the lack of knowing how to code....i cant get it to work.
What i need to do is find the accountbalance() from the start of the day,week, and month. It could be the accountbalance() at the close of yesterday,last week or last month since it would be the same as the opening balance and would not change.
Is there not a way to say: DailyOpenBalance = (AccountBalance(),Period_D1,1)
I know that will not work...but there has to be some simple code to find yesterdays closing balance.
Any help would be greatly appreciated.
This is at the top of the code so i can choose what i want to use:
Inserted Code
extern string SECTION1 = "=====Risk / Money Management====="; extern string Comment1.1 = "Balance, Equity, Free Margin"; extern string BalanceToUse = "Free Margin"; extern string Comment1.2 = "Daily, Weekly, Monthly"; extern string Compounding_Rate = "Daily";
This is what i have to switch what i want to use:
Inserted Code
//|---------Used for Compounding Rate if(Compounding_Rate == "Daily") CompoundingToUse = "DailyOpenBalance"; // Compounds Daily if(Compounding_Rate == "Weekly") CompoundingToUse = "WeeklyOpenBalance"; // Compounds Weekly if(Compounding_Rate == "Monthly") CompoundingToUse = "MonthlyOpenBalance"; // Compounds Monthly //|---------Used for Account Balance if(BalanceToUse == "Balance") AccountBalanceToUse = AccountBalance(); // Uses Balance if(BalanceToUse == "Equity") AccountBalanceToUse = AccountEquity(); // Uses Equity if(BalanceToUse == "Free Margin") AccountBalanceToUse = AccountFreeMargin(); // Uses Free Margin
This is what another member has told me i should use:
Inserted Code
bool isNewDay() { datetime dtSaved = GlobalVariableGet( "DayStartTime" ); datetime dtCurr = iTime( Symbol(), PERIOD_D1, 1 ); if ( ( dtSaved == 0 ) || ( dtCurr > dtSaved ) ) { GlobalVariableSet( "DayStartTime", dtCurr ); GlobalVariableSet( "DailyOpenBalance", BalanceToUse ); } } bool isNewWeek() { datetime dtSaved = GlobalVariableGet( "WeekStartTime" ); datetime dtCurr = iTime( Symbol(), PERIOD_W1, 1 ); if ( ( dtSaved == 0 ) || ( dtCurr > dtSaved ) ) { GlobalVariableSet( "WeekStartTime", dtCurr ); GlobalVariableSet( "WeeklyOpenBalance", BalanceToUse ); } } bool isNewMonth() { datetime dtSaved = GlobalVariableGet( "MonthStartTime" ); datetime dtCurr = iTime( Symbol(), PERIOD_MN1, 1 ); if ( ( dtSaved == 0 ) || ( dtCurr > dtSaved ) ) { GlobalVariableSet( "MonthStartTime", dtCurr ); GlobalVariableSet( "MonthlyOpenBalance", BalanceToUse ); } }
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:
Inserted Code
if (AutoCalculateLots) SLPoints = MathAbs(SL - Ask)/Point; AccountBalanceToRisk = CompoundingToUse * PercentOfAccountToRisk / 100; lotsize = AccountBalanceToRisk * RiskPercent /100 / SLPoints /(MarketInfo(Symbol(), MODE_TICKVALUE)); Lots = lotsize;
If this code will work as is....someone please tell me how to get it to work. I have tried everything i can think of...but with the lack of knowing how to code....i cant get it to work.