I am trying to run a test on the MT4 strategy tester on the 5m chart. I want conditions to be met on both the 5m and 30m charts.
It appears to ignore the 30m chart condition so the condition is never true?
// Input variables
input int KPeriod = 14;
input int DPeriod = 3;
input int Slowing = 3;
input ENUM_MA_METHOD StochMethod = MODE_SMA;
input ENUM_STO_PRICE StochPrice = STO_LOWHIGH;
input int BandsPeriod= 20;
input int BandsShift = 0;
input double BandsDeviations = 2.0;
input ENUM_APPLIED_PRICE BollPrice = PRICE_CLOSE;
// OnTick() event handler
double close = Close;
datetime time = iTime(NULL,0,1);
double stochasticBigMain = iStochastic(_Symbol,PERIOD_M30,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,1);
double stochasticBigSignal = iStochastic(_Symbol,PERIOD_M30,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_SIGNAL,1);
bool timeframeBigBuyCondition = (stochasticBigMain > stochasticBigSignal && stochasticBigMain < 80);
double stochasticSmallMain = iStochastic(_Symbol,PERIOD_M5,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_MAIN,1);
double stochasticSmallSignal = iStochastic(_Symbol,PERIOD_M5,KPeriod,DPeriod,Slowing,StochMethod,StochPrice,MODE_SIGNAL,1);
bool timeframeSmallBuyCondition = (stochasticSmallMain > stochasticSmallSignal && stochasticSmallMain < 80);
if(timeframeBigBuyCondition == true && timeframeSmallBuyCondition == true)
I basically dont know how to make a condition true on a bigger timeframe apply to a smaller timeframe?
How do you know the conditions are never true?
Once the object "Buy" has been created, another object with the same name cannot be created again
Either check that the object exists already and if so, move it.
Or give each object a unique name, such as
double close = Close; //The price from earlier in your code
datetime time = iTime(NULL,0,1); //The time from earlier in your code
string ob_name="Buy "+TimeToStr(time);
Unrelated to your question. When comparing values from any indicator from different timeframes, you need to be sure that you are comparing the bars that you want to.
with your code, say the current time is 05:12
At that time Bar on the M5 chart is the bar that opened at 05:05
on M15, Bar opened at 04:45.
Thanks for the code GumRai that will be useful
To add comments, please log in or register