Repaints Enhanced Trend Reversal Indicator for ThinkorSwim

Repaints
@KennyN You did nothing wrong. It's because this is a re-painting/delaying indicator, the alerts may not be able to work properly.
 

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

I had a quick question about this indicator. I understand it repaints, but after how many bars will the paint actually "dry"? What i mean to say is say a signal prints, do i need to wait for the close of that bar to see if it actually sticks? Close of the next bar? Close of the subsequent 10 bars? etc. Any help here would be appreciated.
 
@tinytrades The signals are delayed between 2-3 bars. However, the bigger problem is the constant repainting. If the stock decides to move in the opposite direction, the signal will disappear. The best way to understand how the repainting work is to watch it live during market hours :)
 
I have been following these threads for a while and experimenting with the Trend Reversal Indicator. I have modified the code to specifically try and fine tune the settings for just the ZigZag part. This ZigZag system alone has 6 separate parameters that can be fiddled with to fine tune the system.
Two of the parameters refer to the 2 Ema's that the system uses to define ZigZag Highs and Lows, (The yellow 5 Ema's on the image below). The other 4 parameters are for fine tuning the ZigZag indicator itself. I found it helpful to understand this indicator. Here is the link for the TOS description: ZigZag Indicator

All 6 parameters I have defined as "inputs" in the code below the image, so you can fiddle with the settings after you understand the implications of doing so by studying what the ZigZag does, if you are interested. I found when I added the indicator to the system I use to day trade it added additional information that was useful, and YES, it does repaint. However, I found that almost all the "fake out" signals (about 4 occurred in the time frame covered by the image) were rather easily identified as potential fakes based on the LOCATION OF THE SIGNALS relative to the major Support/Resistance Levels in my system along with Price/Volume action. So it is correct, YOU COULD NOT depend on these signals alone without the context of other indicators. With my preference for only on the chart indicators, I found the signals useful as possible additional SUPPORTIVE cues to assumptions I might have for price behavior at OR heading toward particular levels. This link from a previous forum post describes the system that I use to day trade and gives code for Support/Resistance Indicators I find most useful in day trading: Auto Grid Lines for Day Trading

For instance, once price reached a major downside Price Level of 45.50 between 8:15 and 8:30 PST, and then shot up with a Signal arrow, it was a no brainer to get in on any pull back. On the way up there were 2 "fake out" signals that could be seen as pull backs but not reversals, taking some profits, or scaling in more once the move up started again. HOW? , BECAUSE THE FIRST PULLBACK HAD NOT YET REACHED THE MAJOR PRICE TARGET LEVEL OF 46 AND THE SECOND PULLBACK HAD PASSED IT AND WAS SIMPLY TESTING THE 46 LEVEL IT ON ITS WAY TO TESTING THE VWAP LINE IN THICK WHITE.

Conclusion for me is I will leave this on the chart for some more experimentation. Code is below the image for the simplified version. Thanks to @BenTen for his work on this code. And all others who have contributed.

Regards,
Bob
61SiY0K.jpg


Code:
# Enhanced Trend Reversal Indicator with Signals
# Added VWAP and Engulfing Candles
# Assembled by BenTen at useThinkScript.com
# Original developer: Bayside of Enhanced Investor
# Original version: https://usethinkscript.com/threads/trend-reversal-indicator-with-signals-for-thinkorswim.183/
# Version 1.0 (read changelog in forum)
#@RLohmeyer Paired down version of the ZigZag code with primary input parmaters identified

#Input Parameters
input averagelength = 5;
input averagetype = AverageType.EXPONENTIAL;
input percentamount = .01;
input revAmount = .02;
input atrlength = 4;
input atrreversal = 1.5;


# ZigZagHighLow Code
def mah = MovingAverage(averagetype, high, averagelength);
def mal = MovingAverage(averagetype, low, averagelength);
def ZZ = ZigZagHighLow("price h" = mah, "price l" = mal, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
rec ZZSave = if !IsNaN(ZZ) then ZZ else GetValue(ZZSave, 1);
def chg = (if ZZSave == mah then mah else mal) - GetValue(ZZSave, 1);
def isUp = chg >= 0;
def ZZL = if !IsNaN(ZZ) and !isUp then mal else GetValue(ZZL, 1);
def ZZH = if !IsNaN(ZZ) and isUp then mah else GetValue(ZZH, 1);
def dir = CompoundValue(1, if ZZL != ZZL[1] or mal == ZZL[1] and mal == ZZSave then 1 else if ZZH != ZZH[1] or mah == ZZH[1] and mah == ZZSave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and mal > ZZL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and mah < ZZH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

# Plot Signals
plot bull =signal > 0 and signal[1] <= 0;
bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull.SetDefaultColor(Color.CYAN);
bull.SetLineWeight(2);
plot bear = signal < 0 and signal[1] >= 0;
bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear.SetDefaultColor(Color.CYAN);
bear.SetLineWeight(2);
 
And PS: Look at the Signal to occur at the exact same price level (45.50) at around 9:30. Another winner.
 
@BenTen , I am trying to place this code in the Enhanced Trend post #83 or #87 of this thread,....I cannot figure out why I am not successful? or Anyone who can assist.....the "colorbars," were generating errors....

Code:
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.GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.RED);
 
Last edited by a moderator:
@Thomas I agree. And considering where it was, it was very clean.

I want to add to post 83 above with some more comments. See Images below. I have modified the code to allow anyone to plot the the EMA band used by the revised Trend Reversal Indicator. Additionally, you can plot dots on the EMA band to show you exactly where the ZigZag code bottom and tops are of the EMAs JUST PRIOR TO THE SIGNAL. This allows you to see where the code detects that the parameters have been satisfied to place a signal. In the image I mark a couple with a Red Arrow. The second image shows you the parameters I used for these signals. Now the white comments by the numbers are where False Signal Bars showed up prior to the actual Go Signals. Look at the image closely (if your interested), and then look at my comments below the image as to how easy or not so easy it would be to detect these potentially false signals based on the other chart indicators.

A4568eG.jpg

KYl0No6.jpg


False Signal Bar 1: These would have be easy to disregard, since it was evident the signal bar was a retrace to test the major Price Level at 46.50 and the VWAP (thick white line). And and in fact, after the reaction bar right after the signal bar, one could have shorted (or added to your short) for relatively high probability move down to what was anticipated to be a move to the 46 level.

False Signal Bar 2: Much iffier situation. I lightened up on my short position, still looking for a test of 46 level.

Go Signal: Did not take it but the presumption about a potential retest of 46 level was shaken. When price settled above the Green S/R Level, closed the remaining short position. So this whole area here was a chop zone that was still manageable.

False Signal Bar 3: I was out of a short at 45.50 and was not going to take this signal because a second test of this level was highly likely.

Go Signal: This was a no brainer after the big boys did a stop run and you had a clean signal.
The code for the revised indicator is below. I continue to experiment with this indicator, possibly adding a filter. Will report back.

Regards,
Bob

Code:
# Trend Reversal Indicator with Signals
# Added VWAP and Engulfing Candles
# Assembled by BenTen at useThinkScript.com
# Original developer: Bayside of Enhanced Investor
# Original version: https://usethinkscript.com/threads/trend-reversal-indicator-with-signals-for-thinkorswim.183/
# Version 1.0 (read changelog in forum)
# @rlohmeyer Paired down version of the ZigZag code with primary input parameters identified
#removed VWAP & Engulfing, plotting for EMA Band and ZigZag

#Input Parameters
input averagelength = 5;
input averagetype = AverageType.EXPONENTIAL;
input percentamount = .01;
input revAmount = .02;
input atrlength = 4;
input atrreversal = 1.5;


# ZigZagHighLow Band Code
def mah = MovingAverage(averagetype, high, averagelength);
def mal = MovingAverage(averagetype, low, averagelength);
def ZZ = ZigZagHighLow("price h" = mah, "price l" = mal, "percentage reversal" = percentamount, "absolute reversal" = revAmount, "atr length" = atrlength, "atr reversal" = atrreversal);
rec ZZSave = if !IsNaN(ZZ) then ZZ else GetValue(ZZSave, 1);
def chg = (if ZZSave == mah then mah else mal) - GetValue(ZZSave, 1);
def isUp = chg >= 0;
def ZZL = if !IsNaN(ZZ) and !isUp then mal else GetValue(ZZL, 1);
def ZZH = if !IsNaN(ZZ) and isUp then mah else GetValue(ZZH, 1);
def dir = CompoundValue(1, if ZZL != ZZL[1] or mal == ZZL[1] and mal == ZZSave then 1 else if ZZH != ZZH[1] or mah == ZZH[1] and mah == ZZSave then -1 else dir[1], 0);
def signal = CompoundValue(1, if dir > 0 and mal > ZZL then if signal[1] <= 0 then 1 else signal[1] else if dir < 0 and mah < ZZH then if signal[1] >= 0 then -1 else signal[1] else signal[1], 0);

#Plot Elements
Plot maa = Mah;
maa.SetPaintingStrategy(PaintingStrategy.line);
maa.SetDefaultColor(Color.yellow);
maa.SetLineWeight(1);
Plot mab = Mal;
mab.SetPaintingStrategy(PaintingStrategy.line);
mab.SetDefaultColor(Color.yellow);
mab.SetLineWeight(1);
Plot zzhl = ZZ;
zzhl.SetPaintingStrategy(PaintingStrategy.points);
zzhl.SetDefaultColor(Color.yellow);
zzhl.SetLineWeight(4);

# ZigZag Signals
plot bull =signal > 0 and signal[1] <= 0;
bull.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bull.SetDefaultColor(Color.CYAN);
bull.SetLineWeight(2);
plot bear = signal < 0 and signal[1] >= 0;
bear.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bear.SetDefaultColor(Color.CYAN);
bear.SetLineWeight(2);
 
@Thomas Thanks so much for this code. You colored bar lowest low/highest high precedes the Yellow Dot Zig/Zag, which precedes the Trend Reversal Signal based on the Zig/Zag. Your code moves the observation point back 1 bar, and can give a one bar lead on a decision as long as other S/R and indicators line up. This can pad the potential Risk/Reward advantage. Very, very nice.

Since I use other S/R levels to qualify entries I will forego the lines, but the Bar Colors are now on my chart. I am going to experiment now on Mondays trade and see how this works.

Regards,
Bob
 
I have been using the bar colors for many months and find them very useful...I will be interested to see how the Dots fit in...
 
I have been using the bar colors for many months and find them very useful...I will be interested to see how the Dots fit in...
Put the dots on a chart and look where they fire, then the Hi_Low mark, place an alert above the body of High_Low, either enter there or find the yellow dot for entry, stop on body low/high.....you have to read price, so necessary to understand candles.....
 
Put the dots on a chart and look where they fire, then the Hi_Low mark, place an alert above the body of High_Low, either enter there or find the yellow dot for entry, stop on body low/high.....you have to read price, so necessary to understand candles
I'll be using this on a tick chart and I have the dots marked and I primarily look at price action...thanks
 
@Thomas @tenacity11

I used the Swing Hi/Lo indicator on this mornings trade. I only trade 1.5 to 2 hours AM only. It was clearly useful, as I explain in post 9 HERE. I show todays trade with comments.

Again, thanks. And @Thomas I saw your post in the forum on the Savage Oscillator, which I was looking at. You mentioned you generally utilize real time price/volume as I do. I would be interested in any further comments you have or have posted about as to your trade style and what you depend on most. I clearly outlined my own in the Auto Significant Price Levels post I made, at the link above.

Regards,
Bob
 
@toopoor88 If you are referring to the Trend Reversal Indicator, yes, totally aware as this thread has mentioned repeatedly. I posted the modified code so that others could fiddle with the inputs for the ZigZag part of the code and removed the VWAP part and Engulfing Bar part (which were part of the originally posted code). I was looking for a way to use it WITH OTHER CONFIRMING INDICATORS, which is the only way it could be useful. However, I presently use the code from post 88 @Thomas (without Hi/Lo Lines drawn on the chart) to paint Swing Hi/Lo bars, which by the way, will also repaint. These types of indicators absolutely need confirmation. The image below shows the Swing Hi/Lo indicator and how it was used in this mornings trade AFTER there was a confirmation of a turn. Hope this helps.
w8Z5nhK.jpg
 
@toopoor88
PS; Below is the code for the above Swing Hi/Lo indicator, with an input that will allow you to fiddle with lookback periods, though I find either 10 or 15 works well for potential good swing trades, WITH CONFIRMATION. On the chart it was a lookback period of 10.

Code:
# Swing High and Swing Low
# tomsk
# 11.18.2019
# As requested by chillc15 I have modified @RobertPayne code to include SwingHigh points which are now plotted in CYAN with the SwingLow points painted in Magenta.
# So now you have both swing high and low on your charts
#Code modified by @rlohmeyer

#Primary Definitions
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);

# SWING POINTS
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);

#Identify the very last swing low point and 10 previous
def lowPointOneBarNumber = HighestAll(if swingLow then bn else 0);
def lowPointOneValue = if bn == lowPointOneBarNumber then low else lowPointOneValue[1];

def lowPointTwoBarNumber = HighestAll(if swingLow and bn < lowPointOneBarNumber then bn else 0);
def lowPointTwoValue = if bn == lowPointTwoBarNumber then low else lowPointTwoValue[1];

def lowPointThreeBarNumber = HighestAll(if swingLow and bn < lowPointTwoBarNumber then bn else 0);
def lowPointThreeValue = if bn == lowPointThreeBarNumber then low else lowPointThreeValue[1];

def lowPointFourBarNumber = HighestAll(if swingLow and bn < lowPointThreeBarNumber then bn else 0);
def lowPointFourValue = if bn == lowPointFourBarNumber then low else lowPointFourValue[1];

def lowPointFiveBarNumber = HighestAll(if swingLow and bn < lowPointFourBarNumber then bn else 0);
def lowPointFiveValue = if bn == lowPointFiveBarNumber then low else lowPointFiveValue[1];

def lowPointSixBarNumber = HighestAll(if swingLow and bn < lowPointFiveBarNumber then bn else 0);
def lowPointSixValue = if bn == lowPointSixBarNumber then low else lowPointSixValue[1];

def lowPointSevenBarNumber = HighestAll(if swingLow and bn < lowPointSixBarNumber then bn else 0);
def lowPointSevenValue = if bn == lowPointSevenBarNumber then low else lowPointSevenValue[1];

def lowPointEightBarNumber = HighestAll(if swingLow and bn < lowPointSevenBarNumber then bn else 0);
def lowPointEightValue = if bn == lowPointEightBarNumber then low else lowPointEightValue[1];

def lowPointNineBarNumber = HighestAll(if swingLow and bn < lowPointEightBarNumber then bn else 0);
def lowPointNineValue = if bn == lowPointNineBarNumber then low else lowPointNineValue[1];

def lowPointTenBarNumber = HighestAll(if swingLow and bn < lowPointNineBarNumber then bn else 0);
def lowPointTenValue = if bn == lowPointTenBarNumber then low else lowPointTenValue[1];

# Identify the very last swing high point and 10 others
def highPointOneBarNumber = HighestAll(if swingHigh then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];

def highPointTwoBarNumber = HighestAll(if swingHigh and bn < highPointOneBarNumber then bn else 0);
def highPointTwoValue = if bn == highPointTwoBarNumber then high else highPointTwoValue[1];

def highPointThreeBarNumber = HighestAll(if swingHigh and bn < highPointTwoBarNumber then bn else 0);
def highPointThreeValue = if bn == highPointThreeBarNumber then high else highPointThreeValue[1];

def highPointFourBarNumber = HighestAll(if swingHigh and bn < highPointThreeBarNumber then bn else 0);
def highPointFourValue = if bn == highPointFourBarNumber then high else highPointFourValue[1];

def highPointFiveBarNumber = HighestAll(if swingHigh and bn < highPointFourBarNumber then bn else 0);
def highPointFiveValue = if bn == highPointFiveBarNumber then high else highPointFiveValue[1];

def highPointSixBarNumber = HighestAll(if swingHigh and bn < highPointFiveBarNumber then bn else 0);
def highPointSixValue = if bn == highPointSixBarNumber then high else highPointSixValue[1];

def highPointSevenBarNumber = HighestAll(if swingHigh and bn < highPointSixBarNumber then bn else 0);
def highPointSevenValue = if bn == highPointSevenBarNumber then high else highPointSevenValue[1];
#
def highPointEightBarNumber = HighestAll(if swingHigh and bn < highPointSevenBarNumber then bn else 0);
def highPointEightValue = if bn == highPointEightBarNumber then high else highPointEightValue[1];

def highPointNineBarNumber = HighestAll(if swingHigh and bn < highPointEightBarNumber then bn else 0);
def highPointNineValue = if bn == highPointNineBarNumber then high else highPointNineValue[1];

def highPointTenBarNumber = HighestAll(if swingHigh and bn < highPointNineBarNumber then bn else 0);
def highPointTenValue = if bn == highPointTenBarNumber then high else highPointTenValue[1];

# ADJUST CANDLE COLORS
AssignPriceColor(if swingLow then Color.CYAN else if swingHigh then Color.CYAN else Color.current);
 
I am still experimenting with finding additional "on the chart" indicators besides the ones I generally use daily posted about HERE in Auto Significant Price Levels. In post 97 and 98 I posted info on the Swing Hi/Lo Indicator that I have used on my chart, which as I have said also repaints, and thus needs additional confirmation in order to trade it.

I have added new code to the previous Zig/Zag Reversal Indicator I posted about in 89. The new code substitutes the moving averages used in Zig/Zag Reversal Indicator with another type of average. The image of the result is below in todays trade. The new indicator paints cyan dots in particular locations based on the Zig/Zag Reversal Indicator calculation on this new average. I will trade with this on the chart for a day or so to see if this code is worth posting. I am hoping it can provide additional confirmation for a Swing Hi/Lo Bar in order to trade it. It looks promising after the close. We will see.

The Average Length for the calculation of Swing Hi/Lo is 15 on this 1 minute chart.

Regards,,
Bob

MTDezkB.jpg
 
Hey guys! Thanks for this script. I think it's awesome. I was trying to figure out how to add a label that would popup when the reversal is fired. It would be good to be able to look as many as 3 bars back. So the label might say Buy, Buy-1, Buy-2 for example. I've done this with some other code, but I can't seem to figure this one out.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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