Indicator issue history drawing

 

hello all,

I have a question about an indicator issue.

I try to create indicator from two others. I do that because of the limit of 8 buffers for one indictor. And to analyse, i need the history of the indictor, in history, i mean the line before the current bar.

For that, in the final indictor, i use two icustom() functions to call my two first indictors.

My first and second indictors run properly with the history visible (screenshoot). No problem.

But, when i create the final indictor, no history. i loose th history and i have only a horizontal line. When the share price resume, i have my correct line, but only from the moment i put my indictor on shart. before, an horizontal line.

Do you have for thought or suggestion to have the history. My problem is the horizontal line and i would like to have the draw of history (like the two first indicators). I do not see the error.


screenshot

#property copyright "NB"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers   2
#property indicator_color1    LightBlue
#property indicator_color2    Green
#property indicator_level1 20     
#property indicator_level2 50     
#property indicator_level3 80     


//Paramètres du RSI
int Price = 0; /*PRICE_CLOSE    0   Close price.
                 PRICE_OPEN     1   Open price.
                 PRICE_HIGH     2   High price.
                 PRICE_LOW      3   Low price.
                 PRICE_MEDIAN   4   Median price, (high+low)/2.
                 PRICE_TYPICAL  5   Typical price, (high+low+close)/3.
                 PRICE_WEIGHTED 6   Weighted close price, (high+low+close+close)/4. */
int RSI_Period = 2; // Period of RSI
int MA_Mode = 1; // Mode of MA (0 SMA , 1 EMA , 2 SMMA , 3 LWMA)

//Paramètres de la TEMA du RSI
int RSI_TEMA_Period = 3; // Period of the RSI's MA
int RSI_TEMA_Type = 1; // Mode of MA (0 SMA , 1 EMA , 2 SMMA , 3 LWMA)

//Buffers
double RSI[];
double RSI_Aug[];
double RSI_Baisse[];
double TemaRSI[];
double Ema[];
double EmaOfEma[];
double EmaOfEmaOfEma[];

//Déclarations variables

int  j, shift, limit,limit2,limit3,counted_bars;
double Price1, Price2;


//------------------------------------------------------------------
// Initialisation affichage Indicateurs                   
//------------------------------------------------------------------
int init()
{
   IndicatorBuffers(7);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexLabel(0,"RSI Price close");
   SetIndexDrawBegin(0,RSI_TEMA_Period);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexLabel(1,"TEMA RSI Price close");
   SetIndexDrawBegin(1,RSI_TEMA_Period);
   SetIndexBuffer(0,RSI);
   SetIndexBuffer(3,RSI_Aug);
   SetIndexBuffer(2,RSI_Baisse); 
   SetIndexBuffer(1,TemaRSI);
   SetIndexBuffer(4,Ema);
   SetIndexBuffer(5,EmaOfEma);
   SetIndexBuffer(6,EmaOfEmaOfEma);
  
   IndicatorShortName("RSI & TEMA");

  
 
  
    
   return(0);
}

//------------------------------------------------------------------
//Calcul Indicateurs                         
//------------------------------------------------------------------
int start()
  {
   counted_bars=IndicatorCounted();
  
//----
   if ( counted_bars < 0 ) return(-1);
  
   if ( counted_bars ==0 )
         {
         limit=Bars-1;
         } 
     
   if(counted_bars>0)
         {limit=Bars-counted_bars;
          limit--;
         }
  
   for( j=limit; j>=0; j--)
   {
     
   RSI_Aug[j] = iCustom(Symbol (),PERIOD_CURRENT,"RSI_TEMA [Hausse]",1,0);
   RSI_Baisse[j] = iCustom(Symbol (),PERIOD_CURRENT,"RSI_TEMA [Baisse]",1,0);

   }
     
   for( j=limit; j>=0; j--)
   {
  
   double AvgRSI_Aug=RSI_Aug[j];
   double AvgRSI_Baisse=RSI_Baisse[j];
  
   if (AvgRSI_Aug!=0) RSI[j] = 100.0/(1+MathAbs(AvgRSI_Baisse)/MathAbs(AvgRSI_Aug));
   else if (AvgRSI_Aug==0) RSI[j] = 0;   
   }

 if (counted_bars==0)
      {
      limit=Bars-1;
      limit2=limit-RSI_TEMA_Period;
      limit3=limit2-RSI_TEMA_Period;
      }
   if (counted_bars>0)
      {
      limit=Bars-counted_bars-1;
      limit2=limit;
      limit3=limit2;
      }
   for (j=limit;j>=0;j--) Ema[j]=iMAOnArray(RSI,0,RSI_TEMA_Period,0,MA_Mode,j);
   for (j=limit2;j>=0;j--) EmaOfEma[j]=iMAOnArray(Ema,0,RSI_TEMA_Period,0,MA_Mode,j);
   for (j=limit3;j>=0;j--) EmaOfEmaOfEma[j]=iMAOnArray(EmaOfEma,0,RSI_TEMA_Period,0,MA_Mode,j);
   for (j=limit3;j>=0;j--) TemaRSI[j]=3*Ema[j]-3*EmaOfEma[j]+EmaOfEmaOfEma[j];


   return(0);
  }
 
  1. Please use the SRC-Button to post your code!
  2. The limit of 8 buffers for one indicator is not longer valid!
  3. Use Comment() to show the values of your variables to find the problem.
 
Carl Schreiber:
  1. Please use the SRC-Button to post your code!
  2. The limit of 8 buffers for one indicator is not longer valid!
  3. Use Comment() to show the values of your variables to find the problem.

Hello,

First, thanks for your answer.

Sorry for formatting errors, i am new on this forum. I will do better the next time.

The values are correct, but it is true, we do not see them on the screenshoot.

It is really a question of formatting. The horizontal line is the last known value (which is correct) but why  i have no history...

Your second comment is very interesting, i didn't know that, i will re-write the indicator, but the question is still here about issue...

 
niklabefox:

Sorry for formatting errors, i am new on this forum. I will do better the next time.

Not next time...:-D

 
Alain Verleyen:

Not next time...:-D


Done :-)
 
Check your call to iCustom. It should contain bar number as the last parameter and proper buffer index as the previous parameter. For example, you did not pass 'j' to iCustom calls of the sub-indicators and always request 0-th bar.
IndicatorBuffers - Custom Indicators - MQL4 Reference
IndicatorBuffers - Custom Indicators - MQL4 Reference
  • docs.mql4.com
IndicatorBuffers - Custom Indicators - MQL4 Reference
 

Hi all

Thanks everybody for your advise.

I resolve my issue with one indictor in place of three.

Special thanks to Carl Shreiber for his indiction about the number of buffer. :-)

Reason: