Repaints Trend Reversal for ThinkorSwim

Repaints
Status
Not open for further replies.
Really enjoyed reading your write up and analysis. Great work backtesting. I have been anecdotally seeing some success trying to use both indicators myself, but didn't manually backtest it. Quick question -- what was your strategy around using the 10m chart instead of perhaps the 5m?
In all honesty, I used the 10 minute time frame due to a couple of factors:

1. OnDemand allows you to skip time frames with a push of a button by 10 minutes. So instead of having to go into the calendar each time and skip by 5 minutes, I went for the simple way.
2. I believe that trading on the 10m with this indicator showed less reversals, creating a higher probability of making more money.

I usually trade on the 3m and 5m, but after reviewing this indicator in depth, I have found that using higher tame frames show less reversal arrows, especially false reversal arrows, which could potentially create more profit. I would have done the 15m, but due to reason 1 and the fact that 15m is a little too high for my taste for intraday trading, the 10m sat well with me.
 
Last edited:

Volatility Trading Range

VTR is a momentum indicator that shows if a stock is overbought or oversold based on its Weekly and Monthly average volatility trading range.

Download the indicator

What time frame are you using again? I trade on a 3 or 5 min candle. I would be happy to have the assistance for the buys now what i am trying to code is the conditional order that aligns with the buy signal... any thoughts????
I was trading on the 10 minute. If I do more back testing in the future with these indicators, I will most likely try out the 5m timeframe; however, I want to try and make sure I am almost 100% comfortable with trading on the 10m before I try using the 5m.

Also, I would actually love to set up a conditional order with this indicator. How would you be able to do this?

TMO: http://tos.mx/Bghxj42
TR: http://tos.mx/GFhAsJa

I would like to combine these two indicators to set an automatic order like this:

1. Short when TMO and TR both show a reversal at the same time or if they show up two different candles right after the other. Set a stop loss at the high of the previous candle. Buy when the TMO and TR show an opposite reversal at the same time or if they show up two different candles one after the other. If that condition does not occur, buy once a candle closes in the opposite zone (-5 to -15 red zone)

2. Long when TMO and TR both show a reversal at the same time or if they show up two different candles right after the other. Set a stop loss at the low of the previous candle. Sell when the TMO and TR show an opposite reversal at the same time or if they show up two different candles one after the other. If that condition does not occur, sell once a candle closes in the opposite zone (5 to 15 green zone)
 
Last edited:
Hi @Gabrielx77, Thank you for your testing and analysis. I do think using both these indicators will give a higher probability of success. Please let us know how it goes

thank you
Well actually, I have already tested the strategy of using both indicators. My success went from 44% when using just the TR indicator to 53% when using both the TR and TMO indicator. Then my RR went from 1:1.9 when using just the TR indicator to 1:2.2 when using both the TR and TMO indicator. The one I'll be back testing now is a more conservative approach that'll most likely improve my success rate to 74%, but decrease my RR. So I'll let you know how that goes tomorrow.
 
Last edited:
@Gabrielx77 or @BenTen is there a comparable built in study that would work like the zigzag or HiLow that i can use to build the conditional order testing. I am working to get close to the above script. The EMA or SMA, TMO are easy but the others are a challenge

Thank you and i will keep working to build it so i can share too
 
@tenacity11 as in the TMO Changs direction on the first candle and then the TR arrow appears? Because on the second strategy I back tested, the one with a 53% success rate, I used both as a signal to enter a trade. When they show a reversal at the same time or when they came right after the other.
 
@tenacity11 as in the TMO Changs direction on the first candle and then the TR arrow appears? Because on the second strategy I back tested, the one with a 53% success rate, I used both as a signal to enter a trade. When they show a reversal at the same time or when they came right after the other.
Actually yes to the second strategy as you did it. I think the difference is that I also use the swing high and low(colored candles) so in essence I look for the cyan swing low candle, then look for the TR candle in conjunction with the TMO. I added your TR indicator to see how it showed and I will post a chart showing what I mean. as a side note and fun for me is there is a pattern called a bullish butterfly that I know from my fib pattern trading days that appeared along with all the other things. Just fun for me to see.
 
To clean it up, I removed all of the code regarding the moving averages as it had no purpose to me. I think previously that part of the code was used to change the candle color.
 
Oh wow, yes mine looks like it lags behind. If you don't mind, would it be possible to share the links to your TR, TMO and Swing HiLow indicators? I'd love to be able to back test them like I did with my original TR indicator. Yours seems to be more reliable.

Also, I see multiple arrows and I don't seem to understand which is which. Is this correct?:

1. Swing HiLow: Candles change color (cyan for swing low, magenta for swing high)
2. TMO: Lower Level indicator
3. Your TR: Arrows (purple for swing low, red for swing high)
4. My TR: Arrows (green for swing low, red for swing high)

Then I see two arrows, one yellow one purple, but they are bigger than the rest. Which ones are these for?
 
Last edited:
Oh wow, yes mine looks like it lags behind. If you don't mind, would it be possible to share the links to your TR, TMO and Swing HiLow indicators? I'd love to be able to back test them like I did with my original TR indicator. Yours seems to be more reliable.

Also, I see multiple arrows and I don't seem to understand which is which. Is this correct?:

1. Swing HiLow: Candles change color (cyan for swing low, magenta for swing high)
2. TMO: Lower Level indicator
3. Your TR: Arrows (purple for swing low, red for swing high)
4. My TR: Arrows (green for swing low, red for swing high)

Then I see two arrows, one yellow one purple, but they are bigger than the rest. Which ones are these for?
i agree gabriel. i hope he'll share the system with us.
 
@Gabrielx77 Here is a chart with the other arrows explained. I will post my codes for the others.

bJLu2ld.png


Code:
#Trend Reverse Indicator

def price = close;

def superfast_length = 9;

def fast_length = 14;

def slow_length = 21;

def displace = 0;



def mov_avg9 = ExpAverage(price[-displace], superfast_length);

def mov_avg14 = ExpAverage(price[-displace], fast_length);

def mov_avg21 = ExpAverage(price[-displace], slow_length);



#moving averages

def Superfast = mov_avg9;

def Fast = mov_avg14;

def Slow = mov_avg21;



def buy = mov_avg9 > mov_avg14 and mov_avg14 > mov_avg21 and low > mov_avg9;

def stopbuy = mov_avg9 <= mov_avg14;

def buynow = !buy[1] and buy;

def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);



def Buy_Signal = buysignal[1] == 0 and buysignal == 1;



#Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);



def Momentum_Down = buysignal[1] == 1 and buysignal == 0;



#Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);



def sell = mov_avg9 < mov_avg14 and mov_avg14 < mov_avg21 and high < mov_avg9;

def stopsell = mov_avg9 >= mov_avg14;

def sellnow = !sell[1] and sell;

def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);



def Sell_Signal = sellsignal[1] == 0 and sellsignal;



#Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);



def Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;



#Alert(condition = sellsignal[1] == 1 and sellSignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);



plot Colorbars = if buysignal == 1 then 1 else if sellsignal == 1 then 2 else if buysignal == 0 or sellsignal == 0 then 3 else 0;

Colorbars.Hide();

Colorbars.DefineColor("Buy_Signal_Bars", Color.GREEN);

Colorbars.DefineColor("Sell_Signal_Bars", Color.RED);

Colorbars.DefineColor("Neutral", Color.PLUM);

#___________________________________________________________________________



input method = {default average, high_low};

def bubbleoffset = .0005;

def percentamount = .01;

def revAmount = .05;

def atrreversal = 2.0;

def atrlength = 5;

def pricehigh = high;

def pricelow = low;

def averagelength = 5;

def averagetype = AverageType.EXPONENTIAL;

def mah = MovingAverage(averagetype, pricehigh, averagelength);

def mal = MovingAverage(averagetype, pricelow, averagelength);

def priceh = if method == method.high_low then pricehigh else mah;

def pricel = if method == method.high_low then pricelow else mal;

def EI = ZigZagHighLow("price h" = priceh, "price l" = pricel, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);

def reversalAmount = if (close * percentamount / 100) > Max(revAmount < atrreversal * reference ATR(atrlength), revAmount) then (close * percentamount / 100) else if revAmount < atrreversal * reference ATR(atrlength) then atrreversal * reference ATR(atrlength) else revAmount;

rec EISave = if !IsNaN(EI) then EI else GetValue(EISave, 1);

def chg = (if EISave == priceh then priceh else pricel) - GetValue(EISave, 1);

def isUp = chg >= 0;

rec isConf = AbsValue(chg) >= reversalAmount or (IsNaN(GetValue(EI, 1)) and GetValue(isConf, 1));

def EId = if isUp then 1 else 0;



#Arrows

def EIL = if !IsNaN(EI) and !isUp then pricel else GetValue(EIL, 1);

def EIH = if !IsNaN(EI) and isUp then priceh else GetValue(EIH, 1);

def dir = CompoundValue(1, if EIL != EIL[1] or pricel == EIL[1] and pricel == EISave then 1 else if EIH != EIH[1] or priceh == EIH[1] and priceh == EISave then -1 else dir[1], 0);

def signal = CompoundValue(1, if dir > 0 and pricel > EIL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and priceh < EIH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

def showarrows = yes;

def U1 = showarrows and signal > 0 and signal[1] <= 0;

#U1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

#U1.SetDefaultColor(Color.GREEN);

#U1.SetLineWeight(4);

def D1 = showarrows and signal < 0 and signal[1] >= 0;

#D1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

#D1.SetDefaultColor(Color.RED);

#D1.SetLineWeight(4);

def barnumber = BarNumber()[10];



def bullish2 = signal > 0 and signal[1] <= 0;

plot upArrow = bullish2;

upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

upArrow.SetDefaultColor(CreateColor(145, 210, 144));



def bearish2 = signal < 0 and signal[1] >= 0;

plot downArrow = bearish2;

downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

downArrow.SetDefaultColor(CreateColor(255, 15, 10));



def revLineTop;

def revLineBot;



if barnumber and D1 {

revLineBot = Double.NaN;

revLineTop = high[1];

} else if barnumber and U1 {

revLineTop = Double.NaN;

revLineBot = low[1];

} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {

revLineBot = revLineBot[1];

revLineTop = Double.NaN;

} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {

revLineTop = revLineTop[1];

revLineBot = Double.NaN;

} else {

revLineTop = Double.NaN;

revLineBot = Double.NaN;

}



plot botLine = revLineBot[-1];

botLine.SetDefaultColor(Color.LIGHT_GREEN);

plot topLine = revLineTop[-1];

topLine.SetDefaultColor(Color.LIGHT_RED);



#Alerts



Alert(downArrow, " ", Alert.Bar, Sound.Chimes);

Alert(upArrow, " ", Alert.Bar, Sound.Bell);

TMO

Code:
declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
     Main.AssignValueColor(if Main > Signal
                           then color.green
                           else color.red);
     Signal.AssignValueColor(if Main > Signal
                             then color.green
                             else color.red);
     Signal.HideBubble();
     Signal.HideTitle();
plot zero = if isNaN(c) then double.nan else 0;
     zero.SetDefaultColor(Color.gray);
     zero.hideBubble();
     zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length * .7);
     ob.SetDefaultColor(Color.gray);
     ob.HideBubble();
     ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length * .7);
     os.SetDefaultColor(Color.gray);
     os.HideBubble();
     os.HideTitle();
# End Code TMO

NOTE that I have turned off the actual lines for swing high and low just leaving the candle colors*

Code:
# Swing High and Swing Low
# tomsk
# 11.18.2019

# As requested by chillc15 I have modified [USER=1174]@RobertPayne[/USER] code to include SwingHigh
# points which are now plotted in CYAN with the swing high points painted in PINK.
# So now you have both swing high and low on your charts

#  +------------------------------------------------------------+
#  |  Example: How to extend levels to the right of the chart   |
#  |                        Robert Payne                        |
#  |               https://funwiththinkscript.com               |
#  +------------------------------------------------------------+

# SWING LOW

# define swing low points
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);

# identify the very last swing low point
def lowPointOneBarNumber = HighestAll(if swingLow then bn else 0);
def lowPointOneValue = if bn == lowPointOneBarNumber then low else lowPointOneValue[1];
plot low1 = if bn < lowPointOneBarNumber then Double.NaN else lowPointOneValue;
low1.SetDefaultColor(Color.LIGHT_RED);

# identify the 2nd to last swing low point
def lowPointTwoBarNumber = HighestAll(if swingLow and bn < lowPointOneBarNumber then bn else 0);
def lowPointTwoValue = if bn == lowPointTwoBarNumber then low else lowPointTwoValue[1];
plot low2 = if bn < lowPointTwoBarNumber then Double.NaN else lowPointTwoValue;
low2.SetDefaultColor(Color.Light_RED);

# just keep doing ths for as many lines as you want to add to the chart
# identify then 3rd to last swingHigh point low
def lowPointThreeBarNumber = HighestAll(if swingLow and bn < lowPointTwoBarNumber then bn else 0);
def lowPointThreeValue = if bn == lowPointThreeBarNumber then low else lowPointThreeValue[1];
plot low3 = if bn < lowPointThreeBarNumber then Double.NaN else lowPointThreeValue;
low3.SetDefaultColor(Color.Light_RED);

# identify then 4th to last swingHigh point low
def lowPointFourBarNumber = HighestAll(if swingLow and bn < lowPointThreeBarNumber then bn else 0);
def lowPointFourValue = if bn == lowPointFourBarNumber then low else lowPointFourValue[1];
plot low4 = if bn < lowPointFourBarNumber then Double.NaN else lowPointFourValue;
low4.SetDefaultColor(Color.Light_RED);

# identify then 5th to last swingHigh point low
def lowPointFiveBarNumber = HighestAll(if swingLow and bn < lowPointFourBarNumber then bn else 0);
def lowPointFiveValue = if bn == lowPointFiveBarNumber then low else lowPointFiveValue[1];
plot low5 = if bn < lowPointFiveBarNumber then Double.NaN else lowPointFiveValue;
low5.SetDefaultColor(Color.Light_RED);

# identify then 6th to last swingHigh point low
def lowPointSixBarNumber = HighestAll(if swingLow and bn < lowPointFiveBarNumber then bn else 0);
def lowPointSixValue = if bn == lowPointSixBarNumber then low else lowPointSixValue[1];
plot low6 = if bn < lowPointSixBarNumber then Double.NaN else lowPointSixValue;
low6.SetDefaultColor(Color.Light_RED);

# identify then 7th to last swingHigh point low
def lowPointSevenBarNumber = HighestAll(if swingLow and bn < lowPointSixBarNumber then bn else 0);
def lowPointSevenValue = if bn == lowPointSevenBarNumber then low else lowPointSevenValue[1];
plot low7 = if bn < lowPointSevenBarNumber then Double.NaN else lowPointSevenValue;
low7.SetDefaultColor(Color.Light_RED);

# identify then 8th to last swingHigh point low
def lowPointEightBarNumber = HighestAll(if swingLow and bn < lowPointSevenBarNumber then bn else 0);
def lowPointEightValue = if bn == lowPointEightBarNumber then low else lowPointEightValue[1];
plot low8 = if bn < lowPointEightBarNumber then Double.NaN else lowPointEightValue;
low8.SetDefaultColor(Color.Light_RED);

# identify then 9th to last swingHigh point low
def lowPointNineBarNumber = HighestAll(if swingLow and bn < lowPointEightBarNumber then bn else 0);
def lowPointNineValue = if bn == lowPointNineBarNumber then low else lowPointNineValue[1];
plot low9 = if bn < lowPointNineBarNumber then Double.NaN else lowPointNineValue;
low9.SetDefaultColor(Color.Light_RED);

# identify then 10th to last swingHigh point low
def lowPointTenBarNumber = HighestAll(if swingLow and bn < lowPointNineBarNumber then bn else 0);
def lowPointTenValue = if bn == lowPointTenBarNumber then low else lowPointTenValue[1];
plot low10 = if bn < lowPointTenBarNumber then Double.NaN else lowPointTenValue;
low10.SetDefaultColor(Color.Light_RED);





# SWING HIGH

# define swing high points
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);

# identify the very last swing high point
def highPointOneBarNumber = HighestAll(if swingHigh then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];
plot high1 = if bn <  highPointOneBarNumber then Double.NaN else highPointOneValue;
high1.SetDefaultColor(Color.CYAN);

# identify the 2nd to last swing high point
def highPointTwoBarNumber = HighestAll(if swingHigh and bn < highPointOneBarNumber then bn else 0);
def highPointTwoValue = if bn == highPointTwoBarNumber then high else highPointTwoValue[1];
plot high2 = if bn < highPointTwoBarNumber then Double.NaN else highPointTwoValue;
high2.SetDefaultColor(Color.CYAN);

# just keep doing ths for as many lines as you want to add to the chart

def highPointThreeBarNumber = HighestAll(if swingHigh and bn < highPointTwoBarNumber then bn else 0);
def highPointThreeValue = if bn == highPointThreeBarNumber then high else highPointThreeValue[1];
plot high3 = if bn < highPointThreeBarNumber then Double.NaN else highPointThreeValue;
high3.SetDefaultColor(Color.CYAN);

def highPointFourBarNumber = HighestAll(if swingHigh and bn < highPointThreeBarNumber then bn else 0);
def highPointFourValue = if bn == highPointFourBarNumber then high else highPointFourValue[1];
plot high4 = if bn < highPointFourBarNumber then Double.NaN else highPointFourValue;
high4.SetDefaultColor(Color.CYAN);

def highPointFiveBarNumber = HighestAll(if swingHigh and bn < highPointFourBarNumber then bn else 0);
def highPointFiveValue = if bn == highPointFiveBarNumber then high else highPointFiveValue[1];
plot high5 = if bn < highPointFiveBarNumber then Double.NaN else highPointFiveValue;
high5.SetDefaultColor(Color.CYAN);

def highPointSixBarNumber = HighestAll(if swingHigh and bn < highPointFiveBarNumber then bn else 0);
def highPointSixValue = if bn == highPointSixBarNumber then high else highPointSixValue[1];
plot high6 = if bn < highPointsixBarNumber then Double.NaN else highPointsixValue;
high6.SetDefaultColor(Color.CYAN);

def highPointSevenBarNumber = HighestAll(if swingHigh and bn < highPointSixBarNumber then bn else 0);
def highPointSevenValue = if bn == highPointSevenBarNumber then high else highPointSevenValue[1];
plot high7 = if bn < highPointSevenBarNumber then Double.NaN else highPointSevenValue;
high7.SetDefaultColor(Color.CYAN);

def highPointEightBarNumber = HighestAll(if swingHigh and bn < highPointSevenBarNumber then bn else 0);
def highPointEightValue = if bn == highPointEightBarNumber then high else highPointEightValue[1];
plot high8 = if bn < highPointEightBarNumber then Double.NaN else highPointEightValue;
high4.SetDefaultColor(Color.CYAN);

def highPointNineBarNumber = HighestAll(if swingHigh and bn < highPointEightBarNumber then bn else 0);
def highPointNineValue = if bn == highPointNineBarNumber then high else highPointNineValue[1];
plot high9 = if bn < highPointNineBarNumber then Double.NaN else highPointNineValue;
high4.SetDefaultColor(Color.CYAN);

def highPointTenBarNumber = HighestAll(if swingHigh and bn < highPointNineBarNumber then bn else 0);
def highPointTenValue = if bn == highPointTenBarNumber then high else highPointTenValue[1];
plot high10 = if bn < highPointTenBarNumber then Double.NaN else highPointTenValue;
high4.SetDefaultColor(Color.CYAN);



# ADJUST CANDLE COLORS

# change candle colors just to make it easier to see what we are working with

AssignPriceColor(if swingLow then Color.cyan else if swingHigh then Color.mageNTA else Color.current);
# End Swing High and Swing Low
 
Last edited by a moderator:
Thanks your the best @tenacity11. I'm going to try and create a test where I will long when the swing high candle appears, followed by a trend reversal arrow combined with the TMO reversal; I'll short when the swing low candle appears, followed by a trend reversal arrow combined with the TMO reversal. I'll let you know how it goes.
 
Thanks your the best @tenacity11. I'm going to try and create a test where I will long when the swing high candle appears, followed by a trend reversal arrow combined with the TMO reversal; I'll short when the swing low candle appears, followed by a trend reversal arrow combined with the TMO reversal. I'll let you know how it goes.
Sounds good..Look forward to the results
 
Status
Not open for further replies.

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
274 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