Multi Timeframe Indicators - page 491

Mladen Rakic
153781
Mladen Rakic  
rickyponting:
Trying to make a simple moving average strategy tester with H1 ticks but using H4 MA with the help of movingaverage_mtf code supplied in these forums.But getting weird H4 moving average values.can anybody help.I doubt it is copying H4 bar time correctly when i use the function :

ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),420);

Is it possible to use multiframe indicators in strategy tester ?

PS: yes, it is possible to use multi time frame indicators in strategy tester, but make sure you do not use current (opened) bar of another time frame or else you are going to get fake positive results (metatrader strategy tester will "know the future" in that case)

Suvra Prakash Mandal
10
Suvra Prakash Mandal  

sorry..I m using 240 in the code...but still no result. Can any kind soul paste some reference code where multi frame SMA is being used in strategy tester.

Mladen Rakic
153781
Mladen Rakic  
rickyponting:
sorry..I m using 240 in the code...but still no result. Can any kind soul paste some reference code where multi frame SMA is being used in strategy tester.

Here is a simple EA that uses multi time frame sma and can be used in strategy tester too (use SmaTimeFrame parameter to choose the target time frame for sma) :

extern int SmaPeriod = 14;

extern int SmaPrice = PRICE_CLOSE;

extern int SmaTimeFrame = 0;

int init() { return(0); }

int deinit() { return(0); }

int start()

{

int smaShift = iBarShift(NULL,SmaTimeFrame,Time[0]);

double smaValue = iMA(NULL,SmaTimeFrame,SmaPeriod,0,MODE_SMA,SmaPrice,smaShift);

Comment(DoubleToStr(smaValue,Digits));

return(0);

}
Suvra Prakash Mandal
10
Suvra Prakash Mandal  

based on ur code i have tried below code to pass on the different time frame MA values in a array...but MA values ares not getting passed into the array..showing all zero..pls help.

extern int SmaPeriod = 14;

extern int SmaPrice = PRICE_CLOSE;

extern int SmaTimeFrame = 1440;

int init() { return(0); }

int deinit() { return(0); }

int start()

{

int counted_bars, limit,i;

int BarShift[];

double ExtMA[],smaValue;

counted_bars=IndicatorCounted();

limit=Bars-counted_bars;

for(i=0;i<limit;i++)

{

BarShift= iBarShift(NULL,SmaTimeFrame,Time);

ExtMA = iMA(NULL,SmaTimeFrame,SmaPeriod,0,MODE_SMA,SmaPrice,BarShift);

}

return(0)

Mladen Rakic
153781
Mladen Rakic  
rickyponting:
based on ur code i have tried below code to pass on the different time frame MA values in a array...but MA values ares not getting passed into the array..showing all zero..pls help.

extern int SmaPeriod = 14;

extern int SmaPrice = PRICE_CLOSE;

extern int SmaTimeFrame = 1440;

int init() { return(0); }

int deinit() { return(0); }

int start()

{

int counted_bars, limit,i;

int BarShift[];

double ExtMA[],smaValue;

counted_bars=IndicatorCounted();

limit=Bars-counted_bars;

for(i=0;i<limit;i++)

{

BarShift= iBarShift(NULL,SmaTimeFrame,Time);

ExtMA = iMA(NULL,SmaTimeFrame,SmaPeriod,0,MODE_SMA,SmaPrice,BarShift);

}

return(0)

I will answer with a question : what is the size of your arrays?

You never initialized the arrays so you have zero sized arrays. Make sure your arrays are made correct size. Also, IndicatorCounted() does not work in EAs. You have to get that value some other way (one way would be to check the value of Bars built in variable and compare it to some stored value in your EA)

john1368
97
john1368  

Can this be made MTF??

Mladen Rakic
153781
Mladen Rakic  
john1368:
Can this be made MTF??

john1368

Here you go

_______________

Corrected and updated version posted here : https://www.mql5.com/en/forum/173574

Suvra Prakash Mandal
10
Suvra Prakash Mandal  

1. can i declare any big arbitray size array ? like array[2000]..I was under the impression once i declare array it will dynamically allocate memory.2.saw in couple of places that easiest solution is to use iBars..can i use it without materially affecting the results ?

Mladen Rakic
153781
Mladen Rakic  
rickyponting:
1. can i declare any big arbitray size array ? like array[2000]..I was under the impression once i declare array it will dynamically allocate memory.2.saw in couple of places that easiest solution is to use iBars..can i use it without materially affecting the results ?

1. Yes you can

2. Yes, since iBars() will return you the same number as Bars except that with iBars() you can specify different symbol and time frame

john1368
97
john1368  

Thanks very much,will try it out.