Using Lower Time Frame Reversal Bars Intra day

truthntrading

New member
Hello All,

I need some help fleshing out an indicator that then can be added as a strategy for forward testing.

Parameters

I limit the time it operates in and i want a visual aid to make it easily actionable.

Based on a mashup of other peoples work on here i have the very rough framework but need some assistance adding things. and getting it working.

Currently i don't know how to reference the reversal bar high, low or mid. it gives me a class error when i try to do so.

In addition to coloring the reversal bar as i already have i would like to add horizontal lines at high,low and mid as well as a cloud between them , exactly like PAM

Sr42giF.png


Depending on Timeframe there may be more than one bar highlighted, so bonus points for being able to toggle highlight 1. the highest reversal bar 2. the lowest 3. both highest n lowest 4. all

Thank you in advance to anyone who can help point me in the right direction. @Chemmy @SleepyZ @mashume @halcyonguy

Code:
 def H = high;
def L = low;

def reversalbar  = if high > high[1] and
                     low < low[1]
                  then 1
                  else Double.NaN;
         
input pricecolor = yes;

AssignPriceColor(if !pricecolor
                 then color.current else
                 if !isNaN(reversalbar) then color.orange ;

def closeh = close(period=aggregationperiod.hour);
 def RBH = high(reversalbar);

def IB = if SecondsFromTime(1031) > 0 and SecondsTillTime(1140) > 0 then 1 else 0;
def MPeriod = if secondsTillTime(1600) < 1800 and secondsTillTime(1600)[1] > 1800 then 1 else 0;

def price = close;



#buy condition

def buyc = h crosses above RBH;
def sellc = h crosses above closeh[-1];

AddOrder(OrderType.BUY_to_OPEN,buyc and IB==1, name="BTOFADE", yes);
AddOrder(OrderType.SELL_to_cLOSE, sellc or MPeriod==1, name="STCFADE", yes);
 
Last edited:
Solution
@truthntrading
The reversalbar series is holding a value, not the point at which it is 1 (it holds a stream of 1 and NaNs). You need to set the RBH value as you go, not using a lookback idea.
Code:
def RBH = if reversalbar == 1 then high else RBH[1];
This code translates to: if the value of the reversalbar for the current bar is 1 then set the value of RBH to the current bar high othewise carry the previous value of RBH forward to this bar.

Hope that helps
-mashume
@truthntrading
The reversalbar series is holding a value, not the point at which it is 1 (it holds a stream of 1 and NaNs). You need to set the RBH value as you go, not using a lookback idea.
Code:
def RBH = if reversalbar == 1 then high else RBH[1];
This code translates to: if the value of the reversalbar for the current bar is 1 then set the value of RBH to the current bar high othewise carry the previous value of RBH forward to this bar.

Hope that helps
-mashume
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@truthntrading
The reversalbar series is holding a value, not the point at which it is 1 (it holds a stream of 1 and NaNs). You need to set the RBH value as you go, not using a lookback idea.
Code:
def RBH = if reversalbar == 1 then high else RBH[1];
This code translates to: if the value of the reversalbar for the current bar is 1 then set the value of RBH to the current bar high othewise carry the previous value of RBH forward to this bar.

Hope that helps
-mashume
Thanks for that answer mashume @mashume and for taking the time to respond.

I'm going to toy around with that code and see if I make any progress referencing high-low-mid of the reversal bar.

If not I'll come back and post here for more assistance if I need it.

Thanks again and really appreciate your contributions.
 
thanks @halcyonguy

i really appreciate the sample code and pointing me in the right direction.

Following your logic i edited it slightly to include the mid of the bar as a line as well so that's a BIG WIN.

THANK YOU THANK YOU!!

I'm sure i can create a cloud between those two values as well.

this is what i added.

Code:
def m;
m = ((h+l)/2);
 m = mid[1];
m =na;

plotzm = m;


How would i have the candle directly before the reversal bar plot instead of the values of the reversal bar itself?

i tried changing the plots to

plot zh = h[-1] etc
l[-1]
m[-1]

but that simply shifts the plot of the reversal bar numbers to anchor over the candle formed before it.

if i change the calcs of
h=h[-1] etc it doesn't load the plots or colors at all.

any pointers please?

as for the toggles it would be on the timeframe i'm on.

so say a 4day 5m chart , the lowest reversal bar in the range, the highest in the range.

[Resolved] i used the

Code:
if reversalbar[-1]

to reference the bar before the reversal bar. last issue is to create multiple lines and clouds without them joining together as described below.
find the highest value , during when?
the whole chart? each day?, each week? each hour?

----------
when a reverse bar happens, read the high, low, mid,
if bar is within x bars ( say 10 bars) of the reverse bar, then set those values to previous value,
else na

an example to get you started

Code:
def bars = 10;
def bn = barnumber();
def na = double.ban;

def revbn;
def h;
def l;
if reverse then {
h=high;
l=low;
revbn = bn;
} else if bn < (revbn[1] + bars) then {
h=h[1];
l=l[1];
revbn = revbn[1];
} else {
h=na;
l=na;
revbn=na;
}
plot zh = h;
plot zl = l;


to plot more than 1 line on a bar, you need more than 1 plot line.

take a look at this gap study.
it looks for a a signal (gap), then plots horizontal lines.

it can plot 4 sets of lines on 1 bar, by having 4 sets of plot code lines.

it counts the signals and resets the lines , on every 4th signal.
seq , counts the signals and determines which data set to be updated. 1,2,3, or 4


# sequence counter, thru the qty
# 1,2,3,0,1,2,3,0...
def seq1 = (cnt % gapqty);
# chg to be, 1,2,3,4,1,2,3,4,...
def seq = if seq1 == 0 then gapqty else seq1;

https://usethinkscript.com/threads/...ses-into-it-for-thinkorswim.11186/#post-97722

thanks @halcyonguy

i really appreciate the sample code and pointing me in the right direction.

Following your logic i edited it slightly to include the mid of the bar as a line as well so that's a BIG WIN.

THANK YOU THANK YOU!!

I'm sure i can create a cloud between those two values as well.

this is what i added.

Code:
def m;
m = ((h+l)/2);
 m = mid[1];
m =na;

plotzm = m;


How would i have the candle directly before the reversal bar plot instead of the values of the reversal bar itself?

i tried changing the plots to

plot zh = h[-1] etc
l[-1]
m[-1]

but that simply shifts the plot of the reversal bar numbers to anchor over the candle formed before it.

if i change the calcs of
h=h[-1] etc it doesn't load the plots or colors at all.

any pointers please?

as for the toggles it would be on the timeframe i'm on.

so say a 4day 5m chart , the lowest reversal bar in the range, the highest in the range.

I used this to add clouds to the high-mid-low of the reversal bar.

Code:
#AddCloud(zh ,zm, Color.RED, Color.RED);
#AddCloud(zm,zl , Color.GREEN, Color.GREEN);

the lines for the reversal bars all join from every area over the chart, as well as when i add the cloud to it. the clouds are similiarly joined.

how do i separate the lines and the clouds?

is that using the logic of the gap fill Gap FIll Clouds?

I'm looking to see how i can apply that to the identified reversal bar.

Clouds and Lines
 
Last edited by a moderator:
Hello All,

I need some help fleshing out an indicator that then can be added as a strategy for forward testing.

Parameters

I limit the time it operates in and i want a visual aid to make it easily actionable.

Based on a mashup of other peoples work on here i have the very rough framework but need some assistance adding things. and getting it working.

Currently i don't know how to reference the reversal bar high, low or mid. it gives me a class error when i try to do so.

In addition to coloring the reversal bar as i already have i would like to add horizontal lines at high,low and mid as well as a cloud between them , exactly like PAM

Sr42giF.png


Depending on Timeframe there may be more than one bar highlighted, so bonus points for being able to toggle highlight 1. the highest reversal bar 2. the lowest 3. both highest n lowest 4. all

Thank you in advance to anyone who can help point me in the right direction. @Chemmy @SleepyZ @mashume @halcyonguy

Code:
 def H = high;
def L = low;

def reversalbar  = if high > high[1] and
                     low < low[1]
                  then 1
                  else Double.NaN;
         
input pricecolor = yes;

AssignPriceColor(if !pricecolor
                 then color.current else
                 if !isNaN(reversalbar) then color.orange ;

def closeh = close(period=aggregationperiod.hour);
 def RBH = high(reversalbar);

def IB = if SecondsFromTime(1031) > 0 and SecondsTillTime(1140) > 0 then 1 else 0;
def MPeriod = if secondsTillTime(1600) < 1800 and secondsTillTime(1600)[1] > 1800 then 1 else 0;

def price = close;



#buy condition

def buyc = h crosses above RBH;
def sellc = h crosses above closeh[-1];

AddOrder(OrderType.BUY_to_OPEN,buyc and IB==1, name="BTOFADE", yes);
AddOrder(OrderType.SELL_to_cLOSE, sellc or MPeriod==1, name="STCFADE", yes);

find the highest value , during when?
the whole chart? each day?, each week? each hour?

----------
when a reverse bar happens, read the high, low, mid,
if bar is within x bars ( say 10 bars) of the reverse bar, then set those values to previous value,
else na

an example to get you started

Code:
def bars = 10;
def bn = barnumber();
def na = double.ban;

def revbn;
def h;
def l;
if reverse then {
h=high;
l=low;
revbn = bn;
} else if bn < (revbn[1] + bars) then {
h=h[1];
l=l[1];
revbn = revbn[1];
} else {
h=na;
l=na;
revbn=na;
}
plot zh = h;
plot zl = l;


to plot more than 1 line on a bar, you need more than 1 plot line.

take a look at this gap study.
it looks for a a signal (gap), then plots horizontal lines.

it can plot 4 sets of lines on 1 bar, by having 4 sets of plot code lines.

it counts the signals and resets the lines , on every 4th signal.
seq , counts the signals and determines which data set to be updated. 1,2,3, or 4


# sequence counter, thru the qty
# 1,2,3,0,1,2,3,0...
def seq1 = (cnt % gapqty);
# chg to be, 1,2,3,4,1,2,3,4,...
def seq = if seq1 == 0 then gapqty else seq1;

https://usethinkscript.com/threads/...ses-into-it-for-thinkorswim.11186/#post-97722
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
460 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top