Getting values from MACDMomentum Indicator

 

Hi all,

Severeal days ago, I had written about getting values about MACDMomentum Indicators. I couldn't get any answer by them. I really need your help. 
I doenload an indicator called MACDMomentum Indicator on mql5.com. It draws MACD Value, Signal value, and Momentum_Smooth value on the chart as an indicator.
I try to get values of them in my EA. However, I don't understand and don2t know how I can get vallues from indicator.

Indicator outputs are follows; //Macd value (histogram), Signal value (yellow line), an Momentum_smooth value (red line);

MACDMomentum

The code is as follows;

//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Gray// Silver
#property  indicator_color2  Yellow
#property  indicator_color3  White// Silver
#property  indicator_color4 Red // Magenta



#property  indicator_width1  2
//--- indicator parameters
input int InpFastEMA=12;   
input int InpSlowEMA=26;   
input int InpSignalSMA=9;  
input int smooth = 3;
//--- indicator buffers
double    ExtMacdBuffer[];
double    ExtSignalBuffer[];
double    Mom[];
double    Mom_smooth[];
//--- right input parameters flag
bool      ExtParameters=false;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorDigits(Digits+1);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexDrawBegin(1,InpSignalSMA);
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"Signal");
//--- check for input parameters
 
    SetIndexBuffer(2,Mom );
    SetIndexStyle(2,DRAW_LINE,0,1);

     SetIndexBuffer(3,Mom_smooth );
    SetIndexStyle(3,DRAW_LINE,0,3);

   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 = rates_total- 3000;
   if(prev_calculated>0)     limit--;
//--- macd counted in the 1-st buffer
   for(i=limit; i>=0; i--)     ExtMacdBuffer[i]=iMA(NULL,0,InpFastEMA,0,MODE_EMA,PRICE_CLOSE,i)-
                               iMA(NULL,0,InpSlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//--- signal line counted in the 2-nd buffer
  // SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);
    for(i=limit; i>=0; i--) ExtSignalBuffer[i] =  iMAOnArray(ExtMacdBuffer,0,InpSignalSMA,0,0,i);


  for(i=limit; i>=0; i--) Mom[i] = ExtMacdBuffer[i] - ExtMacdBuffer[i+10];
  for(i=limit; i>=0; i--) Mom_smooth[i] = iMAOnArray(Mom,0,smooth,0,0,i);


//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+

I really need your help. I don't understand how I can get values, exactly.

Best,

Murat Y.

 
Murat Yazici:

Hi all,

Severeal days ago, I had written about getting values about MACDMomentum Indicators. I couldn't get any answer by them. I really need your help. 
I doenload an indicator called MACDMomentum Indicator on mql5.com. It draws MACD Value, Signal value, and Momentum_Smooth value on the chart as an indicator.
I try to get values of them in my EA. However, I don't understand and don2t know how I can get vallues from indicator.

Indicator outputs are follows; //Macd value (histogram), Signal value (yellow line), an Momentum_smooth value (red line);

The code is as follows;

I really need your help. I don't understand how I can get values, exactly.

Best,

Murat Y.

You should read the documentation https://docs.mql4.com/indicators/icustom 

See example below. The code gets values at the last finished candle.

string indicatorName="..." // indicator name including path
int fastEMA=12;
int slowEMA=26;
int signalSMA=9;
int smooth=3;
double lastMACD=iCustom(_Symbol,_Period,indicatorName,fastEMA,slowEMA,signalSMA,smooth,0,1);
double lastSignal=iCustom(_Symbol,_Period,indicatorName,fastEMA,slowEMA,signalSMA,smooth,1,1);
double lastMomentum=iCustom(_Symbol,_Period,indicatorName,fastEMA,slowEMA,signalSMA,smooth,3,1);
iCustom - Technical Indicators - MQL4 Reference
iCustom - Technical Indicators - MQL4 Reference
  • docs.mql4.com
[in]  Custom indicator compiled program name, relative to the root indicators directory (MQL4/Indicators/). If the indicator is located in subdirectory, for example, in MQL4/Indicators/ The passed parameters and their order must correspond with the declaration order and the type of extern variables of the custom indicator...
 
Petr Nosek:

You should read the documentation https://docs.mql4.com/indicators/icustom 

See example below. The code gets values at the last finished candle.

Thank you, Petr!!

Best,

Murat

 
Murat Yazici:

Thank you Petr so much!
I try this code however I get n error about cannot open file about indicator.

My indicator is under indicator file with mq4. And, I get this message as follows;

Should I save the file as ex4?
Best,

Murat

First you should try to compile your downloaded indicator (MACD_Momentum.mq4). There must be MACD_Momentum.ex4 file in the "indicators" directory after successfully compiling. Don't rename *.mq4 files into *.ex4 files! 

If you are successful (in compiling the indicator) you have to change the first line in my code into this:

string indicatorName="MACD_Momentum";

If compiling the indicator fail you have to fix bugs.

 
Petr Nosek:

First you should try to compile your downloaded indicator (MACD_Momentum.mq4). There must be MACD_Momentum.ex4 file in the "indicators" directory after successfully compiling. Don't rename *.mq4 files into *.ex4 files! 

If you are successful (in compiling the indicator) you have to change the first line in my code into this:

If compiling the indicator fail you have to fix bugs.

Thank you Petr! Problem is solved.

Best,

Murat

 

Hello guys,


I would like how can i save the previous value of the arrow and only replace it if there is a new arrow with his value.

Thankss


bool BlueArrow = false, RedArrow=false;

int BlueArrowIndex, RedArrowIndex, Index = 0;

double BlueArrowPrice, RedArrowPrice;



while(!BlueArrow && !RedArrow)    //  end while loop when we have found the most recent red and Blue arrows

   {

   if(iCustom(Symbol(),PERIOD_CURRENT,"ema-crossover-signal",50,100,0, Index ) < 2147483647)   //  check for Blue arrow

      {

      BlueArrowIndex = Index;

      BlueArrowPrice = iCustom(NULL,0,"ema-crossover-signal",50,100,0,1);

      BlueArrow = true;

      }



   if(iCustom(Symbol(),PERIOD_CURRENT,"ema-crossover-signal",50,100, 1, Index ) < 2147483647)   //  check for Red arrow

      {

      RedArrowIndex = Index;

      RedArrowPrice = iCustom(NULL,0,"ema-crossover-signal",50,100, 1,1);

      RedArrow = true;

      }

   

   

   Index++;

   }





 Comment("RedArrowPrice  ", RedArrowPrice,"  Barnumber Arrow  ",RedArrowIndex,"\n",

      "    BlueArrowPrice  ", BlueArrowPrice,"  Barnumber Arrow  ",BlueArrowIndex); 

Reason: