Trend Reversal Indicator with Signals for ThinkorSwim

D

Dixon72

New member
Warehouse
@BenTen Oh sorry, guess I didn't mention that I get the above when trying to create an alert for the arrows. I'm trying to get alerted when the next 15 minute Trend Reversal arrow is displayed on a chart.
 
D

Dixon72

New member
Warehouse
@BenTen Scanning works just fine. Setting an alert, not so much... Any ideas?
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Dixon72 Many people have reported that alerts do not work for this indicator.
 
2

2sureshk

Member
I watched Pete Hahn's video, added "within 8 days" at the end of the script and it still doesn't work. I'd gladly add a screenshot to show what's happening, but I can't figure out how to add a picture to this thread to save my life...

My scan parameters are: Trend_Reversal_SCAN()."downArrow" equals 1 within 8 bars
The error I get is, "Error processing referenced script Trend_Reversal_scan: No such function: CompoundValue at 1:1 Expected double" and "Trend_Reversal_Scan()" is highlighted in red as though thinkscript has issues with the scan itself...
Please paste the scan script , I will try to replicate and find if I can see the same error
 
D

Dixon72

New member
Warehouse
@2sureshk That would be awesome!! The script that I have is below. I can only assume it's the most current version...

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

tomsk

Well-known member
VIP
Warehouse
@Dixon72 I looked through the code you posted - noticed that there re several calls to CompoundValue() that the scanner typically reports problems with. All CompoundValue() does is that it initializes the code to a value. I have a version going that replaces this with a standard if-then-else comparison. While the scanner no longer complains, I am unable to obtain any signals from the scanner. Looks like this study utilizes a combination of Moving Average crossover comparisons with the TOS ZigZagHighLow study.
 
2

2sureshk

Member
as you mentioned the code with in the scan is not fetching the list. as per my observation it cold be due to the complexity of the code. but I find the alternative option. follow the below and see if you see the same results.

1. Copy the code and create a study (example study name: Trendreversaltest)
2. Go to the Scan and add the Filter select Study.
3. Find the newly created study Trendreversaltest - > upArrow is True with in 2 Bars. ( Daily Scan)

  • Note Criterial for ALL Stocks All optionable it appears that there could be a limitation TOS if you don't select this option you see Error
  • I recommend to use your limited Watch list instead of selecting All stocks
  • you should see the editor script as below

Trendreversaltest()."upArrow" is true within 2 bars

it should give the Bullish2 scan list.

follow the same for Bearish by selecting the DownArrow is true.


Thanks,
Suresh K
 
R

rwfarrell

New member
@BenTen my apologies, I am asking the same question here I did for a different trend reversal indicator. This is correct link I wanted to ask about. Can you create an alert on say the daily chart when the reversal happens up or down in a watchlist of favorite stocks? I am not looking for a scanner for reversals just how to create an alert on the watchlist of stocks. Thank you.
 
D

Dixon72

New member
Warehouse
@tomsk Scanning works just fine for me. Where I have issues is putting the scan/indicator into an alert so I'm notified (email, etc.). Does your if-then-else fix error when you select it in an alert?
 
2

2sureshk

Member
As per the developer for this it is not possible . I was also looking for the same
 
2

2sureshk

Member
Sorry , it could be only possible to see sound alert ,, for some of the studies TOS email alert is not possible . This could be one of them . Or some another expert may be can help with any idea
 
T

tomsk

Well-known member
VIP
Warehouse
As noted in my earlier post, the Trend Reversal code has BOTH a moving average component as well as the TOS ZigZagHighLow component.
The crux of the issue is that ZigZag uses future bars and the scanner doesn't see future bars you won’t be able to scan for it. The other issue is that recursive expressions are not permitted in MarketWatch Alerts. Since there is a fair amount of recursion in the code, does not appear to have any easy solution.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Nikola Post a screenshot of your scanner
 
L

Lauri

New member
I tried to scan with the trend reversal indicator, but it doesn't seem to work. I loaded to study into the scan and asked that if the UpArrow was true within 3 days to list result. The error I am getting says "Error: Trying to self-assign a non-initialized rec: state." Can you tell me what I need to do to get it to work? Thanks, newbie here, struggling.
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Lauri Try scanning it against a smaller watchlist. See if that helps.
 

Top