@amangaloreab We no longer distribute that code because of its repainting factor caused by the trend reversal indicator.
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Can you explain what repainting is?@GetRichOrDieTrying Yes, it will also repaint just like the original indicator. Stop loss would be the high of the previous candle.
Can you explain what repainting is?
Is there a way to replace the zzhl yellow dots with up and down arrows?@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.
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);
@MerryDay Oh I see. Thank you. I just assumed they had direction since there is always a directional signal arrow that plots the day after the dot plots. I thought they were essentially the same except the dots plotted a day earlier. That's why I was wondering why anyone would use the signal arrows when the dots get you in a day earlier. I guess the dots just tell a directional change is coming, but not which direction it will be.@David45 The dots don't have direction... How are you defining up vs down
@rlohmeyer thank you for all your posts and codes on this topic. Am wondering if you have discovered a way to store a signal and paint it on top of the indicators re-paintable arrow and if/when indeed repainted the stored signal marker remains? To some degree that is what the Swing High Low you and thomas have been posting and i find using the swing high low at 10 against the trend indicator set at 5 to be interesting@David45 @MerryDay
The dots plots a directional change in either the low or the high zigzag plot, which is a day before the arrow signal. The issue is, as everyone has reported, that the signals repaint. That is what I was pointing out by showing on the graphic where you would have received false signals, or rather signals with no real follow through. I would use this only with other non-similar confirming indicators, as others have pointed out.
Regards,
Bob
fair enough and thank you for such prompt feedback. my only rationale was in thinking of measuring its reliability despite the repainting. BTW i absolutely love how you broke down the code to its functioning parts. Was trying to do as well until i found yours. thank you@JLEE
Hi,
I am a trader who codes to use the code. None of the above ideas would be valuable in my style of trading, so I would not spend the time to code them. I was hoping to use this version of the Enhanced Trend Reversal Indicator to enhance my style of trading, which is day trading the 1 minute or 5 minute based on price action and Price and Volume related S/R. I have talked about this in the thread I initiated here.
Regards,
Bob
I'm a believer now!!@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.
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);
Can you post the scanner for this setup?Here is the Enhanced version of the popular Trend Reversal indicator available here for ThinkorSwim.
Before we jump into what's new, I just want to clarify that the new version will continue to repaint. Repainting was the problem with the original Trend Reversal. Though there is no way to fix that issue, we continue to find ways to improve it.
One way to increase the reliability of the signals is to implement additional trend reversal patterns. Included in the Enhanced version are:
- Bullish and Bearish Engulfing candles
- VWAP
- Advanced Market Moves (will not be included in the public release due to obvious reason)
Here’s How it Works:
From now on, the Trend Reversal Signals will only appear on your chart if it fits the following requirement:
The reversal candle (pulled from the original version) must either be an Engulfing candle, below/above VWAP, or matches with the signal given by the Advanced Market Moves.
We assume that if any of the three conditions match up in a single candle, most likely there would be a point of reversal in trend. Of course, since this indicator repaint, it’s impossible to backtest. Hopefully, this Enhanced version will work better since additional conditions have been added.
thinkScript Code
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) 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); # MAs part of Trend Reversal 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; def Momentum_Down = buysignal[1] == 1 and buysignal == 0; 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; 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); 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; 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); # Define original signals def bullish2 = signal > 0 and signal[1] <= 0; def bearish2 = signal < 0 and signal[1] >= 0; # VWAP input numDevDn = -2.0; input numDevUp = 2.0; input timeFrame = {default DAY, WEEK, MONTH}; def cap = GetAggregationPeriod(); def errorInAggregation = timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH; Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period"); def yyyyMmDd = GetYYYYMMDD(); def periodIndx; switch (timeFrame) { case DAY: periodIndx = yyyyMmDd; case WEEK: periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7); case MONTH: periodIndx = RoundDown(yyyyMmDd / 100, 0); } def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes); def volumeSum; def volumeVwapSum; def volumeVwap2Sum; if (isPeriodRolled) { volumeSum = volume; volumeVwapSum = volume * vwap; volumeVwap2Sum = volume * Sqr(vwap); } else { volumeSum = CompoundValue(1, volumeSum[1] + volume, volume); volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap); volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)); } def priceVWAP = volumeVwapSum / volumeSum; def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(priceVWAP), 0)); def VWAP = priceVWAP; #plot UpperBand = priceVWAP + numDevUp * deviation; #plot LowerBand = priceVWAP + numDevDn * deviation; def UpVWAP = price > VWAP; def DownVWAP = price < VWAP; # Engulfing Candles. Snippets from @ConfluenceCptl def BodyMax = Max(open, close); def BodyMin = Min(open, close); def IsEngulfing = BodyMax > BodyMax[1] and BodyMin < BodyMin[1]; # Define Signals with VWAP def bullish_vwap = UpVWAP and bullish2; def bearish_vwap = DownVWAP and bearish2; # Plot Signals with VWAP plot bull_vwap = bullish_vwap; bull_vwap.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); bull_vwap.SetDefaultColor(Color.CYAN); bull_vwap.SetLineWeight(2); plot bear_vwap = bearish_vwap; bear_vwap.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); bear_vwap.SetDefaultColor(Color.CYAN); bear_vwap.SetLineWeight(2); # Define Signals with Engulfing Candles def bullish_engulf = bullish2 and Isengulfing and close > open; def bearish_engulf = bearish2 and Isengulfing and close < open; # Plot Signals with Engulfing Candles plot bull_engulf = bullish_engulf; bull_engulf.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP); bull_engulf.SetDefaultColor(Color.WHITE); bull_engulf.SetLineWeight(2); plot bear_engulf = bearish_engulf; bear_engulf.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); bear_engulf.SetDefaultColor(Color.WHITE); bear_engulf.SetLineWeight(2); AddLabel(yes,"Signals w/ VWAP",color.CYAN); AddLabel(yes,"Signals w/ Engulfing",color.WHITE); # Configurations input bEngulf = yes; input sEngulf = yes; input bVWAP = yes; input sVWAP = yes; bull_engulf.SetHiding(!bEngulf); bear_engulf.SetHiding(!sEngulf); bull_vwap.SetHiding(!bVWAP); bear_vwap.SetHiding(!sVWAP);
Shareable Link: https://tos.mx/1we0QW
Configurations
There will be a lot of signals on your chart, however, I have color-coded them. You can also disable any type of arrows right from the indicator’s settings page. You don’t have to edit anything in the source code.
Changelog
Feel free to test it out and let me know. I heard a lot of positive feedback from members using the original version.
Video Tutorial
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Repaints Super Trend MTF Enhanced For ThinkOrSwim | Indicators | 33 | ||
Enhanced VWAP Indicator for ThinkorSwim | Indicators | 12 | ||
Standard Deviation Bands Enhanced for ThinkorSwim | Indicators | 28 | ||
LNL Trend System for ThinkOrSwim | Indicators | 25 | ||
L3 Banker Fund Flow Trend Oscillator for ThinkOrSwim | Indicators | 32 |
Start a new thread and receive assistance from our community.
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.
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.