Download MetaTrader 5

momentum on an indicators values

To add comments, please log in or register
pash0603
13
pash0603  

Hello!

 i am trying to draw a momentum graph based on the values of another indicator and not the open/close prices. This indicator may change so i would like something which would work on different indicators :)

 is there any such indicator out there or could someone please help me figure out how to do this?

 all help is appreciated! Thank you!

Alain Verleyen
Moderator
32007
Alain Verleyen  
JD4
1101
JD4  
You could also learn MQL5 and try to code it yourself.  If you go that route and ask questions in the forum, use SRC to show the part of the code you are having trouble with and specifically your problem is.  "Doesn't work" is not specific and will likely get an equally unspecific answer.
Stanislav Korotky
19835
Stanislav Korotky  

You may use something like this:

//+------------------------------------------------------------------+
//|                                            MomentumUniversal.mq4 |
//|                                       Copyright 2015, Marketeer. |
//|                          https://www.mql5.com/en/users/marketeer |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, Marketeer"
#property link      "https://www.mql5.com/en/users/marketeer"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1

#property indicator_label1  "Momentum"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  2

extern int MomentumPeriod = 7;

// indicator buffers
double MomentumBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
  SetIndexBuffer(0, MomentumBuffer);
  return(INIT_SUCCEEDED);
}
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double& price[])
{
  for(int i = rates_total - 1; i >= prev_calculated; i--)
  {
    if(i - MomentumPeriod >= 0)
    {
      MomentumBuffer[i] = price[i] - price[i - MomentumPeriod];
    }
    else
    {
      MomentumBuffer[i] = EMPTY_VALUE;
    }
  }
  return(rates_total);
}
//+------------------------------------------------------------------+

 It works in MT5, but MT4 does not fully support this feature.

You may apply this on any indicator in a separate window (please note - it is NOT applicable for indicators running in the main window). Just open "Parameters" tab in the momentum properties dialog (don't confuse with "Inputs" tab) and choose appropriate element in the "Apply to" combobox (for example, choose "Previous Indicator's Data").

You'll get something like this:

Universal Momentum indicator applied on MACD 

Disclaimer: This was just created from scratch and may contain bugs.

Files:
To add comments, please log in or register