Problem with MultiTimeFrame chart series

To add comments, please log in or register
Vygintas Va
14
Vygintas Va  

Hi, I am new in  MQL. I want to get two MA indicator on one chart with different time frame, but then I set up  iMA() with different time frame (H1->H4)  I get empty chart without error messages.  Maybe someone can help me and say that I am doing wrong.           


#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window 

//---- the indicator will be plotted in the main window
//#property indicator_chart_window 
//---- one buffer will be used for the calculations and plot of the indicator
#property indicator_buffers 2
//---- only one graphic plot is used 
#property indicator_plots    2


#property indicator_type1   DRAW_LINE
#property indicator_type2   DRAW_LINE
#property indicator_color1  Silver
#property indicator_color2  Red
#property indicator_width1  2
#property indicator_width2  1
#property indicator_label1  "period_test_handle"
#property indicator_label2  "period_test_DTDF"

//---- the declaration of the dynamic array
//that will be used further as an indicator's buffer

double   period_test_buffer[];
double   period_test_DTDF_buffer[];
int      period_test_handle;
int      period_test_DTDF_buffer_hnadle;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+  
void OnInit()
  {
//----+
//---- assign the dynamic array ExtLineBuffer with 0th indicator's buffer
   SetIndexBuffer(0,period_test_buffer,INDICATOR_DATA);
   SetIndexBuffer(1,period_test_DTDF_buffer,INDICATOR_DATA);
   period_test_handle=iMA(NULL,PERIOD_H1,10,0,MODE_SMA,PRICE_CLOSE); 
   period_test_DTDF_buffer_hnadle=iMA(NULL,PERIOD_H4,10,0,MODE_SMA,PRICE_CLOSE); 

  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate (const int rates_total,      // size of input time series 
                 const int prev_calculated,  // bars handled in previous call 
                 const datetime& time[],     // Time 
                 const double& open[],       // Open 
                 const double& high[],       // High 
                 const double& low[],        // Low 
                 const double& close[],      // Close 
                 const long& tick_volume[],  // Tick Volume 
                 const long& volume[],       // Real Volume 
                 const int& spread[]         // Spread 
   )
  {
     
     if(CopyBuffer(period_test_handle,0,0,rates_total,period_test_buffer)!=rates_total)
     {
      Print("CopyBuffer from iMA failed, no data");
      return 0;
     }

    if(CopyBuffer(period_test_DTDF_buffer_hnadle,0,0,rates_total,period_test_DTDF_buffer)!=rates_total)
     {
      Print("CopyBuffer from iMA failed, no data");
      return 0;
     }

    
   
  
   return(rates_total);
  }


Test case 

 taridingview copy




  





Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • www.mql5.com
Ask questions on technical analysis, discuss trading systems and improve your MQL5 programming skills to develop your own trading strategies. Communicate and share your experience with traders from anywhere in the world, answer questions and help beginners — MQL5.community is developing along with you. Frequently Asked Questions about the...
Eleni Anna Branou
Moderator
6580
Eleni Anna Branou  

Please use the </> button to insert your above code.


whroeder1
17943
whroeder1  
You are trying to use copy buffer into your buffers. Therefor bar one is one hour ago. bar ten shows ten hours ago etc. Don't mix apples and oranges.
Vygintas Va
14
Vygintas Va  
whroeder1:
You are trying to use copy buffer into your buffers. Therefor bar one is one hour ago. bar ten shows ten hours ago etc. Don't mix apples and oranges.Wn

 iMA function do not recalculate close price buffer? So if I want to get result as in "tradingview" test case I have to calculate avg of last interval or resize the array and copy paste same candle values?    Maybe you now berter way how to get this result?

To add comments, please log in or register