# 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)
#@RLohmeyer Paired down version of the ZigZag code with primary input parmaters identified
#Input Parameters
input averagelength = 5;
input averagetype = AverageType.EXPONENTIAL;
input percentamount = .01;
input revAmount = .02;
input atrlength = 4;
input atrreversal = 1.5;
# ZigZagHighLow 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 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);
def revLineTop;
def revLineBot;
if barnumber and D1 {
revLineBot = Double.NaN;
revLineTop = high[1];
} else if barnumber and U1 {
revLineTop = Double.NaN;
revLineBot = low[1];
} else if !IsNaN(revLineBot[1]) and (Colorbars[2] == 2 or Colorbars[1] == 2) {
revLineBot = revLineBot[1];
revLineTop = Double.NaN;
} else if !IsNaN(revLineTop[1]) and (Colorbars[2] == 1 or Colorbars[1] == 1) {
revLineTop = revLineTop[1];
revLineBot = Double.NaN;
} else {
revLineTop = Double.NaN;
revLineBot = Double.NaN;
}
plot botLine = revLineBot[-1];
botLine.SetDefaultColor(Color.GREEN);
plot topLine = revLineTop[-1];
topLine.SetDefaultColor(Color.RED);
# 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);
Put the dots on a chart and look where they fire, then the Hi_Low mark, place an alert above the body of High_Low, either enter there or find the yellow dot for entry, stop on body low/high.....you have to read price, so necessary to understand candles.....I have been using the bar colors for many months and find them very useful...I will be interested to see how the Dots fit in...
I'll be using this on a tick chart and I have the dots marked and I primarily look at price action...thanksPut the dots on a chart and look where they fire, then the Hi_Low mark, place an alert above the body of High_Low, either enter there or find the yellow dot for entry, stop on body low/high.....you have to read price, so necessary to understand candles
# Swing High and Swing Low
# tomsk
# 11.18.2019
# As requested by chillc15 I have modified @RobertPayne code to include SwingHigh points which are now plotted in CYAN with the SwingLow points painted in Magenta.
# So now you have both swing high and low on your charts
#Code modified by @rlohmeyer
#Primary Definitions
input length = 10;
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def offset = Min(length - 1, lastBar - bn);
# SWING POINTS
def swingLow = low < Lowest(low[1], length - 1) and low == GetValue(Lowest(low, length), -offset);
def swingHigh = high > Highest(high[1], length - 1) and high == GetValue(Highest(high, length), -offset);
#Identify the very last swing low point and 10 previous
def lowPointOneBarNumber = HighestAll(if swingLow then bn else 0);
def lowPointOneValue = if bn == lowPointOneBarNumber then low else lowPointOneValue[1];
def lowPointTwoBarNumber = HighestAll(if swingLow and bn < lowPointOneBarNumber then bn else 0);
def lowPointTwoValue = if bn == lowPointTwoBarNumber then low else lowPointTwoValue[1];
def lowPointThreeBarNumber = HighestAll(if swingLow and bn < lowPointTwoBarNumber then bn else 0);
def lowPointThreeValue = if bn == lowPointThreeBarNumber then low else lowPointThreeValue[1];
def lowPointFourBarNumber = HighestAll(if swingLow and bn < lowPointThreeBarNumber then bn else 0);
def lowPointFourValue = if bn == lowPointFourBarNumber then low else lowPointFourValue[1];
def lowPointFiveBarNumber = HighestAll(if swingLow and bn < lowPointFourBarNumber then bn else 0);
def lowPointFiveValue = if bn == lowPointFiveBarNumber then low else lowPointFiveValue[1];
def lowPointSixBarNumber = HighestAll(if swingLow and bn < lowPointFiveBarNumber then bn else 0);
def lowPointSixValue = if bn == lowPointSixBarNumber then low else lowPointSixValue[1];
def lowPointSevenBarNumber = HighestAll(if swingLow and bn < lowPointSixBarNumber then bn else 0);
def lowPointSevenValue = if bn == lowPointSevenBarNumber then low else lowPointSevenValue[1];
def lowPointEightBarNumber = HighestAll(if swingLow and bn < lowPointSevenBarNumber then bn else 0);
def lowPointEightValue = if bn == lowPointEightBarNumber then low else lowPointEightValue[1];
def lowPointNineBarNumber = HighestAll(if swingLow and bn < lowPointEightBarNumber then bn else 0);
def lowPointNineValue = if bn == lowPointNineBarNumber then low else lowPointNineValue[1];
def lowPointTenBarNumber = HighestAll(if swingLow and bn < lowPointNineBarNumber then bn else 0);
def lowPointTenValue = if bn == lowPointTenBarNumber then low else lowPointTenValue[1];
# Identify the very last swing high point and 10 others
def highPointOneBarNumber = HighestAll(if swingHigh then bn else 0);
def highPointOneValue = if bn == highPointOneBarNumber then high else highPointOneValue[1];
def highPointTwoBarNumber = HighestAll(if swingHigh and bn < highPointOneBarNumber then bn else 0);
def highPointTwoValue = if bn == highPointTwoBarNumber then high else highPointTwoValue[1];
def highPointThreeBarNumber = HighestAll(if swingHigh and bn < highPointTwoBarNumber then bn else 0);
def highPointThreeValue = if bn == highPointThreeBarNumber then high else highPointThreeValue[1];
def highPointFourBarNumber = HighestAll(if swingHigh and bn < highPointThreeBarNumber then bn else 0);
def highPointFourValue = if bn == highPointFourBarNumber then high else highPointFourValue[1];
def highPointFiveBarNumber = HighestAll(if swingHigh and bn < highPointFourBarNumber then bn else 0);
def highPointFiveValue = if bn == highPointFiveBarNumber then high else highPointFiveValue[1];
def highPointSixBarNumber = HighestAll(if swingHigh and bn < highPointFiveBarNumber then bn else 0);
def highPointSixValue = if bn == highPointSixBarNumber then high else highPointSixValue[1];
def highPointSevenBarNumber = HighestAll(if swingHigh and bn < highPointSixBarNumber then bn else 0);
def highPointSevenValue = if bn == highPointSevenBarNumber then high else highPointSevenValue[1];
#
def highPointEightBarNumber = HighestAll(if swingHigh and bn < highPointSevenBarNumber then bn else 0);
def highPointEightValue = if bn == highPointEightBarNumber then high else highPointEightValue[1];
def highPointNineBarNumber = HighestAll(if swingHigh and bn < highPointEightBarNumber then bn else 0);
def highPointNineValue = if bn == highPointNineBarNumber then high else highPointNineValue[1];
def highPointTenBarNumber = HighestAll(if swingHigh and bn < highPointNineBarNumber then bn else 0);
def highPointTenValue = if bn == highPointTenBarNumber then high else highPointTenValue[1];
# ADJUST CANDLE COLORS
AssignPriceColor(if swingLow then Color.CYAN else if swingHigh then Color.CYAN else Color.current);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
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.