Time since the last range existing

Hi experts, I intended to do the following.

whenever a stock broke above a trading range , i want the barcount from the beginning of that range. Simply says for how many bars that range was there?

Help me to think the problem properly?

  1. Define your trading range with a variable.

  2. You Cross() to check when price Closes above the range.

  3. Use BarsSince() to evaluate when the cross occurred and get the bar count.
    Note: Barcount is a reserved keyword that you should avoid quoting in wrong context.

thanks for the reply.

sorry for using reserved word.

barssince(cross()) wil give bar count since the breakout happen, but i want to know the start of that range.

if i use

RangeHigh = HHV(H,20); 
RangeLow = LLV(L,20);

it will define a range of last 20 periods.

say price was in this range for not only last 20 bar but for a long time.
So want to know when price entered this range, not exit !

If you define two cross functions,

A =  Cross(UpperRange, C);    // When price enters from higher price into range.

B =  Cross(C, LowerRange);    // Entry from lower range

Then both Arrays will have a record for all the number of times price went into the range.

You can just use a Loop, say While with a Condition and retrieve the Barindex when Array bar was true and go back as far as you want.

Then, work on it as you like. The condition for how back in time you want to go is up to you.

2 Likes