Creating a custom indicator from the value of another indicator, chart points out that something is wrong.

 

I want to use the value of another indicator in my own indicator, but from the indicator window I see that the two lines do not coincide.



As you can see from the image above, the dark blue and light blue lines are similar, but not identical. This is my code:


#property copyright "Nicola Peluchetti"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_separate_window

#property indicator_minimum -101

#property indicator_maximum 101

#property indicator_buffers 2

#property indicator_color1 Blue     // Color of the 1st line

#property indicator_color2 Red      // Color of the 2nd line

#property indicator_plots   1

//--- plot Label1

#property indicator_level1     23.6

#property indicator_level2     -23.6

//--- indicator buffers

double  ER[];

double ERM[];


//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

  IndicatorShortName("EFFICIENCY RATIO for Remora");

//--- indicator buffers mapping

   SetIndexBuffer(0,ER);

   SetIndexStyle(0, DRAW_LINE,STYLE_SOLID,2);

   SetIndexLabel(0, "Eff. Ratio Remora");

   

   IndicatorDigits(2);

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

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,                           // Bar index

       Counted_bars;                // Number of counted bars

//--------------------------------------------------------------------

   Counted_bars=IndicatorCounted(); // Number of counted bars

   i=Bars-Counted_bars-1;           // Index of the first uncounted

   while(i>=0)                      // Loop for uncounted bars

     {

      ER[i]=iCustom(NULL,PERIOD_M1,"IL_GRIGIO_EFFICIENCY_V4",2000,"", 21, 21, 2.0, 0,i);;             // Value of 0 buffer on i bar

      i--;                          // Calculating index of the next bar

     }

//----------

   return(rates_total);

  }


What am I doing wrong?

Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • 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. Place manual test order in Strategy...
 

Use "SRC" button to paste programs.

Nobody can confirm the behavior, because there is no "IL_GRIGIO_EFFICIENCY_V4" file.

 
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. They are the same. What you see is the difference in scaling. Look at the values in the  data window.
 
Nicola Peluchetti:

I want to use the value of another indicator in my own indicator, but from the indicator window I see that the two lines do not coincide.

...

What am I doing wrong?

The values are the same but not the scale.
 

Hmm, I wonder why it happen.

#property copyright "Nicola Peluchetti"

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property indicator_separate_window

#property indicator_minimum -101

#property indicator_maximum 101

#property indicator_buffers 2

#property indicator_color1 Blue     // Color of the 1st line

#property indicator_color2 Red      // Color of the 2nd line

#property indicator_plots   1

//--- plot Label1

#property indicator_level1     23.6

#property indicator_level2     -23.6

//--- indicator buffers

double  ER[];

double ERM[];




//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

  IndicatorShortName("EFFICIENCY RATIO for Remora");

//--- indicator buffers mapping

   SetIndexBuffer(0,ER);

   SetIndexStyle(0, DRAW_LINE,STYLE_SOLID,2);

   SetIndexLabel(0, "Eff. Ratio Remora");

   

   IndicatorDigits(2);

   

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

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,                           // Bar index

       Counted_bars;                // Number of counted bars

//--------------------------------------------------------------------

   Counted_bars=IndicatorCounted(); // Number of counted bars

   i=Bars-Counted_bars-1;           // Index of the first uncounted

   while(i>=0)                      // Loop for uncounted bars

     {

      ER[i]=iCustom(NULL,PERIOD_M1,"IL_GRIGIO_EFFICIENCY_V4",2000,"", 21, 21, 2.0, 0,i);;             // Value of 0 buffer on i bar

      i--;                          // Calculating index of the next bar

     }

//----------

   return(rates_total);

  }
 
GrumpyDuckMan:

Hmm, I wonder why it happen.

Because in the original there are no fixed minimum and maximum
 
It has nothing to do with your code. It's because each is being scaled independently.
 

Ok cool, thanks everyobody!

Reason: