Repaints Trend Reversal for ThinkorSwim

Repaints
Status
Not open for further replies.
This is for the scanner or the chart ? I was looking for it for the chart please let me know


That's for the chart, I mentioned earlier it was for a chart but maybe I was not clear. Just load that study on say AAPL daily aggregation and you'll see 2 nice signals there - one bullish and one bearish
 

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

That's for the chart, I mentioned earlier it was for a chart but maybe I was not clear. Just load that study on say AAPL daily aggregation and you'll see 2 nice signals there - one bullish and one bearish
Your right sorry about that thanks
 
Question for the community ...can this script be utilized as a watchlist column with red and green fields indicating a signal within "x" number of bars? Thanks
 
@Trading51 Personally I think most folks would like to see the arrows signal as it's more intuitive. However since you like to use bubbles, I have added a user input selector displayBubblesOnly that when set to "yes" will display Bubbles and the arrows will not be displayed. This way, this offers flexibility for readers who'd like to have an easy choice. Here then is version 1.2 of the code

Code:
# Trend Reversal
# Dixon72 with modifications by tomsk
# 1.18.2020
# Scanner by https://usethinkscript.com/u/theelderwand

# V1.0 - 11.09.2019 - Dixon72 - Initial release of Trend Reversal Scanner
# V1.1 - 01.18.2020 - tomsk   - Modified to only display last bullish/bearish signal
# V1.2 - 01.18.2020 - tomsk   - Added user input selector displayBubblesOnly to display bubbles rather than arrows

input displayBubblesOnly = no;

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;
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);

def bullish2 = if signal > 0 and signal[1] <= 0 then barNumber() else 0;
plot upArrow = if !displayBubblesOnly and barNumber() == HighestAll(bullish2) then low * 0.994 else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetLineWeight(5);
upArrow.SetDefaultColor(Color.CYAN);

def bearish2 = if signal < 0 and signal[1] >= 0 then barNumber() else 0;
plot downArrow = if !displayBubblesOnly and barNumber() == HighestAll(bearish2) then high * 1.004 else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downArrow.SetLineWeight(5);
downArrow.SetDefaultColor(Color.YELLOW);

AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bullish2), low * 0.994, "Bullish\nSignal", Color.Cyan, no);
AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bearish2), high * 1.006, "Bearish\nSignal", Color.Yellow, yes);
# End Trend Reversal
 
@tomsk Is it possible to have the bubble with the stop right below the signal like the original code, this is very hard to understand where the buy and sell is, the original code had the area for the stop which was beneficial

cr93OXI.png
 
Chart Bubbles can certainly be placed anywhere on the chart and are referenced via an X, Y coordinates (axis) where X is the barNumber() or horizontal location and Y is the price location. Earlier you requested the arrows to be replaced by bubbles and that is precisely what I posted in post # 446. Like I mentioned earlier, most folks prefer an arrow signal but you are free to use whatever mechanism you prefer. Not sure how else I can assist further though
 
Last edited:
@BenTen Thanks for all you do. I'm very new here. I stumbled across this site last night while having some rum and researching scans, indicators and Thinkorswim. I can tell this will turn in to my favorite forum. Thank you for all you and the others here do. It took me a while, but I read nearly the entire thread on this custom study and using it as a scan. I'm still trying to figure out how to turn it into a live feed, real-time watchlist but I think it's just too complex to scan the entire market. … again Ben, thank you. It's pretty selfless what you guys do here. I'm amazed to find it on the internet for free.
 
Chart Bubbles can certainly be placed anywhere on the chart and are referenced via an X, Y coordinates (axis) where X is the barNumber() or horizontal location and Y is the price location. Earlier you requested the arrows to be replaced by bubbles and that is precisely what I posted in post # 446. Like I mentioned earlier, most folks prefer an arrow signal but you are free to use whatever mechanism you prefer. Not sure how else I can assist further though
@tomsk To help me out could you post the piece of code that I could just add to my current buy and sell signal code that would show just the last buy and sell, thanks
 
@Trading51 - Adjusted bull/bear bubbles to be placed at value of reversal bar. Added Stop Loss bubble and extended line

Code:
# Trend Reversal
# Dixon72 with modifications by tomsk
# 1.18.2020
# Scanner by https://usethinkscript.com/u/theelderwand

# V1.0 - 11.09.2019 - Dixon72 - Initial release of Trend Reversal Scanner
# V1.1 - 01.18.2020 - tomsk   - Modified to only display last bullish/bearish signal
# V1.2 - 01.18.2020 - tomsk   - Added user input selector displayBubblesOnly to display bubbles rather than arrows
# V1.3 - 01.19.2020 - BLT     - Modified bubble placement, added Stop Loss bubble and extended line

input displayBubblesOnly = yes;

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;
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);

def bullish2 = if signal > 0 and signal[1] <= 0 then barNumber() else 0;
plot upArrow = if !displayBubblesOnly and barNumber() == HighestAll(bullish2) then low * 0.994 else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetLineWeight(5);
upArrow.SetDefaultColor(Color.CYAN);

def bearish2 = if signal < 0 and signal[1] >= 0 then barNumber() else 0;
plot downArrow = if !displayBubblesOnly and barNumber() == HighestAll(bearish2) then high * 1.004 else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downArrow.SetLineWeight(5);
downArrow.SetDefaultColor(Color.YELLOW);

AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bullish2), low, "Bull " + astext(low), Color.Cyan, no);
AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bearish2), high, "Bear " + astext(high), Color.Yellow, yes);
def bullstop= if barNumber() == HighestAll(bullish2) then low[1] else if barnumber() < HighestAll(bullish2) then double.nan else bullstop[1];
plot bullstopplot = bullstop;
bullstopplot.setdefaultColor(color.red);
AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bullish2), low[1], "Stop " + astext(low[1]), Color.red, no);
def bearstop= if barNumber() == HighestAll(bearish2) then high[1] else if barnumber() < HighestAll(bearish2) then double.nan else bearstop[1];
plot bearstopplot = bearstop;
bearstopplot.setdefaultColor(color.red);
AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bearish2), high[1], "Stop " + astext(high[1]), Color.red, yes);
# End Trend Reversal
 
Chart Bubbles can certainly be placed anywhere on the chart and are referenced via an X, Y coordinates (axis) where X is the barNumber() or horizontal location and Y is the price location. Earlier you requested the arrows to be replaced by bubbles and that is precisely what I posted in post # 446. Like I mentioned earlier, most folks prefer an arrow signal but you are free to use whatever mechanism you prefer. Not sure how else I can assist further though
@tomsk, After loaded this indicator, its shows only one time Bear or Bull signal per chart, Is it is possible view the all Trend reversal Bubble a day.
 
Is there any way to modify this indicator to show little arrows or something that isn't so obtrusive?

@spm009 Sure thing, all you do is to change the weightage on the arrows via SetLineWeight. 1 is the min value and 5 is the max value. The following has a weightage of 3 and so should be less "obtrusive" so to speak

Code:
upArrow.SetLineWeight(3);
 
@Trading51 Personally I think most folks would like to see the arrows signal as it's more intuitive. However since you like to use bubbles, I have added a user input selector displayBubblesOnly that when set to "yes" will display Bubbles and the arrows will not be displayed. This way, this offers flexibility for readers who'd like to have an easy choice. Here then is version 1.2 of the code

Code:
# Trend Reversal
# Dixon72 with modifications by tomsk
# 1.18.2020
# Scanner by https://usethinkscript.com/u/theelderwand

# V1.0 - 11.09.2019 - Dixon72 - Initial release of Trend Reversal Scanner
# V1.1 - 01.18.2020 - tomsk   - Modified to only display last bullish/bearish signal
# V1.2 - 01.18.2020 - tomsk   - Added user input selector displayBubblesOnly to display bubbles rather than arrows

input displayBubblesOnly = no;

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;
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);

def bullish2 = if signal > 0 and signal[1] <= 0 then barNumber() else 0;
plot upArrow = if !displayBubblesOnly and barNumber() == HighestAll(bullish2) then low * 0.994 else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetLineWeight(5);
upArrow.SetDefaultColor(Color.CYAN);

def bearish2 = if signal < 0 and signal[1] >= 0 then barNumber() else 0;
plot downArrow = if !displayBubblesOnly and barNumber() == HighestAll(bearish2) then high * 1.004 else Double.NaN;
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
downArrow.SetLineWeight(5);
downArrow.SetDefaultColor(Color.YELLOW);

AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bullish2), low * 0.994, "Bullish\nSignal", Color.Cyan, no);
AddChartBubble(displayBubblesOnly and barNumber() == HighestAll(bearish2), high * 1.006, "Bearish\nSignal", Color.Yellow, yes);
# End Trend Reversal
Thanks for the update that what i was looking for much appreciated
 
@spm009 Sure thing, all you do is to change the weightage on the arrows via SetLineWeight. 1 is the min value and 5 is the max value. The following has a weightage of 3 and so should be less "obtrusive" so to speak

Code:
upArrow.SetLineWeight(3);
Thanks!

I played around with the different versions of the script in this thread, my favorite is actually the original one but the bubbles are extremely annoying. They really get in the way of the chart, especially on zoomed out time frames.
 
Status
Not open for further replies.

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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