Repaints Trend Reversal for ThinkorSwim

Repaints
Status
Not open for further replies.

BenTen's Watchlist + Setup + Trade Recaps

Get access to Ben's watchlist, swing trading strategy, ThinkorSwim setup, and trade examples.

Learn more

@BenTen what does it mean when the trend reversal is purple, and is there a sound alert that can be set with this tool
Try this one out I think you will like it. It does have sound and is pretty accurate in many time frames. I have tried this out with /MES (market direction) SPXL (symbol for market long or up) QQQ ( tech) TQQQ (long tech) also some AAPL. (not stock advice) Best for a person not under the PDT rule but can also grow a small account. I hope this helps you. (I DID NOT MAKE THIS INDICATOR) I spend many days and nights searching this site for good strategies for someone that has a 6yo in online school LOL!

Code:
# Trend Reversal Scanner
# Scanner by [URL]https://usethinkscript.com/u/theelderwand[/URL]
# Discuss [URL]https://usethinkscript.com/d/183-trend-reversal-indicator-with-signals-for-thinkorswim[/URL]

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

#Alerts
input alerts = yes;
def bull = if signal > 0 and signal[1] <= 0 then 1 else 0;
def bear = if signal < 0 and signal[1] >= 0 then 1 else 0;
Alert(alerts and bullish2[1] == 1, "Up   ", Alert.BAR, Sound.Chimes);
Alert(alerts and bearish2[1] == 1, "Down ", Alert.BAR, Sound.Bell);
 
Try this one out I think you will like it. It does have sound and is pretty accurate in many time frames. I have tried this out with /MES (market direction) SPXL (symbol for market long or up) QQQ ( tech) TQQQ (long tech) also some AAPL. (not stock advice) Best for a person not under the PDT rule but can also grow a small account. I hope this helps you. (I DID NOT MAKE THIS INDICATOR) I spend many days and nights searching this site for good strategies for someone that has a 6yo in online school LOL!

# Trend Reversal Scanner
# Scanner by https://usethinkscript.com/u/theelderwand
# Discuss https://usethinkscript.com/d/183-trend-reversal-indicator-with-signals-for-thinkorswim

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

#Alerts
input alerts = yes;
def bull = if signal > 0 and signal[1] <= 0 then 1 else 0;
def bear = if signal < 0 and signal[1] >= 0 then 1 else 0;
Alert(alerts and bullish2[1] == 1, "Up ", Alert.BAR, Sound.Chimes);
Alert(alerts and bearish2[1] == 1, "Down ", Alert.BAR, Sound.Bell);

Thanks for your code. How do I add it to TOS's Stock Hacker in order to use it as a scanner?
 
Last edited:
@Picard to use the script in post# 1385 in the TOS scanner
Copy the code
In Studies, click Create
Paste the above study
Name the study: Trend_Reversal_Scanner
Save
Click on the scanner.
  1. Click on +Add filter
  2. Click on the pencil icon next to the filter you just added
  3. Click edit
  4. In the left column, click on the 1st pull-down window, click study
  5. Type in Trend_Reversal_Scanner
  6. Under Plot, click on the pull-down window, choose upArrow
  7. In the middle column, choose is true
  8. Save
I didn't write this script. Any questions should be referred to the original poster. HTH
 
@Picard to use the script in post# 1385 in the TOS scanner
Copy the code
In Studies, click Create
Paste the above study
Name the study: Trend_Reversal_Scanner
Save
Click on the scanner.
  1. Click on +Add filter
  2. Click on the pencil icon next to the filter you just added
  3. Click edit
  4. In the left column, click on the 1st pull-down window, click study
  5. Type in Trend_Reversal_Scanner
  6. Under Plot, click on the pull-down window, choose upArrow
  7. In the middle column, choose is true
  8. Save
I didn't write this script. Any questions should be referred to the original poster. HTH
Thanks MerryDay,

I got it to work.
 
Last edited:
Is there a way for the indicator alerts to send email notifications?

Also I tried using "Create Alert" from a chart and inserting the code, but now I'm back to the error "Exactly one plot expected". Apparently in the code plotting an arrow is not what TOS considers a plot that would correct this error. It must need some other plot. How can I correct this error?
 
Last edited:
@Picard For future reference, it is poor forum etiquette to continuing to ask the same question after it has been answered.
As already stated indicators cannot send email or text notifications.
You can have scans send text and email alerts but there are delays. For more information refer to this tutorial:
https://usethinkscript.com/threads/how-to-receive-thinkorswim-alert-notifications-via-phone.5430/
Sorry about that. I didn't see that post before. However, it's also common and frustrating that many who answer my questions only pick one of the questions in my post and ignore the rest of my post. Was there also an answer in this forum for the second part of my post that I may have missed?

Also I tried using "Create Alert" from a chart and inserting the code, but now I'm back to the error "Exactly one plot expected". Apparently in the code plotting an arrow is not what TOS considers a plot that would correct this error. It must need some other plot. How can I correct this error?
 
Sorry about that. I didn't see that post before. However, it's also common and frustrating that many who answer my questions only pick one of the questions in my post and ignore the rest of my post. Was there also an answer in this forum for the second part of my post that I may have missed?
I found a video on YouTube.

 
@MerryDay ...I copied the code from post #1385, followed your instructions then to create a scanner. I set the stock price to be only $1 - $20 (so as not to have to look at too many) and ran the scan. It took a long time and returned "Error: Script execution timeout" and of course, no stocks. Any idea why this is happening?
 
Does anyone know how to use this indicator in a custom watchlist? This is what I've got so far and I cannot get it to work. Help someone?

Code:
# Trend Reversal Scanner
# Scanner by https://usethinkscript.com/u/theelderwand
# Discuss https://usethinkscript.com/d/183-trend-reversal-indicator-with-signals-for-thinkorswim

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 bullish = signal > 0 and signal[1] <= 0;
plot upArrow = bullish;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
#upArrow.SetDefaultColor(CreateColor(145, 210, 144));
upArrow.AssignValueColor(Color.Light_Green);
#AddLabel(yes, "Buy", Color.Lime);


def bearish = signal < 0 and signal[1] >= 0;
plot downArrow = bearish;
downArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
#downArrow.SetDefaultColor(CreateColor(255, 15, 10));
downArrow.AssignValueColor(Color.Pink);
#AddLabel(yes, "Sell", Color.Pink);

# AddLabel(yes, if Bullish then ("Buy", Color.Lime) else Bearish ("Sell" , Color.Pink);

# =========================================
# Buy/Sell Signal
# =========================================
plot BuyAlert = bullish;
plot SellAlert = bearish;

BuyAlert.AssignValueColor(if BuyAlert then Color.Green else if SellAlert then Color.Red else Color.White);
AssignBackgroundColor(if BuyAlert then Color.Green else if SellAlert then Color.Red else Color.White);

Alert(BuyAlert, "Buy", Alert.BAR, Sound.Ring);

AddOrder(OrderType.BUY_AUTO, BuyAlert, tickColor = Color.Dark_Green, arrowColor =  Color.Dark_Green, name = "Buy");
AddOrder(OrderType.SELL_AUTO, SellAlert, tickColor = Color.Dark_Red, arrowColor = Color.Dark_Red, name = "Sell");

AddLabel(yes,
        if BuyAlert then Concat("BUY@ ", AsText(hl2, NumberFormat.Dollar)) else if SellAlert then Concat("SELL@ ", AsText(hl2, NumberFormat.Dollar)) else "", if BuyAlert then Color.Dark_Green else if SellAlert then Color.Dark_Red else Color.White);
 
Last edited:
@Picard
You have been asked to do your own searches for answers before posting.
If you don't know how to search a thread for an answer. Here are the directions.
Meanwhile, here is the answer to your question.
HTH
Yes, I understand what you are saying. I've done this before and made complicated indicator into a custom watchlist quote column by using the Wizard. http://tos.mx/VNXwnbK However, in this case there's something else that isn't quite working well and I keep going over it again and again to figure it out.
 
To Find A Shared Watchlist Column
  1. Click on MarketWatch at the top of the TOS app
  2. Click on the gear icon to the far right of all the columns in the table
  3. Type in the Name of the Indicator you imported
iQRvo7n.png

@royalrock HTH
 
Last edited:
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
543 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