how to ... ? - page 2

 
mehba:

In this code, the buffer 0 and 1 it working but not displayng on the chart because i want to do so, buffers 2 and 3 is working and displayng on chart and that is ok, the problem is for buffers 4 and 5 the code of them is not make the matematic calcul and not display on chart!

Thank you very much for your help!

I wait for answers!

You probably have to use [i] instead of [0].
 

you calculate with these values before they have value, that part is after this line in the code:


      dUpValue=((((UpRatio[0])+(UpRatio[1])+(UpRatio[2]))/3)*1.008); 

this part is better placed after the other calculations in the while loop.

and as angevoyageur also noticed, probably here also you should use i+0, i+1, i+2.

 
  1. Simplify your loop. Your maximum look back is 6:
    dCurrent<Low[i+6]
    Your code
       nCountedBars=IndicatorCounted();
    //---- last counted bar will be recounted    
       if(nCountedBars<=2)
          i=Bars-nCountedBars-3;
       if(nCountedBars>2)
         {
          nCountedBars--;
          i=Bars-nCountedBars-1;
         }
    //----Up and Down Fractals
       while(i>=2)
    
    Contradictory information on IndicatorCounted() - MQL4 forum
       nCountedBars=IndicatorCounted();
       if(nCountedBars < 6) nCountedBars = 6; // Lookback
       for(int i=Bars - 1 - nCounted; i>=2; i--)
    

  2. You are not setting your values into the array
    UpValue not set
                ExtUpFractalsBuffer[i]=dCurrent;
                UpRatio[i]=dRatio;
                UpValue[0]=dUpValue;
    
    Likewise DownValue
                ExtUpFractalsBuffer[i]=dCurrent;
                UpRatio[i]=dRatio;
                UpValue[i]=dUpValue;
    

  3. The look back code is already handled.
    if(!bFound && (Bars-i-1)>=3)
      {
       if(dCurrent==High[i+1] && dCurrent>High[i+2] && dCurrent>High[i+3] &&
          dCurrent>High[i-1] && dCurrent>High[i-2])
    
    Don't look forward (at bar zero or the future)
    if(!bFound && i>2)
      {
       if(dCurrent==High[i+1] && dCurrent>High[i+2] && dCurrent>High[i+3] &&
          dCurrent>High[i-1] && dCurrent>High[i-2])