Indicator doesnt get displayed

 

Hello Trading friends,

I coded the attached indicator but when i load it to a chart, it doesnt get displayed...i assume that the array is empty but idk why.

The idea is the following: First the the difference between aroon up and aroon down signals are calculated.

The second indicator is the ADX indicator. Here the difference between the DI+ and DI- are calculated and multiplied with the adx trendline resulting in another array. 

in the indicator "TREND_DIFF" i just want to add these two values. 


I have calculated the two indicators seperatly and i just want to add up the Histogram values of those two. You find them in the attachement too.


Any ideas why it doesnt work?


Cheers

Files:
 

You have to bind specific indicator buffers with "SetIndexBuffer" in the "int init()".

SetIndexBuffer(1, DiPlusFinal);
SetIndexBuffer(2, DiMinusFinal);
.
.
.


 
Naguisa Unada:

You have to bind specific indicator buffers with "SetIndexBuffer" in the "int init()".

Hmm doesnt change anything since i definded the indicator buffer at the beginning already

 
akuh: Hmm doesnt change anything since i definded the indicator buffer at the beginning already
  1. Please don't add text inside quoted text or CODE blocks, put it outside.
              MQL4 forum editor problem - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. // TREND_DIFF.mq4
    //---- buffers
    double MomBuffer1[],MomBuffer2[],MomBuffer3[];
    double DiPlusFinal[];
    double DiMinusFinal[];
    double ADXFinal[];
    double DIPlusLead[];
    double DIMinusLead[];
    double ADXLead[];
    double ADXDIFF[];
    double sum[];
    int init(){   
       SetIndexStyle(0,DRAW_HISTOGRAM);
       SetIndexBuffer(0,sum);
    
    No, you didn't. Only sum is a buffer. All the rest of the arrays have zero size.
 
akuh:
Please don't answer inside the quote.
 
whroeder1:
  1. Please don't add text inside quoted text or CODE blocks, put it outside.
              MQL4 forum editor problem - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. No, you didn't. Only sum is a buffer. All the rest of the arrays have zero size.

Thank you for your answers. Now is my question,  do i have to define the other arrays with SetIndexBuffer() although i dont want to display them?

My goal is to only display the Histogram of the Sum of the required two values without displaying all the other arrays.

 
akuh :

Hmm ok. Do i have to definde the with SetIndexBuffer() although i dont want to display them?

My goal is to only display the Histogram of the Sum of the required two values without displaying all the other arrays.

All other buffers are required for calculation. However, it's impossible in your program, because they have size zero.

 
Naguisa Unada:

All other buffers are required for calculation. However, it's impossible in your program, because they have size zero.

int init()
  {
   string short_name;
//---- indicator line
  IndicatorBuffers(11);
      SetIndexBuffer(0,sum);
      SetIndexStyle(0,DRAW_HISTOGRAM);
      
 //--------     
      SetIndexBuffer(1,MomBuffer1);
      SetIndexBuffer(2,MomBuffer2);
      SetIndexBuffer(3,MomBuffer3);
      SetIndexBuffer(4,DiPlusFinal);
      SetIndexBuffer(5,DiMinusFinal);
      SetIndexBuffer(6,ADXFinal);
      SetIndexBuffer(7,DIPlusLead);
      SetIndexBuffer(8,DIMinusLead);
      SetIndexBuffer(9,ADXLead);
      SetIndexBuffer(10,ADXDIFF);

Ok i inserted this. Can i have a little help what the next step is?


Thanks you guys still for the help.

 
 i=Bars-MomPeriod-1;
   if(counted_bars>=MomPeriod) i=Bars-counted_bars-1;//15-14-1=0
   int nHigh,nLow;
   while(i>=0)
     {
      double Max=-100000;
      double Min=100000;
      for(int k=i;k<i+MomPeriod;k++){
         double Num=Close[k];
         if(Num>Max){
            Max=Num;
            nHigh=k;
         }
         if(Num<Min){
            Min=Num;
            nLow=k;
         }
      }
     //Aroon Indicator math..
      MomBuffer1[i]=100.0*(MomPeriod-(nHigh-i))/MomPeriod;
      MomBuffer2[i]=-100.0*(MomPeriod-(nLow-i))/MomPeriod;
      MomBuffer3[i]=(MomBuffer1[i]+MomBuffer2[i]);
      i--;
     }  //<----------------------(1) Add this one
 
     for(i = limit; i >= 0; i--)
     {
       DIPlus = iADX(NULL, 0, per, PriceType, MODE_PLUSDI, i);
       DIMinus = iADX(NULL, 0, per, PriceType, MODE_MINUSDI, i);
       ADX = iADX(NULL, 0, per, PriceType, MODE_MAIN, i);
       DIPlus1 = iADX(NULL, 0, per, PriceType, MODE_PLUSDI, i + 1);
       DIMinus1 = iADX(NULL, 0, per, PriceType, MODE_MINUSDI, i + 1);
       ADX1 = iADX(NULL, 0, per, PriceType, MODE_MAIN, i + 1);
       //----
       DIPlusLead[i] = 2*DIPlus + (alpha1 - 2) * DIPlus1 + 
                       (1 - alpha1) * DIPlusLead[i+1];
       DIMinusLead[i] = 2*DIMinus + (alpha1 - 2) * DIMinus1 + 
                        (1 - alpha1) * DIMinusLead[i+1];
       ADXLead[i] = 2*ADX + (alpha1 - 2) * ADX1 + (1 - alpha1) * ADXLead[i+1];
     }   
   for(i = limit; i >= 0; i--)
     {
       DiPlusFinal[i] = alpha2*DIPlusLead[i] + (1 - alpha2) * DiPlusFinal[i+1];
       DiMinusFinal[i] = -1*alpha2*DIMinusLead[i] + (1 - alpha2) * DiMinusFinal[i+1];
       ADXFinal[i] = alpha2*ADXLead[i] + (1 - alpha2) * ADXFinal[i+1];
       ADXDIFF[i]= (DiPlusFinal[i]+DiMinusFinal[i])*ADXFinal[i]*0.1;
       
       sum[i]=MomBuffer3[i]+ADXDIFF[i];
     }  
    
    
     
      
      
     //}  <----------------------(2) Delete this one
   return(0);
  }
 


Ok so the Buffers of the ADX indicator are full with correctly calculated values. Now the mistake must be with the aroon buffersr "Mombuffer" since these buffers are empty. Can you guys figure out why they are not calculated ? I dont see a  mistake in the code.


Cheers, akuh

 
As in # 8, fix two points of "}", then work well.
Reason: