Download MetaTrader 5

Other timeframes

To add comments, please log in or register
Aecio de Feo Flora Neto
7618
Aecio de Feo Flora Neto  

Hello all.

I am working on a test for multiple timeframe indicator and starting with a simple dummy code, as below, results in no bar calculation at all.

The only way for this code to work is selecting D1 timeframe, but I need this information in other timeframes such as M5 and M2.

Any help and comment is much appreciated.

 

 Thanks in advance. 

int hmm;

double mm[];

//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   if ( (hmm = iMA(_Symbol, PERIOD_D1, 20, 0, MODE_SMA, PRICE_CLOSE)) < 0 )
      return(INIT_FAILED);
      
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
{
   IndicatorRelease(hmm);
} 
  
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
//---
   int calculated_mm = BarsCalculated(hmm);
   Print(calculated_mm);
   
//---
   int start = 1;
   
//--- check for data
   if(rates_total < start)
      return(0);

   if(prev_calculated > 0)
      start = prev_calculated-1;
   
//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+
Alexander Voronkov
19507
Alexander Voronkov  
aecioneto:

Hello all.

I am working on a test for multiple timeframe indicator and starting with a simple dummy code, as below, results in no bar calculation at all.

The only way for this code to work is selecting D1 timeframe, but I need this information in other timeframes such as M5 and M2.

Any help and comment is much appreciated.

 

 Thanks in advance. 

Hello,

Note:    if ( (hmm = iMA(_Symbol, PERIOD_D1, 20, 0, MODE_SMA, PRICE_CLOSE)) < 0 )

https://www.mql5.com/en/docs/constants/chartconstants/enum_timeframes

Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Chart Constants / Chart Timeframes - Reference on algorithmic/automated trading language for MetaTrader 5
Aecio de Feo Flora Neto
7618
Aecio de Feo Flora Neto  

Fillellin,

This is *exactly* what I want. A SMA from D1, no matter what TF I am seeing in the chart. 

Alexander Fedosov
8544
Alexander Fedosov  
Instead PERIOD_D1 insert the number of minutes
Aecio de Feo Flora Neto
7618
Aecio de Feo Flora Neto  
Alex2356:
Instead PERIOD_D1 insert the number of minutes

Can you post the entire line, please?

I don't know what you mean here. 

To add comments, please log in or register