WaveTrend Oscillator for ThinkorSwim [LazyBear]

I really like this indicator, here is another fun take on it, this is the wavetrend indicator with a donchian, donchian channels are usually calculated over 21 periods however I notice that a 34 period could give you better "safer" signals, although 21 period works just fine, I use it to confirm a continuation of direction.

pP2kIlV.png


Code:
#WT_LB Short Name TV
declare lower;
input Channel_Length = 10; #10
input Average_Length = 21; #10
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;
input show_bubbles = yes;
input show_sec_bbls = no;
input show_alerts = yes;
def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 4);
def zero = 0;

plot obLevel1 = over_bought_1;
obLevel1.SetDefaultColor(Color.RED);
plot osLevel1 = over_sold_1;
osLevel1.SetDefaultColor(Color.GREEN);
plot  obLevel2 = over_bought_2;
obLevel2.SetDefaultColor(Color.RED);
obLevel2.SetStyle(Curve.SHORT_DASH);
plot  osLevel2 = over_sold_2;
osLevel2.SetDefaultColor(Color.GREEN);
osLevel2.SetStyle(Curve.SHORT_DASH);

plot wt1_1 = wt1;
wt1_1.SetDefaultColor(Color.GREEN);
plot wt2_1 = wt2;
wt2_1.SetDefaultColor(Color.RED);
wt2_1.SetStyle(Curve.POINTS);
def signal1 = wt1 crosses above wt2 and wt1 < over_sold_2;
plot Signal = if signal1  then (signal1 * over_sold_2) else Double.NaN;
Signal.SetDefaultColor(Color.GREEN);
Signal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal.SetLineWeight(3);
Signal.HideTitle();
def signal2 = wt1 crosses below wt2 and wt1 > over_bought_2;
plot Signal2_ = if signal2  then (signal2 * over_bought_2) else Double.NaN;
Signal2_.SetDefaultColor(Color.RED);
Signal2_.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal2_.SetLineWeight(3);
Signal2_.HideTitle();



#Name:             DonchianChannel
#Programmed By:    Chris Ball ([email protected]) on 10/23/08
#Posted At:        http://chartingwithchris.blogspot.com
#Description:      This is a channel system that is used frequently for trend trading.  Google the term "turtle trader" for more information.
#Modified 2020-06-10 by rad14733 to utilize AddCloud()

input length_donchian = 34;

plot upperBand = Highest(wt1_1[1], length_donchian);
plot lowerBand = Lowest(wt1_1[1],  length_donchian);
plot middleBand = (upperBand + lowerBand) / 2;

upperBand.SetDefaultColor(Color.DARK_GRAY);
lowerBand.SetDefaultColor(Color.DARK_GRAY);
middleBand.SetDefaultColor(Color.Orange);

AddCloud(upperBand, lowerBand, Color.DARK_GRAY, Color.WHITE);
 
MTF WaveTrend Oscillator upper chart arrows only
YL0o3ok.png

Shared Study Link: http://tos.mx/aFYR0rH
Easiest way to load shared links
Code:

Ruby:
#WT_LB Short Name TV  ****MTF**** WaveTrend Upper Chart Arrows Only
input Channel_Length = 10; #10
input Average_Length = 21; #10
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;
input AGG = aggregationPeriod.HOUR ;
def hlc3 = hlc3(period = AGG);

def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 4);

def signal1 = wt1 crosses above wt2 and wt1 < over_sold_2;
plot Signal = if signal1  then low else Double.NaN;
Signal.SetDefaultColor(Color.blue);
Signal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal.SetLineWeight(3);
Signal.HideTitle();
def signal2 = wt1 crosses below wt2 and wt1 > over_bought_2;
plot Signal2_ = if signal2  then high else Double.NaN;
Signal2_.SetDefaultColor(Color.magenta);
Signal2_.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal2_.SetLineWeight(3);
Signal2_.HideTitle();
@stocksniper
 
Last edited:
VOLATILITY RATIO INDICATOR FOR THINKORSWIM HELP
Can someone help turn the Volatility Ratio Indicator from Tradingview to ThinkorSwim code? Much appreciated.
 
Last edited by a moderator:
@Mr.T Assuming it is a lower chart indicator. if that is what you are looking for here is the code.

Ruby:
#Convered to TOS by @SuryaKiranC
#Requested by Mr.T
#https://usethinkscript.com/threads/volatility-ratio-indicator-for-thinkorswim-help.9092/

declare lower;
input n1 = 10;
input n2 = 21;
input price = HLC3;

input OB1 = 60;
input OB2 = 53;
input OS1 = -60;
input OS2 = -53;

def esa = ExpAverage(price, n1);
def d = ExpAverage(AbsValue(price - esa),n1);
def ci = (price - esa) / (0.015 * d);
def tci = ExpAverage(ci,n2);
def wt1 = tci;
def wt2 = simpleMovingAvg(wt1, 4);

plot Zero = 0;
plot OverSold1 = OS1;
OverSold1.SetDefaultColor(Color.GREEN);
plot OverSold2 = OS2;
OverSold2.SetDefaultColor(Color.GREEN);
OverSold2.SetStyle(Curve.SHORT_DASH);
plot OverBought1 = OB1;
OverBought1.SetDefaultColor(Color.RED);
plot OverBought2 = OB2;
OverBought2.SetDefaultColor(Color.RED);
OverBought2.SetStyle(Curve.SHORT_DASH);

plot w1 = wt1;
w1.SetDefaultColor(Color.GREEN);
plot w2 = wt2;
w2.SetDefaultColor(Color.RED);
plot diff = wt1 - wt2;
diff.SetDefaultColor(Color.CYAN);

#End
 
Had to set up a new version of TOS and lost old templates. Can't find the Wavetrendbentenwalarms indicator. Anyone have an old copy they can post code for me? Thank you in advance.
 
Had to set up a new version of TOS and lost old templates. Can't find the Wavetrendbentenwalarms indicator. Anyone have an old copy they can post code for me? Thank you in advance.
I moved your thread here as there are dozens of wave trend script variations within. Start w/ page 1 and plug&play
 
On this study, once the signal candle has closed it plots the vertical signal line behind (to the left) the candle. Is it possible to have this shift to once the signal candle closes to post that signal to the right of the candle where the white line is?

chart (sorry not sure how to add an image, chart is the image)

declare lower;
input Channel_Length = 10;
input Average_Length = 21;
input wt_Length = 4;
def esa = MovingAverage(AverageType.EXPONENTIAL, hlc3, Channel_Length);
def d = MovingAverage(AverageType.EXPONENTIAL, AbsValue(hlc3 - esa), Channel_Length);
def ci = (hlc3 - esa) / (0.01 * d);
def tci = MovingAverage(AverageType.EXPONENTIAL, ci, Average_Length);
plot wt1 = tci;
wt1.SetDefaultColor(Color.GREEN);
plot wt2 = MovingAverage(AverageType.Simple, Wt1, wt_Length);
wt2.SetDefaultColor(Color.RED);

input overBought = 60;
input overSold = -60;
plot zero = 0;
zero.setDefaultColor(color.white);
plot ob = overBought;
plot os = oversold;
ob.setDefaultColor(color.red);
os.setDefaultColor(color.Green);
plot top = 100;
plot bottom = -100;
top.setDefaultColor(color.Gray);
bottom.setDefaultColor(color.Gray);
plot line=0;


input diffRange1 = 5;
input diffRange2 = 0;

def diff = wt1 - wt2;

AddLabel(1, "Money Spread: " + diff, if diff > diffRange1 then Color.green else if diff > diffRange2 then Color.Yellow else Color.red);


addverticalLine( if wt1 crosses above WT2 then high else double.nan, "B U Y", color.green, curve.firm);
addverticalLine( if wt1 crosses below WT2 then low else double.nan, "S E L L", color.RED, curve.firm);
 
On this study, once the signal candle has closed it plots the vertical signal line behind (to the left) the candle. Is it possible to have this shift to once the signal candle closes to post that signal to the right of the candle where the white line is?
like this perhaps:
Code:
addverticalLine( if wt1[1] crosses above WT2[1] then high else double.nan, "B U Y", color.green, curve.firm);
addverticalLine( if wt1[1] crosses below WT2[1] then low else double.nan, "S E L L", color.RED, curve.firm);
the bracket notation tells ToS to look at the cross condition for one bar ago rather than the current bar.

happy trading
mashume
 
Last edited by a moderator:
hello can someone help me take the mtf portion out of this indicator

# WT_LB Short Name TV
# Modidied into an MTF version by BenTen at UseThinkScript.com

declare upper;
input aggregationPeriod = AggregationPeriod.DAY;
def close = close (period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
input Channel_Length = 10; #10
input Average_Length = 21; #10

input show_bubbles = yes;
input show_sec_bbls = no;
input show_alerts = yes;
def ap = (High + Low + Close) / 3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 =esa;# tci;
def wt2 = SimpleMovingAvg(wt1, 4);
#def zero = 0;
plot w=esa;
plot w1=SimpleMovingAvg(w, 4);

plot wt1_1 = wt1;
wt1_1.SetDefaultColor(Color.GREEN);
plot wt2_1 = wt2;
wt2_1.SetDefaultColor(Color.RED);
wt2_1.SetStyle(Curve.POINTS);

addCloud(wt1_1, wt2_1, Color.LIGHT_GREEN, color.red);


assignpricecolor( if wt1_1<wt2_1 then color.red else if wt1_1 > wt2_1 then color.blue else color.gray);
 
Last edited by a moderator:
hello can someone help me take the mtf portion out of this indicator

Here ya go:
Ruby:
# WT_LB Short Name TV
# Modified by BenTen at UseThinkScript.com

declare upper;

input Channel_Length = 10; #10
input Average_Length = 21; #10

input show_bubbles = yes;
input show_sec_bbls = no;
input show_alerts = yes;
def ap = (High + Low + Close) / 3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 =esa;# tci;
def wt2 = SimpleMovingAvg(wt1, 4);
#def zero = 0;
plot w=esa;
plot w1=SimpleMovingAvg(w, 4);

plot wt1_1 = wt1;
wt1_1.SetDefaultColor(Color.GREEN);
plot wt2_1 = wt2;
wt2_1.SetDefaultColor(Color.RED);
wt2_1.SetStyle(Curve.POINTS);

addCloud(wt1_1, wt2_1, Color.LIGHT_GREEN, color.red);


assignpricecolor( if wt1_1<wt2_1 then color.red else if wt1_1 > wt2_1 then color.blue else color.gray);
 
Last edited:
Is it possible to auto draw a trendline that connects two points on a lower study? I have the following code which plots the line as DOTS. I wish to connect the latest Higher Low and the latest Lower High (red and green dots) of the indicator. Thanks in advance.

https://usethinkscript.com/threads/wavetrend-oscillator-for-thinkorswim-lazybear.233/
#WaveTrend Oscillator script for ThinkorSwim. Came from Came LazyBear over at TradingView version that was ported from TS/MT
# also known as "The Perfect Leading Indicator."
#ported by BenTen 6/18/19
#WT_LB Short Name TV
declare lower;

input Channel_Length = 10;
input Average_Length = 21;
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;

input numBars = 5;
input TrendResistanceStart = 0;
input TrendResistanceEnd = 0;
input TrendSupportStart = 0;
input TrendSupportEnd = 0;


def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 4);

def green = if wt1 > wt1[1] AND wt1[1] <= wt1[2] then 1 ELSE 0;
def red = if wt1 < wt1[1] AND wt1[1] >= wt1[2] then 1 ELSE 0;

plot wt1_1 = wt1;
wt1_1.SetStyle(Curve.POINTS);
wt1_1.AssignValueColor(if green then (CreateColor(55, 251, 55)) else if red then (CreateColor(255, 0, 0)) else (color.gray));
wt1_1.SetLineWeight(5);

def UserSetResistance = TrendResistanceStart > 0 and TrendResistanceEnd > 0;
def UserSetSupport = TrendSupportStart > 0 and TrendSupportEnd > 0;
def currentHigh = high;
def currentLow = low;
def currentBar = BarNumber();
def PH;
def PL;

# +---------------------+
# | PIVOT HIGH |
# +---------------------+

def isHigherThanNextBars = fold i = 1 to numBars + 1 with p = 1
while p do currentHigh > GetValue(high, -i);

PH = if wt1 < wt1[1] AND wt1[1] >= wt1[2] then currentHigh else Double.NaN;

# +---------------------+
# | PIVOT LOW |
# +---------------------+

def isLowerThanNextBars = fold j = 1 to numBars + 1 with q = 1
while q do currentLow < GetValue(low, -j);

PL = if wt1 > wt1[1] AND wt1[1] <= wt1[2] then currentLow else Double.NaN;

# +---------------------+
# | ESTABLISH THE DOTS |
# +---------------------+

rec PHBar = if UserSetResistance then TrendResistanceEnd else if !IsNaN(PH) then currentBar else PHBar[1];
rec PLBar = if UserSetSupport then TrendSupportEnd else if !IsNaN(PL) then currentBar else PLBar[1];
rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec priorPHBar = if UserSetResistance then TrendResistanceStart else if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];
rec priorPLBar = if UserSetSupport then TrendSupportStart else if PLL != PLL[1] then PLBar[1] else priorPLBar[1];
def isFinalTwoHighPivots = currentBar >= HighestAll(priorPHBar);
def isFinalTwoLowPivots = currentBar >= HighestAll(priorPLBar);
def ResistanceFinishOffset = if isFinalTwoHighPivots then currentBar - PHBar else 0;
def ResistanceStartOffset = if isFinalTwoHighPivots then currentBar - priorPHBar else 0;
def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) - GetValue(PH, ResistanceStartOffset)) / (PHBar - priorPHBar);
def SupportFinishOffset = if isFinalTwoLowPivots then currentBar - PLBar else 0;
def SupportStartOffset = if isFinalTwoLowPivots then currentBar - priorPLBar else 0;
def SupportSlope = (GetValue(PL, SupportFinishOffset) - GetValue(PL, SupportStartOffset)) / (PLBar - priorPLBar);
rec ResistanceExtend = if currentBar == HighestAll(PHBar) then 1 else ResistanceExtend[1];
rec SupportExtend = if currentBar == HighestAll(PLBar) then 1 else SupportExtend[1];

def pivotHigh = if
ph>0 then PH else Double.NaN;

def pivotLow = if
pl>0 then PL else Double.NaN;

def pivotdot = if !IsNaN(pivotHigh) then pivotHigh else if !IsNaN(pivotLow) then pivotLow else Double.NaN;

# +---------------------+
# | CONNECT THE DOTS |
# +---------------------+

script Line {
input v = 0; #value
input s = 0; #start
input e = 0; #end
input xl = 0; #extend left
input xr = Double.POSITIVE_INFINITY; #extend right
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def x1 = Min(s, e);
def x2 = Max(s, e);
def y1 = GetValue(v, bn - x1);
def y2 = GetValue(v, bn - x2);
def m = (y2 - y1) / (x2 - x1);
def x = bn - x1;
def b = y1;
plot return = if bn < (x1 - xl) or bn > (x2 + xr) then Double.NaN else m * x + b;
}
def bn = BarNumber();
def prevPH = if !IsNaN(PH[1]) then high else prevPH[1];
def prevBh = if !IsNaN(PH[1]) then bn[1] else prevBh[1];
def prevPL = if !IsNaN(PL[1]) then low else prevPL[1];
def prevBl = if !IsNaN(PL[1]) then bn[1] else prevBl[1];
def rEnd = HighestAll(if !IsNaN(PH) and high < prevPH then bn else 0);
def rStart = HighestAll(if bn == rEnd then prevBh else 0);
def sEnd = HighestAll(if !IsNaN(PL) and low > prevPL then bn else 0);
def sStart = HighestAll(if bn == sEnd then prevBl else 0);

plot resistance = line(high, rStart, rEnd);
resistance.SetDefaultColor(CreateColor( 255, 126, 156));
resistance.SetLineWeight(3);

plot support = line(low, sStart, sEnd);
support.SetDefaultColor(CreateColor( 51, 255, 51));
support.SetLineWeight(3);
 
Last edited by a moderator:
Is it possible to auto draw a trendline that connects two points on a lower study? I have the following code which plots the line as DOTS. I wish to connect the latest Higher Low and the latest Lower High (red and green dots) of the indicator. Thanks in advance.

https://usethinkscript.com/threads/wavetrend-oscillator-for-thinkorswim-lazybear.233/
#WaveTrend Oscillator script for ThinkorSwim. Came from Came LazyBear over at TradingView version that was ported from TS/MT
# also known as "The Perfect Leading Indicator."
#ported by BenTen 6/18/19
#WT_LB Short Name TV
declare lower;

input Channel_Length = 10;
input Average_Length = 21;
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;

input numBars = 5;
input TrendResistanceStart = 0;
input TrendResistanceEnd = 0;
input TrendSupportStart = 0;
input TrendSupportEnd = 0;


def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 4);

def green = if wt1 > wt1[1] AND wt1[1] <= wt1[2] then 1 ELSE 0;
def red = if wt1 < wt1[1] AND wt1[1] >= wt1[2] then 1 ELSE 0;

plot wt1_1 = wt1;
wt1_1.SetStyle(Curve.POINTS);
wt1_1.AssignValueColor(if green then (CreateColor(55, 251, 55)) else if red then (CreateColor(255, 0, 0)) else (color.gray));
wt1_1.SetLineWeight(5);

def UserSetResistance = TrendResistanceStart > 0 and TrendResistanceEnd > 0;
def UserSetSupport = TrendSupportStart > 0 and TrendSupportEnd > 0;
def currentHigh = high;
def currentLow = low;
def currentBar = BarNumber();
def PH;
def PL;

# +---------------------+
# | PIVOT HIGH |
# +---------------------+

def isHigherThanNextBars = fold i = 1 to numBars + 1 with p = 1
while p do currentHigh > GetValue(high, -i);

PH = if wt1 < wt1[1] AND wt1[1] >= wt1[2] then currentHigh else Double.NaN;

# +---------------------+
# | PIVOT LOW |
# +---------------------+

def isLowerThanNextBars = fold j = 1 to numBars + 1 with q = 1
while q do currentLow < GetValue(low, -j);

PL = if wt1 > wt1[1] AND wt1[1] <= wt1[2] then currentLow else Double.NaN;

# +---------------------+
# | ESTABLISH THE DOTS |
# +---------------------+

rec PHBar = if UserSetResistance then TrendResistanceEnd else if !IsNaN(PH) then currentBar else PHBar[1];
rec PLBar = if UserSetSupport then TrendSupportEnd else if !IsNaN(PL) then currentBar else PLBar[1];
rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec priorPHBar = if UserSetResistance then TrendResistanceStart else if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];
rec priorPLBar = if UserSetSupport then TrendSupportStart else if PLL != PLL[1] then PLBar[1] else priorPLBar[1];
def isFinalTwoHighPivots = currentBar >= HighestAll(priorPHBar);
def isFinalTwoLowPivots = currentBar >= HighestAll(priorPLBar);
def ResistanceFinishOffset = if isFinalTwoHighPivots then currentBar - PHBar else 0;
def ResistanceStartOffset = if isFinalTwoHighPivots then currentBar - priorPHBar else 0;
def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) - GetValue(PH, ResistanceStartOffset)) / (PHBar - priorPHBar);
def SupportFinishOffset = if isFinalTwoLowPivots then currentBar - PLBar else 0;
def SupportStartOffset = if isFinalTwoLowPivots then currentBar - priorPLBar else 0;
def SupportSlope = (GetValue(PL, SupportFinishOffset) - GetValue(PL, SupportStartOffset)) / (PLBar - priorPLBar);
rec ResistanceExtend = if currentBar == HighestAll(PHBar) then 1 else ResistanceExtend[1];
rec SupportExtend = if currentBar == HighestAll(PLBar) then 1 else SupportExtend[1];

def pivotHigh = if
ph>0 then PH else Double.NaN;

def pivotLow = if
pl>0 then PL else Double.NaN;

def pivotdot = if !IsNaN(pivotHigh) then pivotHigh else if !IsNaN(pivotLow) then pivotLow else Double.NaN;

# +---------------------+
# | CONNECT THE DOTS |
# +---------------------+

script Line {
input v = 0; #value
input s = 0; #start
input e = 0; #end
input xl = 0; #extend left
input xr = Double.POSITIVE_INFINITY; #extend right
def bn = BarNumber();
def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
def x1 = Min(s, e);
def x2 = Max(s, e);
def y1 = GetValue(v, bn - x1);
def y2 = GetValue(v, bn - x2);
def m = (y2 - y1) / (x2 - x1);
def x = bn - x1;
def b = y1;
plot return = if bn < (x1 - xl) or bn > (x2 + xr) then Double.NaN else m * x + b;
}
def bn = BarNumber();
def prevPH = if !IsNaN(PH[1]) then high else prevPH[1];
def prevBh = if !IsNaN(PH[1]) then bn[1] else prevBh[1];
def prevPL = if !IsNaN(PL[1]) then low else prevPL[1];
def prevBl = if !IsNaN(PL[1]) then bn[1] else prevBl[1];
def rEnd = HighestAll(if !IsNaN(PH) and high < prevPH then bn else 0);
def rStart = HighestAll(if bn == rEnd then prevBh else 0);
def sEnd = HighestAll(if !IsNaN(PL) and low > prevPL then bn else 0);
def sStart = HighestAll(if bn == sEnd then prevBl else 0);

plot resistance = line(high, rStart, rEnd);
resistance.SetDefaultColor(CreateColor( 255, 126, 156));
resistance.SetLineWeight(3);

plot support = line(low, sStart, sEnd);
support.SetDefaultColor(CreateColor( 51, 255, 51));
support.SetLineWeight(3);

This is intended to draw a line between the last green and red dots.

Capture.jpg
Ruby:
#WaveTrend Oscillator script for ThinkorSwim. Came from Came LazyBear over at TradingView version that was ported from TS/MT
# also known as "The Perfect Leading Indicator."
#ported by BenTen 6/18/19
#WT_LB Short Name TV
declare lower;

input Channel_Length = 10;
input Average_Length = 21;
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;

input numBars = 5;
input TrendResistanceStart = 0;
input TrendResistanceEnd = 0;
input TrendSupportStart = 0;
input TrendSupportEnd = 0;


def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 4);

def green = if wt1 > wt1[1] and wt1[1] <= wt1[2] then 1 else 0;
def red = if wt1 < wt1[1] and wt1[1] >= wt1[2] then 1 else 0;

plot wt1_1 = wt1;
wt1_1.SetStyle(Curve.POINTS);
wt1_1.AssignValueColor(if green then (CreateColor(55, 251, 55)) else if red then (CreateColor(255, 0, 0)) else (Color.GRAY));
wt1_1.SetLineWeight(2);

def UserSetResistance = TrendResistanceStart > 0 and TrendResistanceEnd > 0;
def UserSetSupport = TrendSupportStart > 0 and TrendSupportEnd > 0;
def currentHigh = high;
def currentLow = low;
def currentBar = BarNumber();
def PH;
def PL;

# +---------------------+
# | PIVOT HIGH |
# +---------------------+

def isHigherThanNextBars = fold i = 1 to numBars + 1 with p = 1
while p do currentHigh > GetValue(high, -i);

PH = if wt1 < wt1[1] and wt1[1] >= wt1[2] then currentHigh else Double.NaN;

# +---------------------+
# | PIVOT LOW |
# +---------------------+

def isLowerThanNextBars = fold j = 1 to numBars + 1 with q = 1
while q do currentLow < GetValue(low, -j);

PL = if wt1 > wt1[1] and wt1[1] <= wt1[2] then currentLow else Double.NaN;

# +---------------------+
# | ESTABLISH THE DOTS |
# +---------------------+

rec PHBar = if UserSetResistance then TrendResistanceEnd else if !IsNaN(PH) then currentBar else PHBar[1];
rec PLBar = if UserSetSupport then TrendSupportEnd else if !IsNaN(PL) then currentBar else PLBar[1];
rec PHL = if !IsNaN(PH) then PH else PHL[1];
rec priorPHBar = if UserSetResistance then TrendResistanceStart else if PHL != PHL[1] then PHBar[1] else priorPHBar[1];
rec PLL = if !IsNaN(PL) then PL else PLL[1];
rec priorPLBar = if UserSetSupport then TrendSupportStart else if PLL != PLL[1] then PLBar[1] else priorPLBar[1];
def isFinalTwoHighPivots = currentBar >= HighestAll(priorPHBar);
def isFinalTwoLowPivots = currentBar >= HighestAll(priorPLBar);
def ResistanceFinishOffset = if isFinalTwoHighPivots then currentBar - PHBar else 0;
def ResistanceStartOffset = if isFinalTwoHighPivots then currentBar - priorPHBar else 0;
def ResistanceSlope = (GetValue(PH, ResistanceFinishOffset) - GetValue(PH, ResistanceStartOffset)) / (PHBar - priorPHBar);
def SupportFinishOffset = if isFinalTwoLowPivots then currentBar - PLBar else 0;
def SupportStartOffset = if isFinalTwoLowPivots then currentBar - priorPLBar else 0;
def SupportSlope = (GetValue(PL, SupportFinishOffset) - GetValue(PL, SupportStartOffset)) / (PLBar - priorPLBar);
rec ResistanceExtend = if currentBar == HighestAll(PHBar) then 1 else ResistanceExtend[1];
rec SupportExtend = if currentBar == HighestAll(PLBar) then 1 else SupportExtend[1];

def pivotHigh = if
PH > 0 then PH else Double.NaN;

def pivotLow = if
PL > 0 then PL else Double.NaN;


# +---------------------+
# | CONNECT THE DOTS |
# +---------------------+

script Line {
    input v = 0; #value
    input s = 0; #start
    input e = 0; #end
    input xl = 0; #extend left
    input xr = Double.POSITIVE_INFINITY; #extend right
    def bn = BarNumber();
    def lastBar = HighestAll(if IsNaN(close) then 0 else bn);
    def x1 = Min(s, e);
    def x2 = Max(s, e);
    def y1 = GetValue(v, bn - x1);
    def y2 = GetValue(v, bn - x2);
    def m = (y2 - y1) / (x2 - x1);
    def x = bn - x1;
    def b = y1;
    plot return = if bn < (x1 - xl) or bn > (x2 + xr) then Double.NaN else m * x + b;
}
def bn = BarNumber();
def prevPH = if !IsNaN(PH[1]) then high else prevPH[1];
def prevBh = if !IsNaN(PH[1]) then bn[1] else prevBh[1];
def prevPL = if !IsNaN(PL[1]) then low else prevPL[1];
def prevBl = if !IsNaN(PL[1]) then bn[1] else prevBl[1];
def rEnd = HighestAll(if !IsNaN(PH) and high < prevPH then bn else 0);
def rStart = HighestAll(if bn == rEnd then prevBh else 0);
def sEnd = HighestAll(if !IsNaN(PL) and low > prevPL then bn else 0);
def sStart = HighestAll(if bn == sEnd then prevBl else 0);

plot resistance = line(high, rStart, rEnd);
resistance.SetDefaultColor(CreateColor( 255, 126, 156));
resistance.SetLineWeight(3);

plot support = line(low, sStart, sEnd);
support.SetDefaultColor(CreateColor( 51, 255, 51));
support.SetLineWeight(3);

#################################################
def g  = if green != green[1] then wt1 else g[1];
def gg = if g != g[1] then BarNumber() else Double.NaN;
def r  = if red != red[1] then wt1 else r[1];
def rr = if r != r[1] then BarNumber() else Double.NaN;

def pivotbar = if BarNumber() == HighestAll(gg - 1)
               then wt1
               else if BarNumber() == HighestAll(rr - 1)
               then wt1
               else Double.NaN;

plot xdot = pivotbar;
xdot.EnableApproximation();
xdot.setdefaultColor(color.white);
xdot.setlineWeight(5);
##################################################
 
Hi all,

Here is my take on the Wave Trend Oscillator, built off of the backbones of the LazyBear oscillator -- I found some inspiration from a different wave oscillator on tradingview by Zeiierman, though I wasn't able to figure out everything that was included there: https://www.tradingview.com/script/fIUTPDOD-WaveTrend-Momentum-Expo/

I've defaulted to the settings that I prefer for the best signals on the 3-minute time frame, and included both impulse moves (when the signal strongly crosses into overbought/oversold) as well as divergences.

lTnlw0b.png


This version of the oscillator shows pushes into heavier buying/selling, as well as divergences and the option to adjust the moving average inputs for finer tuning of buy/sell signals. If anyone else sees further ways to improve this, feel free!

Code:
## Wave Oscillator inspired by LazyBear and Zeiierman on TradingView
## Ported over by Chemmy for usethinkscript.com

declare lower;
input Channel_Length = 21; #10
input Average_Length = 35; #10
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;
input show_bubbles = yes;
input show_sec_bbls = no;
input show_alerts = yes;
input show_lines = no;
input term = 60;
input calcavgtype = averagetype.EXPONENTIAL;
input band_avgtype = averagetype.WILDERS;
input showdiv = Yes;
input show_impulse = Yes;

def ap = hlc3;
def esa = MovingAverage(calcavgtype, ap, Channel_Length);
def d = MovingAverage(calcavgtype, AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = MovingAverage(calcavgtype, ci, Average_Length);
def wt1 = tci;
def wt2 = MovingAverage(band_avgtype, wt1, 4);
#def zero = 0;
plot zero = 0;
zero.SetDefaultColor( Color.GRAY );
#plot obLevel1 = over_bought_1;
#obLevel1.SetDefaultColor(Color.RED);
#plot osLevel1 = over_sold_1;
#osLevel1.SetDefaultColor(Color.GREEN);
#plot  obLevel2 = over_bought_2;
#obLevel2.SetDefaultColor(Color.RED);
#obLevel2.SetStyle(Curve.SHORT_DASH);
#plot  osLevel2 = over_sold_2;
#osLevel2.SetDefaultColor(Color.GREEN);
#osLevel2.SetStyle(Curve.SHORT_DASH);

plot wt1_1 = wt1;
wt1_1.SetDefaultColor(Color.GREEN);
wt1_1.SetHiding(!show_lines);

plot wt2_1 = wt2;
wt2_1.SetDefaultColor(Color.RED);
wt2_1.SetStyle(Curve.POINTS);
wt2_1.SetHiding(!show_lines);

plot wt3 = (wt1 - wt2);
wt3.AssignValueColor(if wt3>0 and wt3>wt3[1] then color.Green else if wt3>0 and wt3 <= wt3[1] then color.dark_green
            else if wt3<0 and wt3<wt3[1] then color.Red else if wt3<0 and wt3>=wt3[1] then color.dark_red else color.Gray);
wt3.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

def dyna1 = highest(wt3, term);
def dyna2 = lowest(wt3, term);

plot dynaup = dyna1;
plot dynadn = dyna2;

def signal1 = wt1 crosses above wt2 and wt1 < over_sold_2;
plot Signal = if signal1  then (signal1 * dyna2) else Double.NaN;
Signal.SetDefaultColor(Color.GREEN);
Signal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal.SetLineWeight(3);
Signal.HideTitle();
def signal2 = wt1 crosses below wt2 and wt1 > over_bought_2;
plot Signal2_ = if signal2  then (signal2 * dyna1) else Double.NaN;
Signal2_.SetDefaultColor(Color.RED);
Signal2_.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal2_.SetLineWeight(3);
Signal2_.HideTitle();

def impdown = wt1 crosses below dynadn;
plot impulsedn = if impdown then wt3 else double.NaN;
impulsedn.SetPaintingStrategy(PaintingStrategy.Points);
impulsedn.SetDefaultColor(color.Red);
impulsedn.setlineweight(3);
impulsedn.SetHiding(!show_impulse);

def impup = wt1 crosses below dynadn;
plot impulseup = if impup then wt3 else double.NaN;
impulseup.SetPaintingStrategy(PaintingStrategy.Points);
impulseup.SetDefaultColor(color.Green);
impulseup.setlineweight(3);
impulseup.SetHiding(!show_impulse);

## Divergence Sections
##### DIVERGANCE
def bar = BarNumber();
def n = channel_Length;
def CurrH = if wt1 > dynaup
                then fold i = 1 to Floor(n / 2)
                with p = 1
                while p
                do wt1 > GetValue(wt1, -i)
                else 0;

def CurrPivotH = if (bar > n and
                         wt1 == Highest(wt1, Floor(n / 2)) and CurrH) then wt3 else double.NaN;

def CurrL = if wt1 < dynadn
                then fold j = 1 to Floor(n / 2)
                with q = 1
                while q
                do wt1 < GetValue(wt1, -j)
                else 0;

def CurrPivotL =  if (bar > n and
                         wt1 == Lowest(wt1, Floor(n / 2)) and CurrL) then wt3 else double.NaN;

def CurrPHBar = if !IsNaN(CurrPivotH) then bar else CurrPHBar[1];
def CurrPLBar = if !IsNaN(CurrPivotL) then bar else CurrPLBar[1];

def PHpoint = if !IsNaN(CurrPivotH) then CurrPivotH else PHpoint[1];
def PLpoint = if !IsNaN(CurrPivotL) then CurrPivotL else PLpoint[1];

def priorPHBar = if PHpoint != PHpoint[1] then CurrPHBar[1] else priorPHBar[1];
def priorPLBar = if PLpoint != PLpoint[1] then CurrPLBar[1] else priorPLBar[1];

def HighPivots = bar >= HighestAll(priorPHBar);
def LowPivots  = bar >= HighestAll(priorPLBar);

def pivotHigh = if HighPivots then CurrPivotH else double.Nan;
def pivotLow  = if LowPivots  then CurrPivotL else double.Nan;

plot PlotHline = pivotHigh;
PlotHline.EnableApproximation();
PlotHline.SetDefaultColor(Color.RED);
PlotHline.SetStyle(Curve.SHORT_DASH);
PlotHline.SetHiding(!ShowDiv);

plot PlotLline = pivotLow;
PlotLline.EnableApproximation();
PlotLline.SetDefaultColor(Color.LIME);
PlotLline.SetStyle(Curve.SHORT_DASH);
PlotLline.SetHiding(!ShowDiv);

plot PivotDot = if !IsNaN(pivotHigh) then pivotHigh else
                if !IsNaN(pivotLow)  then pivotLow  else double.NaN;
PivotDot.SetDefaultColor(Color.YELLOW);
PivotDot.SetPaintingStrategy(PaintingStrategy.POINTS);
PivotDot.SetLineWeight(3);
PivotDot.SetHiding(!ShowDiv);
 
Just wanting wt1_1 to show red when below 0 and green when over 0. Thank you in advance!


#WT_LB Short Name TV
declare lower;
input Channel_Length = 10;
input Average_Length = 21;
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;
input show_bubbles = yes;
input show_sec_bbls = no;
input show_alerts = yes;
def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, Average_Length);
def wt1 = tci;
def wt2 = SimpleMovingAvg(wt1, 4);
#def zero = 0;
plot zero = 0;
zero.SetDefaultColor( Color.GRAY );
plot obLevel1 = over_bought_1;
obLevel1.SetDefaultColor(Color.RED);
plot osLevel1 = over_sold_1;
osLevel1.SetDefaultColor(Color.GREEN);
plot obLevel2 = over_bought_2;
obLevel2.SetDefaultColor(Color.RED);
obLevel2.SetStyle(Curve.SHORT_DASH);
plot osLevel2 = over_sold_2;
osLevel2.SetDefaultColor(Color.GREEN);
osLevel2.SetStyle(Curve.SHORT_DASH);

plot wt1_1 = wt1;
wt1_1.SetDefaultColor(Color.GREEN);
plot wt2_1 = wt2;
wt2_1.SetDefaultColor(Color.RED);
wt2_1.SetStyle(Curve.POINTS);
plot wt3 = (wt1 - wt2);
wt3.SetDefaultColor(Color.BLUE);
wt3.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
def signal1 = wt1 crosses above wt2 and wt1 < over_sold_2;
plot Signal = if signal1 then (signal1 * over_sold_2) else Double.NaN;
Signal.SetDefaultColor(Color.GREEN);
Signal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
Signal.SetLineWeight(3);
Signal.HideTitle();
def signal2 = wt1 crosses below wt2 and wt1 > over_bought_2;
plot Signal2_ = if signal2 then (signal2 * over_bought_2) else Double.NaN;
Signal2_.SetDefaultColor(Color.RED);
Signal2_.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Signal2_.SetLineWeight(3);
Signal2_.HideTitle();

AddVerticalLine(crosses (wt1_1[1], 0, CrossingDirection.ABOVE), "Long", Color.green, 3);
AddVerticalLine(crosses (wt1_1[1], 0, CrossingDirection.BELOW), "Short", Color.red, 3);
 
Just wanting wt1_1 to show red when below 0 and green when over 0. Thank you in advance!

Shared Watchlist link: http://tos.mx/EZE4cvM Click here for --> Easiest way to load shared links
88ZnFcb.png

Ruby:
input Channel_Length = 10; #10
input Average_Length = 21; #10
input over_bought_1 = 60;
input over_bought_2 = 53;
input over_sold_1 = -60;
input over_sold_2 = -53;

def ap = hlc3;
def esa = ExpAverage(ap, Channel_Length);
def d = ExpAverage(AbsValue(ap - esa), Channel_Length);
def ci = (ap - esa) / (0.015 * d);
plot tci = ExpAverage(ci, Average_Length);

AssignBackgroundColor(
if tci>0 then color.green else color.red);
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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