Indicator period_m1 is not drawn on a backtest with 5 minute choosen as time period

 
//--------------------------------------------------------------------
// userindicator.mq4 
// The code should be used for educational purpose only.
//--------------------------------------------------------------------
#property indicator_separate_window // Indicator is drawn in the main window
#property indicator_buffers 1       // Number of buffers
#property indicator_color1 Blue     // Color of the 1st line
double Buf_0[];                     // Declaring arrays (for indicator buffers)
//--------------------------------------------------------------------
int init()                          // Special function init()
  {
   SetIndexBuffer(0,Buf_0);         // Assigning an array to a buffer
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,2);// Line style
   return;                          // Exit the special funct. init()
  }
//--------------------------------------------------------------------
int start()                         // Special function start()
  {
   int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
   while(i>=0)                      // Loop for uncounted bars
     {
   Buf_0[i]=iMomentum(NULL,PERIOD_M1,14,PRICE_CLOSE,0);             // Value of 0 buffer on i bar
      i--;                          // Calculating index of the next bar
     }
//--------------------------------------------------------------------
   return;                          // Exit the special funct. start()
  }
//--------------------------------------------------------------------

I want to draw the momentum using period_m1 when backtesting with 5 minute choosen as time period.

Problem: Momentum period_m1 is only drawn if I backtest with 1 minute choosen as time period.

Has someone an idea how this could work?

Thanks in advance!

 
APeng:

I want to draw the momentum using period_m1 when backtesting with 5 minute choosen as time period.

Problem: Momentum period_m1 is only drawn if I backtest with 1 minute choosen as time period.

Has someone an idea how this could work?

Thanks in advance!

Forget backtesting . . it doesn't work on a live chart.

 

Try this . . .

 Buf_0[i]=iMomentum(NULL,PERIOD_M1,14,PRICE_CLOSE, i );   
 
But that isn't quite correct . .. IMO but at leaat it paints something more than a horizontal line.
 

Try this . . .

Buf_0[i]=iMomentum(NULL,PERIOD_M1,14,PRICE_CLOSE, i*Period() );  



 

It draws a graph before I start the backtest. But the momentum´s values are different (test 1: 1 minute, test2:5 minute). When I start the backtest, a horizontal line is drawn.

Is it only a problem for MT to visualize the graph? Then at least I could use the data. The idea is to open an order on a higher timeframe when the price breaks out of a channel and to analyze the following movement depending on a smaller timeframe.


 

You are testing on M5 data, how should MT4 calculate M1?

Instead you have to start your test on M1 chart and internally get the values from higher timeframes (which is possible). The other way, (getting values from lower timeframes) is not possible

 

hi zzuegg!

Using

double Min_15 = iMomentum(NULL,PERIOD_M15 ,20,PRICE_CLOSE,1);

double H1 = iMomentum(NULL,PERIOD_H1 ,20,PRICE_CLOSE,1);

Alert("Min_15: ",Min_15," Min_60: ",H1);

delivers results for H1 an Min_15. On 15 minute timeframe and on 1 h timeframe.

The Problem seems to be the drawing of the results via an indicator. Another option would be to export the results to excel and to draw the graph there. But that would be very uncomfortabel :/

 
APeng:

hi zzuegg!

The Problem seems to be the drawing of the results via an indicator. Another option would be to export the results to excel and to draw the graph there. But that would be very uncomfortabel :/

If you are drawing the Indicator on an M15 chart you can only plot points at the M15 time intervals . . . i.e. every 15 mins, hence my change to your code . . .

Buf_0[i]=iMomentum(NULL,PERIOD_M1,14,PRICE_CLOSE, i*Period() );  

because you are looking at a sample size of 14 the sample boundaries from M1 to M15 will probably not synchronise. Try a sample size of 15, you may well get a better match . . .

 
RaptorUK:

If you are drawing the Indicator on an M15 chart you can only plot points at the M15 time intervals . . . i.e. every 15 mins, hence my change to your code . . .

because you are looking at a sample size of 14 the sample boundaries from M1 to M15 will probably not synchronise. Try a sample size of 15, you may well get a better match . . .

I used your code

Buf_0[i]=iMomentum(NULL,PERIOD_M1,14,PRICE_CLOSE, i*Period() );
and I got what I´ve shown above . Don´t know exactly what you mean with a sample size of 15?
 
APeng:

I used your code

and I got what I´ve shown above . Don´t know exactly what you mean with a sample size of 15?

By Sample size I was talking about the "Period - amount of bars for calculation of price changes" . . .

iMomentum( string symbol, int timeframe, int period, int applied_price, int shift)


Parameters:
symbol - Symbol the data of which should be used to calculate indicator.NULL means the current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
period - Period (amount of bars) for calculation of price changes.
applied_price - Applied price. It can be any of Applied price enumeration values.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
Reason: