# Ochoa's Candlestick Reversal System for ThinkorSwim

#### BenTen

Staff
VIP
This indicator consists of different candlestick patterns and reversal system, as explained by Franklin Ochoa in his book.
• Wick Reversal System
• Extreme Reversal System
• Outside Reversal System
• Doji Reversal System
I included the ability to turn off any of the reversal signals above within the indicator's setting. You can use this with the ToS scanner as well.

Note: I could not incorporate the wick reversal system, so it's not part of the script. Credit goes to the original developer LonesomeTheBlue from TradingView.

Code:
``````# Candlestick Reversal System
# Assembled by BenTen at useThinkScript.com

input extreme_reversal = yes;
input outside_reversal = yes;
input doji_reversal = yes;

def O = open;
def C = close;
def H = high;
def L = low;

input bodysize = 0.525;
input barsback = 50;
input bodymultiplier = 2;

def mybodysize = absValue(C - O);
def AverageBody = simpleMovingAvg(mybodysize, barsback);
def mycandlesize = (H - L);
def AverageCandle = simpleMovingAvg(mycandlesize, barsback);

def Elongsignal = ((O[1] - C[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((O[1] - C[1]) >  AverageBody) and (C > O);
def Eshortsignal = ((C[1] - O[1]) >= (bodysize * (H[1] - L[1]))) and ((H[1] - L[1]) > (AverageCandle * bodymultiplier)) and ((C[1] - O[1]) >  AverageBody) and (O > C);

input BarMultiplier = 1.25;

def AverageCandle1 = simpleMovingAvg(mycandlesize, BarsBack);

def Olongsignal = L < L[1] and C > H[1] and (H - L) >= AverageCandle1 * BarMultiplier;
def Oshortsignal = H > H[1] and C < L[1] and (H - L) >= AverageCandle1 * BarMultiplier;

input percentage = 0.1;

def frangehl = H[1] - L[1];
def frangeco = absValue(C[1] - O[1]);
def sma10 = simpleMovingAvg(close, 10);

def Dshortsignal = (frangeco <= frangehl * percentage and C < L[1] and L[1] > sma10 and C < O)  or (C < L[2] and C[1] >= L[2] and frangeco <= frangeco * percentage and C < O and L[2] > sma10);
def Dlongsignal = (frangeco <= frangehl * percentage and C > H[1] and H[1] < sma10 and C > O)  or (C > H[2] and C[1] <= H[2] and frangeco <= frangeco * percentage and C > O and H[2] < sma10);

plot bullish_extreme = if extreme_reversal then Elongsignal else double.nan;
plot bearish_extreme = if extreme_reversal then Eshortsignal else double.nan;

plot bullish_outside = if outside_reversal then Olongsignal else double.nan;
plot bearish_outside = if outside_reversal then Oshortsignal else double.nan;

plot bullish_doji = if doji_reversal then Dlongsignal else double.nan;
plot bearish_doji = if doji_reversal then Dshortsignal else double.nan;

bullish_extreme.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish_extreme.SetDefaultColor(Color.CYAN);
bullish_extreme.SetLineWeight(1);
bearish_extreme.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish_extreme.SetDefaultColor(Color.CYAN);
bearish_extreme.SetLineWeight(1);

bullish_outside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish_outside.SetDefaultColor(Color.MAGENTA);
bullish_outside.SetLineWeight(1);
bearish_outside.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish_outside.SetDefaultColor(Color.MAGENTA);
bearish_outside.SetLineWeight(1);

bullish_doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish_doji.SetDefaultColor(Color.YELLOW);
bullish_doji.SetLineWeight(1);
bearish_doji.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish_doji.SetDefaultColor(Color.YELLOW);
bearish_doji.SetLineWeight(1);``````

#### MerryDay

Staff member
Staff
VIP
@BenTen, you present us with so many interesting scripts. Thank you for all your time!

#### AryanP

##### New member
Does this repaint?

#### AryanP

##### New member
no, candle close and signal is given
Wow. The signals seem very accurate so I thought they repaint if it goes against the signal.

#### ssagar1212

##### New member
Thanks Ben. What would the script look as a scan. And is there a way to add an alert for these reversals in the tos script above? And is there an alert which could be generated on a watchlist column also? Thank you

Think I figured it out:

For scan I used the study and made the condition is true for each one...but since scans are realtime I don't expect to see any results of the scan until opening bell. My time frame is set to Day.

Thank you

Last edited:

#### MerryDay

Staff member
Staff
VIP
@ssagar1212 I am not sure what you are asking? You would set up your scan for the exact same variables that you set up your alerts on.
So if you are alerting on bearish_doji, you scan for bearish_doji. If you want to scan for all the bearish or bullish triggers then you put all the bearish or bullish variables in your scan. Make sure to click on the "any" button. That tells the scanner, that you want to filter if any of the conditions exist.
(change "A0_Example()" to whatever you named your study).
After you save your scan. You open a watchlist with the name of your scan. Be aware there is a 3-7min lag in watchlist updates. It is a TOS limitation there is no workaround.
HTH

#### ssagar1212

##### New member
Thank you MerryDay....done....I forgot about the lag hehe

#### halcyonguy

##### Well-known member
VIP
Thanks Ben. What would the script look as a scan. And is there a way to add an alert for these reversals in the tos script above? And is there an alert which could be generated on a watchlist column also? Thank you

Think I figured it out:

For scan I used the study and made the condition is true for each one...but since scans are realtime I don't expect to see any results of the scan until opening bell. My time frame is set to Day.

Thank you
i tend to buy from stocks in my watchlist, i don't scan.
if you prefer to scan for results, do what merryday posted about above.

here is a version of the original as a column study
cucandlerev02
http://tos.mx/Lz6Kk1F
( i start my custom column studies with cu ...)

i assigned numbers 1-6 , to the 6 possible outputs, so a sorted column would group them in an order, that i thought was correct.
"1 /\ Ext"
"2 /\ Out"
"3 /\ Doj"
"4 \/ Doj"
"5 \/ Out"
"6 \/ Ext"

this is the code i added to original

Code:
``````# add code for column --------------------------------------
# disable plots
# copy plots and convert to def
def bullish_extreme = if extreme_reversal then Elongsignal else double.nan;
def bearish_extreme = if extreme_reversal then Eshortsignal else double.nan;
def bullish_outside = if outside_reversal then Olongsignal else double.nan;
def bearish_outside = if outside_reversal then Oshortsignal else double.nan;
def bullish_doji = if doji_reversal then Dlongsignal else double.nan;
def bearish_doji = if doji_reversal then Dshortsignal else double.nan;

# color vars
# extreme  cyan
def ext = (bullish_extreme or bearish_extreme);
# outside  magenta
def out = (bullish_outside or bearish_outside);
# doji  yellow
def doj = (bullish_doji or bearish_doji);

if bullish_extreme then "1 /\ Ext"
else if bearish_extreme then "6 \/ Ext"
else if bullish_outside then "2 /\ Out"
else if bearish_outside then "5 \/ Out"
else if bullish_doji then "3 /\ Doj"
else if bearish_doji then "4 \/ Doj"
else "9 ---", color.black);

assignbackgroundcolor(if ext then color.cyan else if out then color.magenta else if doj then color.yellow else color.dark_gray);``````

Last edited:

#### ssagar1212

##### New member
Wow....Awesome....thank you so much Halcyonguy....much appreciated!!

#### iSul

##### Member
i tend to buy from stocks in my watchlist, i don't scan.
if you prefer to scan for results, do what merryday posted about above.

here is a version of the original as a column study
cucandlerev02
http://tos.mx/Lz6Kk1F
( i start my custom column studies with cu ...)

i assigned numbers 1-6 , to the 6 possible outputs, so a sorted column would group them in an order, that i thought was correct.
"1 /\ Ext"
"2 /\ Out"
"3 /\ Doj"
"4 \/ Doj"
"5 \/ Out"
"6 \/ Ext"

this is the code i added to original

Code:
``````# add code for column --------------------------------------
# disable plots
# copy plots and convert to def
def bullish_extreme = if extreme_reversal then Elongsignal else double.nan;
def bearish_extreme = if extreme_reversal then Eshortsignal else double.nan;
def bullish_outside = if outside_reversal then Olongsignal else double.nan;
def bearish_outside = if outside_reversal then Oshortsignal else double.nan;
def bullish_doji = if doji_reversal then Dlongsignal else double.nan;
def bearish_doji = if doji_reversal then Dshortsignal else double.nan;

# color vars
# extreme  cyan
def ext = (bullish_extreme or bearish_extreme);
# outside  magenta
def out = (bullish_outside or bearish_outside);
# doji  yellow
def doj = (bullish_doji or bearish_doji);

if bullish_extreme then "1 /\ Ext"
else if bearish_extreme then "6 \/ Ext"
else if bullish_outside then "2 /\ Out"
else if bearish_outside then "5 \/ Out"
else if bullish_doji then "3 /\ Doj"
else if bearish_doji then "4 \/ Doj"
else "9 ---", color.black);

assignbackgroundcolor(if ext then color.cyan else if out then color.magenta else if doj then color.yellow else color.dark_gray);
[
[QUOTE="halcyonguy, post: 60599, member: 10697"]
i tend to buy from stocks in my watchlist, i don't scan.
if you prefer to scan for results, do what merryday posted about above.

here is a version of the original as a column study
cucandlerev02
http://tos.mx/Lz6Kk1F
( i start my custom column studies with cu ...)

i assigned numbers 1-6 , to the 6 possible outputs, so a sorted column would group them in an order, that i thought was correct.
"1 /\ Ext"
"2 /\ Out"
"3 /\ Doj"
"4 \/ Doj"
"5 \/ Out"
"6 \/ Ext"

[IMG]https://i.imgur.com/0uFSXDu.jpg[/IMG]

this is the code i added to original

[code]
# add code for column --------------------------------------
# disable plots
# copy plots and convert to def
def bullish_extreme = if extreme_reversal then Elongsignal else double.nan;
def bearish_extreme = if extreme_reversal then Eshortsignal else double.nan;
def bullish_outside = if outside_reversal then Olongsignal else double.nan;
def bearish_outside = if outside_reversal then Oshortsignal else double.nan;
def bullish_doji = if doji_reversal then Dlongsignal else double.nan;
def bearish_doji = if doji_reversal then Dshortsignal else double.nan;

# color vars
# extreme  cyan
def ext = (bullish_extreme or bearish_extreme);
# outside  magenta
def out = (bullish_outside or bearish_outside);
# doji  yellow
def doj = (bullish_doji or bearish_doji);

if bullish_extreme then "1 /\ Ext"
else if bearish_extreme then "6 \/ Ext"
else if bullish_outside then "2 /\ Out"
else if bearish_outside then "5 \/ Out"
else if bullish_doji then "3 /\ Doj"
else if bearish_doji then "4 \/ Doj"
else "9 ---", color.black);

assignbackgroundcolor(if ext then color.cyan else if out then color.magenta else if doj then color.yellow else color.dark_gray);``````

excuse me , what do you mean by

if bullish_extreme then "1 /\ Ext"
else if bearish_extreme then "6 \/ Ext"
else if bullish_outside then "2 /\ Out"
else if bearish_outside then "5 \/ Out"
else if bullish_doji then "3 /\ Doj"
else if bearish_doji then "4 \/ Doj"

can explain the number and sign

Last edited by a moderator:

#### MerryDay

Staff member
Staff
VIP
excuse me , what do you mean by

if bullish_extreme then "1 /\ Ext"
else if bearish_extreme then "6 \/ Ext"
else if bullish_outside then "2 /\ Out"
else if bearish_outside then "5 \/ Out"
else if bullish_doji then "3 /\ Doj"
else if bearish_doji then "4 \/ Doj"

can explain the number and sign
Ruby:
``````if bullish_extreme then "1 /\ Ext"
else if bearish_extreme then "6 \/ Ext"
else if bullish_outside then "2 /\ Out"
else if bearish_outside then "5 \/ Out"
else if bullish_doji then "3 /\ Doj"
else if bearish_doji then "4 \/ Doj"
else "9 ---", color.black);``````

Last edited:

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?