I need help with "iBarShift"

 

hello MQLers

I have done drawing the monthly and weekly pivot point but the yearly is kinda tricky, here is my code

//---
   int Counted_bars,i;
   Counted_bars=IndicatorCounted();
   i=Bars-Counted_bars-1;
   while(i>=0)
     {
      shift=iBarShift(Symbol(),PERIOD_MN1,Time[i],0);
      temp=(iHigh(NULL,PERIOD_MN1,iHighest(NULL,PERIOD_MN1,MODE_HIGH,12,Month()))
            +iLow(NULL,PERIOD_MN1,iLowest(NULL,PERIOD_MN1,MODE_LOW,12,Month()))
            +iClose(NULL,PERIOD_MN1,Month()))/3;
      p[i]=temp;
      i--;
     }//End_While
//---

help me, gimme a hint

 

Hint about what? Help you with what? You haven't stated a problem.

You are using Month() to get the last MN1 bar of the year. There for you can only paint this years bars.

Get the Monthly time of Month() - 1, beginning of the year. Get the shift, draw from there on.

move your temp outside the loop.

 
whroeder1:

Hint about what? Help you with what? You haven't stated a problem.


the problem is clear in the code, how to draw yearly pivot with iBarShift?

 
whroeder1:

Get the Monthly time of Month() - 1, beginning of the year. Get the shift, draw from there on.


I still dont get it

 
  1. Don't double post!
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. What part of "Help you with what? You haven't stated a problem." is unclear?
 

I still havent figure out for to get (High, Low, Close) for each year or quarter, in order to draw yearly or quarterly pivot point

 

Hello

thank you for not helping me,I overclocked my brain and figured the Close

   int Counted_bars,i;
   Counted_bars=IndicatorCounted();
   i=Bars-Counted_bars-1;
   while(i>=0)
     {
      for(int j=1; j<=12; j++)
        {
         shift=iBarShift(Symbol(),PERIOD_MN1,Time[i],0)+1;
         if(TimeMonth(Time[i])==j)yearClose=iClose(Symbol(),PERIOD_MN1,shift+j);
        }
      pp[i]=yearClose;
      i--;
     }//End_While

now, looking for the High and Low

 

now where is the problem, the Close is good, High & Low are not good

//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 White
#property indicator_color3 Red
int shift;
double yearClose,yearHigh,yearLow;
double h[],c[],l[];
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,h);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(1,c);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(2,l);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,2);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
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 Counted_bars,i;
   Counted_bars=IndicatorCounted();
   i=Bars-Counted_bars-1;
   while(i>=0)
     {
      shift=iBarShift(Symbol(),PERIOD_MN1,Time[i],0)+1;
      for(int j=1; j<=12; j++)
        {
         if(TimeMonth(Time[i])==j)
           {
            yearClose=iClose(Symbol(),PERIOD_MN1,shift+j);
           }
         yearHigh=iHigh(Symbol(),PERIOD_MN1,iHighest(Symbol(),PERIOD_MN1,MODE_HIGH,12+j,shift));
         yearLow=iLow(Symbol(),PERIOD_MN1,iLowest(Symbol(),PERIOD_MN1,MODE_LOW,12+j,shift));
        }
      h[i]=yearHigh;
      c[i]=yearClose;
      l[i]=yearLow;
      i--;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Samih Abdelli:

now where is the problem, the Close is good, High & Low are not good

What is
12+j

supposed to do? What is actually "j" supposed to do there?

 
Mladen Rakic:
What is

supposed to do? What is actually "j" supposed to do there?


j is number of the month

j helped me getting the yearly close

 
Samih Abdelli:

j is number of the month

j helped me getting the yearly close

J there is not a number of the month - that parameter there is for count, not for shift

You don't need the "for(int j=1; j<=12; j++)" loop at all - those two lines there (without j) are doing the whole job

Reason: