Different Periods on one Chart

 

Hi All,


I've create an indicator based on the difference between two simple moving averages (which goes to zero when they cross). I've added a parameter for period just so I can compare the 15 minute, 30 minute and 1 hour on one chart. The thing is that when I look at them on the 15 minute the values are different than on the 30 minute or 1 hour charts. So if I'm testing at 3am for example, the values on my 3 indicators (the 15 min, 30 min and 1 hour indicators) should be the same no matter which chart they're on. Any ideas why is this is not so?

 

"the values on my 3 indicators (the 15 min, 30 min and 1 hour indicators) should be the same no matter which chart they're on. Any ideas why is this is not so?"

Show your code.

 
phy:

"the values on my 3 indicators (the 15 min, 30 min and 1 hour indicators) should be the same no matter which chart they're on. Any ideas why is this is not so?"

Show your code.

File attached, a very simple indicator that takes in Period as a parameter. I add the indicator to my chart with Period set to 15 min, 30 min and 1 hour. If I change the chart Period I get different values for all three.

Files:
sma_test.mq4  3 kb
 
//+------------------------------------------------------------------+
//|                                                     SMA_Test.mq4 |
//|                                   Copyright © 2008, Kevin Naidoo |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Kevin Naidoo"
#property link      ""
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Yellow
#property indicator_color3 Lime
//---- indicator parameters
extern int epPeriod1 = 15;
extern int epPeriod2 = 30;
extern int multiplier2 = 2;
extern int epPeriod3 = 60;
extern int multiplier3 = 4;
extern int epAveragingPeriod1 = 3;
extern int epAveragingPeriod2 = 5;
extern int BarsToAverage = 1000;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_SECTION);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_SECTION);
   SetIndexBuffer(2,ExtMapBuffer3);
   string short_name = "SMA("+epAveragingPeriod1+")-SMA("+epAveragingPeriod2+") ("+epPeriod1+") ("+epPeriod2+") ("+epPeriod3+") ";
   IndicatorShortName(short_name);
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i;
   BarsToAverage = MathMin(Bars-1-epPeriod3, BarsToAverage);
   
   for(i=0; i< BarsToAverage; i++)
   {     
     ExtMapBuffer1[i] = EMPTY_VALUE;
     ExtMapBuffer2[i] = EMPTY_VALUE;
     ExtMapBuffer3[i] = EMPTY_VALUE;
  }
 
   for(i=0; i< BarsToAverage; i++)
   {     
     ExtMapBuffer1[i]  = iMA(Symbol(), epPeriod1, epAveragingPeriod1, 0, 0, PRICE_OPEN, i) - iMA(Symbol(), epPeriod1, epAveragingPeriod2, 3, 0, PRICE_OPEN, i);
     ExtMapBuffer2[i*multiplier2 ] = iMA(Symbol(), epPeriod2, epAveragingPeriod1, 0, 0, PRICE_OPEN, i) - iMA(Symbol(), epPeriod2, epAveragingPeriod2, 3, 0, PRICE_OPEN, i);
     ExtMapBuffer3[i*multiplier3 ] = iMA(Symbol(), epPeriod3, epAveragingPeriod1, 0, 0, PRICE_OPEN, i) - iMA(Symbol(), epPeriod3, epAveragingPeriod2, 3, 0, PRICE_OPEN, i);
   }
   return(0);
  }
//+------------------------------------------------------------------+
If you choose other timeframes, you will have to adjust the multiplier.
 
phy:
If you choose other timeframes, you will have to adjust the multiplier.

Thank you phy! I understand what you're doing and I see it does make the averages more reliable and accurate. However, I still have the same problem even with the indicator you've given me now. What I've noticed though is that the actually graphs stay the same (the same curves etc.), just the time lines are different.


So what I mean is, I put down a vertical line at say 1pm (19/08/2008) and then change the period to one of 15, 30 or 60. The values at 1pm are different on that vertical line for each period selected. However, the values at 1pm (19/08/2008) on the 1 hour chart are the same as the values at 1:30pm (20/08/2008) and the same as the values at 1:45pm (21/08/2008)! Trying another example, 1H at 7pm (20/08/2008)=30min at 4:30pm (21/08/2008)=15min at 9:15am (21/08/2008). In fact, if I flip from 15min to 30min to 1hour, the graph stays exactly the same, it's just the timelines (x-axis) that changes.


Any ideas. (this happens to the indicator you've given me and the one I've done.)

 

Think real hard about the relationship of time and number of bars.

The indicator is locked to the lowest time frame, in the example above, 15m.

 
Gambit317z wrote >>

Hi All,

I've create an indicator based on the difference between two simple moving averages (which goes to zero when they cross). I've added a parameter for period just so I can compare the 15 minute, 30 minute and 1 hour on one chart. The thing is that when I look at them on the 15 minute the values are different than on the 30 minute or 1 hour charts. So if I'm testing at 3am for example, the values on my 3 indicators (the 15 min, 30 min and 1 hour indicators) should be the same no matter which chart they're on. Any ideas why is this is not so?

I'm thinking it has something to do with the fact that you can have a trend within a trend, e.g. a 5 min chart can trend up and down in the same time period that a

1 hour chart may only have a trend in one direction, up or down.

You may be able to tell me how to add a parameter to do what I'm trying to do. Please read my question regarding the Heiken Ashi Smooth indicator, where I want add a straight line of all the different time frames at the bottom of the chart so that you can see them all at the same time. I've seen this, but don't know how to do it. The Heiken Ashi Smoothed appears as green and red "candles", depending on whether the trend is up or down. When you see them in a straight line they can differ in colour for the different time frames. This might also help you answer your question. Regards, JohanB.

Reason: