4 Candle Reversal Indicator for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
This script looks at 4 candles at a time.
  • If the first 3 candles in the pattern are BEARISH and the 4th candle BULLISH engulfs the 3rd candle then a GREEN triangle UP will display BELOW the 4th candle
  • If the first 3 candles in the pattern are BULLISH and the 4th candle BEARISH engulfs the 3rd candle then a RED triangle DOWN will display ABOVE the 4th candle
This version for ThinkorSwim, I replaced the signals with green and red colored bars.

Recommended timeframes:
  • Hourly and Daily to identify trend / swing trading
  • 5m for day trading





thinkScript Code

Code:
# 4 Candle Analysis
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/3TPknP5w-4-Candle-Analysis/

def candle1_Open = open[3];
def candle1_Close = close[3];
def candle2_Open = open[2];
def candle2_Close = close[2];
def candle3_Open = open[1];
def candle3_Close = close[1];

def candle4_Open = open;
def candle4_Close = close;

def isBullishTripleCandle = (candle1_Close > candle1_Open) and(candle2_Close > candle2_Open) and(candle3_Close >= candle3_Open) and(candle2_Close > candle1_Close);
def engulfCandle3withCandle4 = (candle4_Close <= candle4_Open) and(candle4_Close < candle3_Open);

def bearishReversalPredicted = isBullishTripleCandle and engulfCandle3withCandle4;

def isBearishTripleCandle = (candle1_Close < candle1_Open) and(candle2_Close < candle2_Open) and(candle3_Close <= candle3_Open) and(candle2_Close<candle1_Close);
def engulfCandle3withCandle4_1 = (candle4_Close >= candle4_Open) and(candle4_Close > candle3_Open);

def bullishReversalPredicted = isBearishTripleCandle and engulfCandle3withCandle4_1;

assignPriceColor(if bullishReversalPredicted then Color.Green else if bearishReversalPredicted then Color.Red else Color.White);
 
D

diazlaz

Well-known member
2019 Donor
VIP
This looks like it will have great potential in 1 min chart. need to backtest - adding to my backlog. Does anyone have any good exit indicators that will complement this strategy?
 
BenTen

BenTen

Administrative
Staff
VIP
@diazlaz Heard of DMI Oscillator? It's available in ThinkorSwim. I heard it's very good with helping you stay in and ride the trend. Test it out.
 
D

diazlaz

Well-known member
2019 Donor
VIP
@diazlaz Heard of DMI Oscillator? It's available in ThinkorSwim. I heard it's very good with helping you stay in and ride the trend. Test it out.


Thanks Ben, shows promise, suggest folks to experiment with your favorite and share your findings. I have a number of other ideas I will test.

Here is the 4 candles, turned into arrows, with the SSL as a bar below and a ALMA + DMI below. There are a number of possible exit indicators, you can see the DMI maps nicely, when the DMI turns opposite of the trend exit, the SSL can also be used when it turns counter trend exit, and also once it breaks a lower ALMA it could also be used. (moving average line plotted on the upper).

great potential. suggest folks to play with it some more.
 
BenTen

BenTen

Administrative
Staff
VIP
@diazlaz I'm not sure about your preference or the type of trader you are but for me the 1 minute chart is too noisy. I found the 5m chart to be the bare minimum for day trading. But if the 1m works for you then absolutely use that. I found some great backtesting result with this candle indicator on the 5 minute chart. You should check it out as well.
 
D

diazlaz

Well-known member
2019 Donor
VIP
@diazlaz I'm not sure about your preference or the type of trader you are but for me the 1 minute chart is too noisy. I found the 5m chart to be the bare minimum for day trading. But if the 1m works for you then absolutely use that. I found some great backtesting result with this candle indicator on the 5 minute chart. You should check it out as well.
thanks Ben. I will build systems and have automated algo's trade the 1 minute, intraday trade the 5 minute and then swing trade. also more and more looking at weekly trading position and momentum. I been so focus on the 1 minute chart lately, thanks for awareness and need to go to a higher timeframe. appreciate that.

I'm amazed the simplicity of this indicator and leveraging price action with great potential. we should all pair this up with 1 or 2 additional confirmation indicators and I think this could turn into a viable trading plan.

Here is the an example on a 5 minute MSFT and FB.



 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
@diazlaz Glad to hear your plan. I hope you the best of luck. Great looking chart there. Simple and clean ;)
 
korygill

korygill

Active member
VIP
@diazlaz do have a shareable link to your chart above? I like the mods you did to simplify that layout.
 
D

diazlaz

Well-known member
2019 Donor
VIP
@korygill as promised here is the updates on SSL to display it in bar form and steps to replicate the chart:



Indicators
  1. Modified Ben's BlueMagikSSL (upper)
  2. Modified Ben's 4CandleAnalysis (upper)
  3. DMI_Oscillator (lower)
Changes:

  1. Added Arrows to 4Candle Analysis
  2. Added Arrows to SSL (configure via input)
  3. Added Dashboard Bar to SSL (configure via input)

Code:
# Blue Magik SSL
# I assume this is based on the popular SSL indicator
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/i85H2tZ8-blue-magik/


input period = 10;
input len = 10;
input colorBars = yes;
input showArrows = no;
input showDashboard = no;

def smaHigh = simpleMovingAvg(high, len);
def smaLow = simpleMovingAvg(low, len);
def Hlv = if close > smaHigh then 1 else if close<smaLow then -1 else Hlv[1];
def sslDown = if Hlv< 0 then smaHigh else smaLow;
def sslUp = if Hlv< 0 then smaLow else smaHigh;
plot isup = sslUp;
plot isdown = sslDown;
isup.SetDefaultColor(GetColor(1));
isdown.SetDefaultColor(GetColor(0));
def sBlueSSL = if Hlv< 0 then -100 else 100;
isup.SetHiding (showDashboard);
isdown.SetHiding (showDashboard);

def sColorData = sBlueSSL;
AssignPriceColor(
   if colorBars then    
      if sColorData == 100 then COLOR.GREEN else
      COLOR.RED
   else
     Color.CURRENT);

plot pUP = sBlueSSL crosses above 0;
pUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
pUP.AssignValueColor(COLOR.GREEN);
pUP.SetLineWeight(2);
pUP.SetHiding (!showArrows);

plot pDOWN = sBlueSSL crosses below 0;
pDOWN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
pDOWN.AssignValueColor(COLOR.RED);
pDOWN.SetLineWeight(2);
pDOWN.SetHiding (!showArrows);

plot pDB1 = LowestAll(low) - 0.01;
pDB1.AssignValueColor(
if IsNaN(sBlueSSL) then Color.DARK_GRAY else
if sBlueSSL == 100 then COLOR.GREEN else COLOR.RED);
pDB1.SetPaintingStrategy (PaintingStrategy.HORIZONTAL);
pDB1.SetLineWeight(5);
pDB1.HideTitle();
pDB1.HideBubble();
pDB1.SetHiding (!showDashboard);
 
korygill

korygill

Active member
VIP
Thank you for sharing @diazlaz. Did you know you can also share charts/grids/etc from the menu on the chart? This will put a hyperlink on your clipboard you can then send to others. You have the option to share just the chart, or the chart + all the studies.



For example, here is your chart except I don't have your colored moving average, and I added my own code to change the arrows.

https://tos.mx/XJGDjaZ

From main window, Setup | Open Shared Item and paste in that hyperlink.

Appreciate your post!
 
P

Playstation

Active member
VIP
Is it possible to just have the Red and Green arrows below/above the candles, without changing the default candle colors?
 
horserider

horserider

Well-known member
VIP
@Playstation Never used this study but looking at the code it has an input for bar color. Go into study settings and change it from yes to no.
 
wilmanv

wilmanv

Member
VIP
How change this script don't change the colors on the bars (all white) just leave them as are for default (Green and Red), just show a arrow (green or red) when meet the 4bars reversal? thanks
 
BenTen

BenTen

Administrative
Staff
VIP
@wilmanv Below is the updated script with your requested feature.

Code:
# 4 Candle Analysis
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/3TPknP5w-4-Candle-Analysis/

def candle1_Open = open[3];
def candle1_Close = close[3];
def candle2_Open = open[2];
def candle2_Close = close[2];
def candle3_Open = open[1];
def candle3_Close = close[1];

def candle4_Open = open;
def candle4_Close = close;

def isBullishTripleCandle = (candle1_Close > candle1_Open) and(candle2_Close > candle2_Open) and(candle3_Close >= candle3_Open) and(candle2_Close > candle1_Close);
def engulfCandle3withCandle4 = (candle4_Close <= candle4_Open) and(candle4_Close < candle3_Open);

def bearishReversalPredicted = isBullishTripleCandle and engulfCandle3withCandle4;

def isBearishTripleCandle = (candle1_Close < candle1_Open) and(candle2_Close < candle2_Open) and(candle3_Close <= candle3_Open) and(candle2_Close<candle1_Close);
def engulfCandle3withCandle4_1 = (candle4_Close >= candle4_Open) and(candle4_Close > candle3_Open);

def bullishReversalPredicted = isBearishTripleCandle and engulfCandle3withCandle4_1;

#assignPriceColor(if bullishReversalPredicted then Color.Green else if bearishReversalPredicted then Color.Red else Color.White);

# Plot Signals
plot bullish = bullishReversalPredicted;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(1);
plot bearish = bearishReversalPredicted;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(1);
 
wilmanv

wilmanv

Member
VIP
@wilmanv Below is the updated script with your requested feature.

Code:
# 4 Candle Analysis
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/3TPknP5w-4-Candle-Analysis/

def candle1_Open = open[3];
def candle1_Close = close[3];
def candle2_Open = open[2];
def candle2_Close = close[2];
def candle3_Open = open[1];
def candle3_Close = close[1];

def candle4_Open = open;
def candle4_Close = close;

def isBullishTripleCandle = (candle1_Close > candle1_Open) and(candle2_Close > candle2_Open) and(candle3_Close >= candle3_Open) and(candle2_Close > candle1_Close);
def engulfCandle3withCandle4 = (candle4_Close <= candle4_Open) and(candle4_Close < candle3_Open);

def bearishReversalPredicted = isBullishTripleCandle and engulfCandle3withCandle4;

def isBearishTripleCandle = (candle1_Close < candle1_Open) and(candle2_Close < candle2_Open) and(candle3_Close <= candle3_Open) and(candle2_Close<candle1_Close);
def engulfCandle3withCandle4_1 = (candle4_Close >= candle4_Open) and(candle4_Close > candle3_Open);

def bullishReversalPredicted = isBearishTripleCandle and engulfCandle3withCandle4_1;

#assignPriceColor(if bullishReversalPredicted then Color.Green else if bearishReversalPredicted then Color.Red else Color.White);

# Plot Signals
plot bullish = bullishReversalPredicted;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(1);
plot bearish = bearishReversalPredicted;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(1);

Thanks Mr @BenTen
 
P

pdxtrader

New member
VIP
...... I will build systems and have automated algo's trade the 1 minute, intraday trade the 5 minute and then swing trade. also more and more looking at weekly trading position and momentum.........
Hey diazlaz
Were you able to automate it like TOS will execute based on the indicator without manual intervention?
 
D

diazlaz

Well-known member
2019 Donor
VIP
Hey diazlaz
Were you able to automate it like TOS will execute based on the indicator without manual intervention?
Hi @pdxtrader, i'm working on a automation platform that ties into ToS, will likely have a release towards end of December or January 2020 the latest. still not sure if it will be distributed or not, but will keep you all updated on the progress and learnings.
 
P

pdxtrader

New member
VIP
Hi @pdxtrader, i'm working on a automation platform that ties into ToS, will likely have a release towards end of December or January 2020 the latest. still not sure if it will be distributed or not, but will keep you all updated on the progress and learnings.
Thank you man. Please update me.
 
dougn

dougn

Member
2019 Donor
Thanks Benten for posting this over on Twitter as I had missed it previously. I prefer the arrows as well because I use trend colorization on my charts and would also like to use this in conjunction with one or two other trend change studies.

Would it be possible to provide the script for a watchlist column?

Thanks
 
Top