Help with indicator value on bar(j) not bar i=1

 

Hi Everyone,

Sorry for the subject but I am not sure how to express it correctly.

I wrote an indicator that right now can identify the High/Low (buffer name: Upper/Lower) of a given period, kind of Zigzag point.

The next step should be like that: At bar 1, analyze previous High/Low to identify what is the level of support and resistance.

(for example, resistence or level1[I]= average of most recent 2 High/Upper level) 

That step is where the trouble is.

I cannot pull the value of the previous High/Low for analysis. I guess the reason is that the High/Low is not appear on bar[I] since I need to compare High/Low with bar on Left and bar on Right.

Can you please help me with that? 

(I attached the indicator also) 

Thank you so much.

 SCFX 

 

//---
   int limit=rates_total-prev_calculated-1;
   if(limit<0) limit=2;
   if(prev_calculated>0)
   limit++;
   
//---
for(int i=lookbackwindow;i<=limit;i++)
   {
//==SECTION 1: IDENTIFY HIGHEST/LOWEST POINT ON CHART
      double h=0;
      int position_high=0;
      for(int j=i-lookbackwindow;j<=i+lookbackwindow;j++)
      {  if(High[j]>h)
         {  h=High[j] ;
            position_high=j;
         }
      }
      if(position_high>=i)
      {  upper[position_high]=h+0.002;
         //level1[i]=h+0.004;
         for(int k=position_high;k>i;k--)
            upper[k]=0;
      }
      
   
      double l=1000;
      int position_low=0;
      for(int jj=i-lookbackwindow;jj<=i+lookbackwindow;jj++)
      {  if(Low[jj]<l)
         {  l=Low[jj] ;
            position_low=jj;
         }
      }
      if(position_low>=i)
      {  lower[position_low]=l-0.002;
         for(int kk=position_low;kk>i;kk--)
            lower[kk]=0;
      }
//==SECTION 2: IDENTIFY MAJOR LEVEL FOR CURRENT BAR 1
//FEW NOTE:  imporatnt level is when High/Low occur withing 100 bar.
   //for(int i3=1;i3<=limit;i3++)
 // { if(lower[i3]>0.1) level1[i3]=High[i3]+0.004;
//if(lower[i]>1) level1[i]=High[i]+0.004;
} 
Files:
 

Forum on trading, automated trading systems and testing trading strategies


Hello,

This forum is about MT5/mql5, please post your question about MT4/mql4 on mql4.com forum.

  • They are more people who can answer there.
  • They are more people who can have similar problem there.
  • A forum is not only to get help but to share with the community, mql4/MT4 community isn't the same as mql5/MT5 community.

Reason: