WaveTrend Oscillator for ThinkorSwim [LazyBear]

Can someone please help create two Thinkscript scanners based on this WaveTrend Oscillator from LazyBear?
Buy Signal Scanner 1: Scan for stocks where the WT1 (Green Line) just crossed ABOVE the WT2 (Red Dotted Line) for the FIRST time while both lines are BELOW minus 20 (-20)

Sell Signal Scanner 2: Scan for stocks where the WT1 (Green Line) just crossed UNDER the WT2 (Red Dotted Line) for the FIRST time while both lines are ABOVE 20
It should be The "first time in the last 3 bars"


add this code snippet to the bottom of your study:
def BuySig = wt1_1<-20 and wt2_1<-20 and wt1_1 crosses above wt2_1;
plot BuySigScan = !BuySig[1] and !BuySig[2] and BuySig; BuySigScan.hide();

def SellSig = wt1_1>20 and wt2_1>20 and wt1_1 crosses below wt2_1;
plot SellSigScan = !SellSig[1] and !SellSig[2] and SellSig; SellSigScan.hide();

Your scan filter will be:
BuySigScan is true
or
SellSigScan is true

Here is a tutorial for adding scan filters to the Scan Hacker:
https://usethinkscript.com/threads/how-to-use-thinkorswim-stock-hacker-scans.284/
 
Last edited:
This is one of my first attempts at converting a Pine Script indicator into ThinkScript, and I wanted to start with something relatively simple to get the hang of it. I’ve always been interested in how indicators work under the hood, and working through the conversion process has been a great way to learn. Converting scripts really interests me, and I plan to keep practicing so I can improve my skills and eventually tackle more complex projects.

The original author of this script states:
WaveTrend Oscillator is a port of a famous TS/MT indicator.
When the Oscillator(Cyan line) is above the overbought band (red lines) and crosses down the signal (Yellow dotted line), it is usually a good SELL signal. Similarly, when the oscillator crosses above the signal when below the Oversold band (green lines), it is a good BUY signal.
Ruby:
# -----------------------
# WaveTrend Indicator by LazyBear
# Converted by TraderSam
# 08/30/25
# -----------------------

declare lower;

# === Inputs ===
input EMALength1 = 10;
input EMALength2 = 21;
input wt2Length = 4;
input oblevel1 = 60;
input oblevel2 = 53;
input oslevel1 = -60;
input oslevel2 = -53;
input showcloud = yes;
input showHistogram = no;

# === Basic Calculations ===
def AP = (high + low + close) / 3;  #HLC3
def EMA = Expaverage(ap, emalength1);
def dEMA = Expaverage(absValue(ap - EMA), EmaLength1);
def ci = (ap - ema) / (0.015 * dEMA);
def tci = expAverage(ci, emaLength2);

def wt1 = tci;
def wt2 = simpleMovingAvg(tci, wt2Length);
def diff = wt1 - wt2;

# === Plots ===
plot Zeroline = 0;
zeroline.setDefaultColor(color.gray);
zeroline.setLineWeight(3);

plot OB1 = oblevel1;
ob1.setDefaultColor(color.red);
ob1.setLineWeight(2);

plot ob2 = oblevel2;
ob2.setdefaultColor(color.red);
ob2.setStyle(curve.short_dash);
ob2.setlineWeight(1);

plot os1 = oslevel1;
os1.setdefaultColor(color.green);
os1.setlineWeight(2);

plot os2 = oslevel2;
os2.setDefaultColor(color.green);
os2.setStyle(curve.short_dash);
os2.setLineWeight(1);

plot wavetrend = wt1;
wavetrend.setdefaultColor(color.cyan);
wavetrend.setLineWeight(2);

plot signal = wt2;
signal.setdefaultcolor(color.yellow);
signal.setStyle(curve.short_dash);
signal.setlineweight(1);

# === clouds ===
AddCloud(if showCloud then wt1 else Double.NaN, if showCloud then wt2 else Double.NaN, CreateColor(80,140,255));

# === optional histogram ===
plot Histogram = if showHistogram then diff else Double.NaN;
Histogram.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Histogram.SetDefaultColor(Color.BLUE);
Histogram.SetLineWeight(2);
 

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
1108 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