zackgray88
New member
Hi all! I've lurked for quite awhile and have gleaned a lot of useful information a bits of code here and there to build different indicators. I'm a little stuck on trying to finish the one below.
Purpose of Study: Looks at the average daily ATR and divides it by a user input to define what a tight intraday range is for a given stock. This maps out areas of tight consolidations where price may move aggressively away from (load this indicator on $PFE with a 3 minute chart for the past few days). That part of the indicator is working fine for my needs.
Problem: I'm really only interested when I get 5 or more bars consecutive signals in a row (i.e. one bar with a tight range in the midst of a bunch of volatility isn't what I'm looking for). Is there anyway to get this to only plot a signal when there are consecutive number of true signals? I took a stab at the bottom of the code that I just have blanked out.
Any help would be super appreciated!
Purpose of Study: Looks at the average daily ATR and divides it by a user input to define what a tight intraday range is for a given stock. This maps out areas of tight consolidations where price may move aggressively away from (load this indicator on $PFE with a 3 minute chart for the past few days). That part of the indicator is working fine for my needs.
Problem: I'm really only interested when I get 5 or more bars consecutive signals in a row (i.e. one bar with a tight range in the midst of a bunch of volatility isn't what I'm looking for). Is there anyway to get this to only plot a signal when there are consecutive number of true signals? I took a stab at the bottom of the code that I just have blanked out.
Any help would be super appreciated!
Code:
input aggPeriod = AggregationPeriod.DAY;
input length = 20;
input multiplier = 2;
input barperiod = aggregationperiod.three_min;
input atrrange = 40;
def studyPrice = close(period = aggPeriod);
def hi = high(period = aggPeriod);
def lo = low(period = aggPeriod);
def r = hi - lo;
def avgRange = Average(r, length);
def avg = Average(studyPrice, length);
def range = high(period = barperiod) - low(period = barperiod);
def avgbodyLength = ((high(period = barperiod)[1] - low(period = barperiod)[1]) + (High(period = barperiod)[2] - low(period = barperiod)[2]) + (High(period = barperiod)[3] - low(period = barperiod)[3]) + (High(period = barperiod)[4] - low(period = barperiod)[4]) + (High(period = barperiod)[5] - low(period = barperiod)[5]) + (High(period = barperiod)[6] - low(period = barperiod)[6]) + (High(period = barperiod)[7] - low(period = barperiod)[7]) + (High(period = barperiod)[8] - low(period = barperiod)[8])+ (High(period = barperiod)[9] - low(period = barperiod)[9]) + (High(period = barperiod)[10] - low(period = barperiod)[10]) + (High(period = barperiod)[11] - low(period = barperiod)[11]) + (High(period = barperiod)[12] - low(period = barperiod)[12]) + (High(period = barperiod)[13] - low(period = barperiod)[13]) + (High(period = barperiod)[14] - low(period = barperiod)[14]) + (High(period = barperiod)[15] - low(period = barperiod)[15]) + (High(period = barperiod)[16] - low(period = barperiod)[16]) + (High(period = barperiod)[17] - low(period = barperiod)[17]) + (High(period = barperiod)[18] - low(period = barperiod)[18]) + (High(period = barperiod)[19] - low(period = barperiod)[19])+ (High(period = barperiod)[20] - low(period = barperiod)[20])+ (High(period = barperiod)[21] - low(period = barperiod)[21])+ (High(period = barperiod)[22] - low(period = barperiod)[22])+ (High(period = barperiod)[23] - low(period = barperiod)[23])+ (High(period = barperiod)[24] - low(period = barperiod)[24])+ (High(period = barperiod)[25] - low(period = barperiod)[25])+ (High(period = barperiod)[26] - low(period = barperiod)[26])+ (High(period = barperiod)[27] - low(period = barperiod)[27])+ (High(period = barperiod)[28] - low(period = barperiod)[28])+ (High(period = barperiod)[29] - low(period = barperiod)[29])+ (High(period = barperiod)[30] - low(period = barperiod)[30]))/length;
def intradayatr = avgrange/atrrange;
def nan = Double.NaN;
plot tightrange = range< intradayatr;
tightrange.setpaintingstrategy(paintingstrategy.booleAN_POINTS);
#def consecutive = if tightrange then tightrange[1] + 1 else 0;
#plot consecutivebars = consecutive > 5;