stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Bar lookback, over/under pip threshold
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=733
Page 1 of 1
Author:  alphakenny1 [ Mon Jul 30, 2012 5:31 pm ]
Post subject:  Bar lookback, over/under pip threshold

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) :)
Author:  gaheitman [ Mon Aug 27, 2012 4:21 am ]
Post subject:  Re: Bar lookback, over/under pip threshold

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
All times are UTC Page 1 of 1