Trend Reversal Indicator with Signals for ThinkorSwim

H

HighNDryTrader

New member
@BLT Welcome to useThinkScript! Happy that you are lending your experience to this excellent website.
@BLT @markos @tomsk thanks you very much for your replies. I will try the code and see if it works.
 
H

HighNDryTrader

New member
@HighNDryTrader
Add these to the bottom of the script to create the alerts that I think you are wanting

alert(bullish2[1], "Bull", Alert.BAR, Sound.Ring);
alert(bearish2[1], "Bear", Alert.BAR, Sound.Ding);
Thanks @BLT this works like a charm.
 
V

vinora

New member
do i just copy and paste this at the end of the original script?
 
B

BLT

New member
@vinora Here is the script with the alerts added

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

alert(bullish2[1], "Bull", Alert.BAR, Sound.Ring);
alert(bearish2[1], "Bear", Alert.BAR, Sound.Ding);
 
H

HighBredCloud

Active member
Guys...I've never imported a custom scan into the scanner before...I have a few questions in regards to the scan posted by @BLT in post #424...I watched the tutorial video but I am not sure IF that's how you do this...

Can someone tell me what conditions I need to add from the pic below because the tutorial video only showed "true"...Is this the case for EVERY scanner or are there different inputs for the conditions part? How do I know what to select? ALSO...IF I am trading on the 5 min chart I am assuming that I need to change the AGGREGATION part from D to whatever timeframe I am trading on for the scan to work? Or does the scan work better on certain types of AGGREGATIONS than others?



NEXT...there are two options for the scanner...UP arrow and DOWN arrow...when I select ADD Condition and I try to add the DOWN arrow I cannot hit OK button...and I get this error.



Is the proper remedy to add a second study filter and select custom then the indicator...followed by DOWN arrow to basically reflect this below:



Obviously nothing comes up now when I scan...I am assuming because the market is closed...I hope that I am not doing anything wrong on my end...Can someone please confirm what I am doing to be correct so that I can save this scan and finally know how to utilize them...Thanks.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@HighBredCloud When scanning for up/down signals, most likely, you will have to use the "true" condition. Due to the complexity of this script, you can only scan for one type of signal at a time (bullish or bearish). The setup that you have in the last picture is showing that you want to scan for both up and down arrows at the same time. I don't think that will yield any result.

Here is how I would set it up.

 
H

HighBredCloud

Active member
@BenTen Thanks...OK...so basically what I need to do is make a separate scan for bullish and bearish...I was not aware of this. I am assuming that same would be true if I used a HULL scan that is positive or negative that I would also need two separate scans for that as well? Now as far as the Aggregation goes...the scan in your pic will scan for DAILY trend reversals to the UP side...IF I am trading a 5 min chart I am assuming just change that to the 5 min? Reason why I ask is that I recall having a conversation with TOS support and they said that scans tend to appear late sometimes up to 2-3 candlesticks late despite of the timeframe...making you miss the moves you're scanning for to begin with. This was more pertaining a scan I did for a MA cross over...
 
H

HighBredCloud

Active member
@BenTen I just tried scanning by deleting EVERYTHING from my previous scan set up and leaving it the way you had it in your pic...and I can't come up with anything...and seem to get the error I circled...any ideas?

 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@HighBredCloud This indicator is not suitable for someone who just started using the ToS scanner. It has been mentioned from the start that this indicator repaint and how complex it its. As a result, you need to use a smaller watchlist (from that picture, you're using the "All Stocks" watchlist). If you want to scan for signals on the 5m chart, then change the timeframe from the scanner to 5m.
 
T

tomsk

Well-known member
VIP
Warehouse
@BenTen Exactly right, and perhaps this is the reason why no signals show up for bullish/bearish scans across all aggregations. I ran those scans and checked. Like I mentioned much earlier, this study sure looks so good on hindsight, due to the "repainting" profile it has.
 
S

Superfast

New member
Marketplace
Good day, I'd like to change the scanner script below to a watchlist and on the watchlist I'd like to have the background colour of the cell be yellow or show 1 for buy signal. Can someone help please? Thanks.
 
S

Superfast

New member
Marketplace
I'd also like to have the signal on the watchlist show any signals within 4 bars ago. Is this possible?
 
C

Cut Throat Trader

New member
I just added this indicator and I've notice a lot of false signals ? When wrong the reversal tag disappears all together ? Is anybody else getting this too ?
 
A

Antares66

New member
Has someone made an adaption to tradingview in the meantime? I use them both.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Cut Throat Trader You should see the opposite. You should only see perfect signals. All the wrong reversal signals has disappear (note: the indicator will repaint so be cautious when using it).
 
CLICKANDGRAB808

CLICKANDGRAB808

New member
its a reverse indicator looking for a scanner that would alert buy and sell signals
 
Last edited by a moderator:
J007RMC

J007RMC

Active member
VIP
Warehouse
In majority of pinning's I'm finding this to be an extremely accurate/decisive indicator on a 1000t chart may be a bar late or early but its great stuff
https://tos.mx/GfzAhpT. Along with the WT_LV_TV, upper indicator upperhttps://
tos.mx/DBWgOvD
as for confirmation provided by ES-STRATEGY on site.

Scanner on the first page of this thread or you can use the code below. It works as indicator and scanner.
Code:
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));
 
Last edited by a moderator:

Top