Help with Creating a Scan

kmercurio

New member
VIP
Below I've attached the user's Chemmy's code
https://usethinkscript.com/threads/...r-thinkorswim-lazybear.233/page-4#post-110687
for his version of the Wave Trend oscillator. All credit goes towards him for creating it. One of the features of this indicator is that a yellow dot will appear when a divergence occurs. I'd like the scan for what this yellow divergence dot appears. I've been struggling to make a scan out of it. Thanks in advance, and the code is posted below.

## 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);
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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