Download MetaTrader 5

Higher Time Frame Indicator - page 2

To add comments, please log in or register
Ernst Van Der Merwe
4793
Ernst Van Der Merwe 2014.10.17 09:16  
tparimore:

Right or Wrong, I like to see if the signal line is coming in asymptotic or at a nice angle when it approaches zero. A stair-step line always looks like a shallow angle.

 

Below is a picture of an RSI being shown across all time frames as they would appear (not stair-step). I think what I am looking to do is possible?  ---Tom

 

Sure, but you'd probably need to recalculate the buffer on every new bar.

//+------------------------------------------------------------------+
//|                                                  Custom MACD.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "https://www.mql4.com"
#property description "Moving Averages Convergence/Divergence"
#property strict
//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  Silver
#property  indicator_color2  Red
#property  indicator_width1  2
//--- indicator parameters
input int InpFastEMA=12;   // Fast EMA Period
input int InpSlowEMA=26;   // Slow EMA Period
input int InpSignalSMA=9;  // Signal SMA Period
input int TimeFrame=PERIOD_M5;
input int BarsToCount=50;
//--- indicator buffers
double    ExtMacdBuffer[];
double    ExtSignalBuffer[];
//--- right input parameters flag
bool      ExtParameters=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorDigits(Digits+1);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(0,Bars-BarsToCount);
   SetIndexDrawBegin(1,Bars-BarsToCount);
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
   string    sTimeFrame;
   switch(TimeFrame)
      {
       case PERIOD_MN1: sTimeFrame = "MN1 ";break;
       case PERIOD_W1:  sTimeFrame = "W1 "; break;
       case PERIOD_D1:  sTimeFrame = "D1 "; break;
       case PERIOD_H4:  sTimeFrame = "H4 "; break;
       case PERIOD_H1:  sTimeFrame = "H1 "; break;
       case PERIOD_M30: sTimeFrame = "M30 ";break;
       case PERIOD_M15: sTimeFrame = "M15 ";break;
       case PERIOD_M5:  sTimeFrame = "M5 "; break;
       case PERIOD_M1:  sTimeFrame = "M1 "; break;
       default:         sTimeFrame = "";    break;
      }
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD "+sTimeFrame+"("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
   SetIndexLabel(0,"MACD "+sTimeFrame);
   SetIndexLabel(1,"Signal "+sTimeFrame);

   //ArrayInitialize(ExtMacdBuffer_1,0.0);
   //ArrayInitialize(ExtSignalBuffer_1,0.0);
//--- check for input parameters
   if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
     {
      Print("Wrong input parameters");
      ExtParameters=false;
      return(INIT_FAILED);
     }
   else
      ExtParameters=true;
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
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 i,limit;
//---
   if(rates_total<=InpSignalSMA || !ExtParameters)
      return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated==0) limit=BarsToCount;
   if(prev_calculated>0) limit++;
   static datetime time_prev;
   if(prev_calculated>0 && time_prev!=time[0])
     {
      time_prev=time[0];
      limit=BarsToCount;
      ExtMacdBuffer[limit]=EMPTY_VALUE;
      ExtSignalBuffer[limit]=EMPTY_VALUE;
     }
//--- macd counted in the 1-st buffer
   for(i=0;i<limit; i++)
     {
      ExtMacdBuffer[i]=iMACD(NULL,TimeFrame,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_MAIN,i);
      ExtSignalBuffer[i]=iMACD(NULL,TimeFrame,InpFastEMA,InpSlowEMA,InpSignalSMA,PRICE_CLOSE,MODE_SIGNAL,i);
     }
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
12
To add comments, please log in or register