Help with Creating a Scan


New member
Below I've attached the user's Chemmy's code
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

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;
#plot osLevel1 = over_sold_1;
#plot obLevel2 = over_bought_2;
#plot osLevel2 = over_sold_2;

plot wt1_1 = wt1;

plot wt2_1 = wt2;

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

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;
def signal2 = wt1 crosses below wt2 and wt1 > over_bought_2;
plot Signal2_ = if signal2 then (signal2 * dyna1) else Double.NaN;

def impdown = wt1 crosses below dynadn;
plot impulsedn = if impdown then wt3 else double.NaN;

def impup = wt1 crosses below dynadn;
plot impulseup = if impup then wt3 else double.NaN;

## Divergence Sections
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;

plot PlotLline = pivotLow;

plot PivotDot = if !IsNaN(pivotHigh) then pivotHigh else
if !IsNaN(pivotLow) then pivotLow else double.NaN;
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.