Bar lookback, over/under pip threshold

Post Reply
alphakenny1
Posts: 4
Joined: Mon Jul 30, 2012 4:31 pm

Bar lookback, over/under pip threshold

Post by alphakenny1 »

Hello

New to the forum, but have been silently lurking in the back since the beginning of the forum. I was mostly hanging out in forexfactory, but now that place resembles a kindergarden so i came here.

I come here seeking advice, i have been trading renko charts, and looking for some help improving a indicator i wrote.

What i want is to display the number of bar above and below a certain pip number on X(25 e.g) candles back (100 e.g), in main window:
Candles above 25 = 37
Candles below 25 = 63

So the user input would be number of candles look back, and pip threshold.

My problem lays in how to code the look back candles, any guidance would be nice (code example even nicer) :)
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Bar lookback, over/under pip threshold

Post by gaheitman »

alphakenny1 wrote:Hello

New to the forum, but have been silently lurking in the back since the beginning of the forum. I was mostly hanging out in forexfactory, but now that place resembles a kindergarden so i came here.

I come here seeking advice, i have been trading renko charts, and looking for some help improving a indicator i wrote.

What i want is to display the number of bar above and below a certain pip number on X(25 e.g) candles back (100 e.g), in main window:
Candles above 25 = 37
Candles below 25 = 63

So the user input would be number of candles look back, and pip threshold.

My problem lays in how to code the look back candles, any guidance would be nice (code example even nicer) :)
I think you are looking for something like the code below.

Code: Select all

#property indicator_chart_window
//--- input parameters
extern double    Price;
extern int       BarsBack=100;

int BarsAbove=-1;
int BarsBelow=-1;

int init()  {   return(0);  }
int deinit()  {   return(0);  }


int start()   {
  //only run on new bars
  static datetime bar;
  if (bar == Time[0])
     return(0);
  bar = Time[0];

  //reset our counters
  BarsAbove=0;
  BarsBelow=0;
     
  //look back at our last BarsBack bars
  for (int x=0;x<BarsBack;x++) {
  
     if (Close[x+1] > Price)
        BarsAbove++;
     else
        BarsBelow++;
        
  }
  Comment("Price Level: ",Price, " - Above/Below : ", BarsAbove," / ",BarsBelow);
  return(0);
  }
The code just prints the results as a comment. The trick is using the for loop to look at past values.

George
Post Reply

Return to “Indicators”