WaveTrend Overlay For ThinkOrSwim

TRADERSAM

Active member
VIP
Author states: ScalpingTrend Buy/Sell is a simple and effective buy/sell indicator that works directly on the price chart. It is based on the classic WaveTrend oscillator and focuses solely on buy/sell signals.

afEi1q2.png


Been really busy lately, but finally had time to sit down and code a bit. I've been having fun converting indicators from TradingView to Thinkorswim, and it's been a great way to learn the fundamentals of coding along the way. Found this indicator and thought it looked pretty simple, so I took a shot at converting it and I think it came out pretty well. If you spot anything I could improve, feel free to let me know. Always learning!

Here’s the original script (some variable names were tough to translate since they weren’t in English 😂)
https://www.tradingview.com/script/CxjCOZub/

Here is my code:
Ruby:
#indicator(title="WaveTrend Overlay Al/Sat", shorttitle="WT_Overlay", overlay=true)

input n1 = 10;
input n2 = 21;
input reaction_wt = 1;
input only_sells_when_overbought = yes;
input only_buys_when_oversold = yes;
input nsc = 53;
input nsv = -53;

# === WaveTrend ===
def ap = hlc3;
def esa = expaverage(ap, n1);
def d = expaverage(absvalue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * d);
def tci = expaverage(ci, n2);

def wt1 = tci;
def wt2 = simplemovingavg(ci, n2);

# === Buy/Sell Signals ===
def sell = wt1 crosses below wt2 and wt1 >= nsc and only_sells_when_overbought;
def sell_1 = wt1 crosses below wt2 and !only_sells_when_overbought;

def buy = wt1 crosses above wt2 and wt1 <= nsv and  only_buys_when_oversold;
def buy_1 = wt1 crosses above wt2 and wt1 <= nsv and !only_buys_when_oversold;

assignpriceColor(if buy or buy_1 then color.green else if sell or sell_1 then color.red else color.current);

plot buyPlot = if buy or buy_1 then low else double.nan;
plot sellPlot = if sell or sell_1 then high else double.nan;

buyplot.setpaintingStrategy(paintingStrategy.BOOLEAN_arrow_up);
sellplot.setpaintingStrategy(paintingStrategy.BOOLEAN_arrow_down);

buyplot.setdefaultcolor(createcolor(57, 255, 20));
sellplot.setdefaultcolor(createcolor(255, 30, 60));

buyplot.setlineWeight(2);
sellplot.setlineWeight(2);
 
Last edited by a moderator:
Author states: ScalpingTrend Buy/Sell is a simple and effective buy/sell indicator that works directly on the price chart. It is based on the classic WaveTrend oscillator and focuses solely on buy/sell signals.

afEi1q2.png


Been really busy lately, but finally had time to sit down and code a bit. I've been having fun converting indicators from TradingView to Thinkorswim, and it's been a great way to learn the fundamentals of coding along the way. Found this indicator and thought it looked pretty simple, so I took a shot at converting it and I think it came out pretty well. If you spot anything I could improve, feel free to let me know. Always learning!

Here’s the original script (some variable names were tough to translate since they weren’t in English 😂)
https://www.tradingview.com/script/CxjCOZub/

Here is my code:
Ruby:
#indicator(title="WaveTrend Overlay Al/Sat", shorttitle="WT_Overlay", overlay=true)

input n1 = 10;
input n2 = 21;
input reaction_wt = 1;
input only_sells_when_overbought = yes;
input only_buys_when_oversold = yes;
input nsc = 53;
input nsv = -53;

# === WaveTrend ===
def ap = hlc3;
def esa = expaverage(ap, n1);
def d = expaverage(absvalue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * d);
def tci = expaverage(ci, n2);

def wt1 = tci;
def wt2 = simplemovingavg(ci, n2);

# === Buy/Sell Signals ===
def sell = wt1 crosses below wt2 and wt1 >= nsc and only_sells_when_overbought;
def sell_1 = wt1 crosses below wt2 and !only_sells_when_overbought;

def buy = wt1 crosses above wt2 and wt1 <= nsv and  only_buys_when_oversold;
def buy_1 = wt1 crosses above wt2 and wt1 <= nsv and !only_buys_when_oversold;

assignpriceColor(if buy or buy_1 then color.green else if sell or sell_1 then color.red else color.current);

plot buyPlot = if buy or buy_1 then low else double.nan;
plot sellPlot = if sell or sell_1 then high else double.nan;

buyplot.setpaintingStrategy(paintingStrategy.BOOLEAN_arrow_up);
sellplot.setpaintingStrategy(paintingStrategy.BOOLEAN_arrow_down);

buyplot.setdefaultcolor(createcolor(57, 255, 20));
sellplot.setdefaultcolor(createcolor(255, 30, 60));

buyplot.setlineWeight(2);
sellplot.setlineWeight(2);
YES alot going on behind the scenes that maybe needs to have some light shed on it - validation is good but may need volume and momentums added - I created a lower trend plotting the wt1 and wt2 so you can visualize every crossing and not just the oversold and overbought higher ranges but everytime.

1762575600733.png


The Core Logic WaveTrend Lower

ConceptWhat It MeansTypical Action
WT1 crosses above WT2Bullish momentum turning upPossible Buy signal
WT1 crosses below WT2Bearish momentum turning downPossible Sell signal
WT1 > +53Market is overboughtAvoid new longs, watch for reversal
WT1 < –53Market is oversoldAvoid new shorts, look for bottom reversal
WT1 & WT2 moving in same directionTrend continuationHold position, avoid counter-trend trades
https://tos.mx/!PCSa7t7d
Code:
# ===============================
# WaveTrend Oscillator (Lower Study)
# Companion to WaveTrend Overlay
# v.1 antwerks 11/07/2025
# ===============================

declare lower;

input n1 = 10;
input n2 = 21;
input nsc = 53;   # Overbought threshold
input nsv = -53;  # Oversold threshold

# === Core WaveTrend Calculation ===
def ap = hlc3;
def esa = ExpAverage(ap, n1);
def d = ExpAverage(AbsValue(ap - esa), n1);
def ci = (ap - esa) / (0.015 * d);
def tci = ExpAverage(ci, n2);

def wt1 = tci;
def wt2 = SimpleMovingAvg(ci, n2);

# === Plot the Oscillator Lines ===
plot PlotWT1 = wt1;
plot PlotWT2 = wt2;

PlotWT1.SetDefaultColor(Color.CYAN);
PlotWT2.SetDefaultColor(Color.MAGENTA);
PlotWT1.SetLineWeight(2);
PlotWT2.SetLineWeight(1);

# === Overbought / Oversold Levels ===
plot OverBought = nsc;
plot OverSold = nsv;
plot ZeroLine = 0;

OverBought.SetDefaultColor(Color.DARK_RED);
OverSold.SetDefaultColor(Color.DARK_GREEN);
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);

# === Background Clouds ===
AddCloud(PlotWT1, PlotWT2, Color.LIGHT_GRAY, Color.CURRENT);
AddCloud(if wt1 > nsc then wt1 else Double.NaN, nsc, Color.RED, Color.CURRENT);
AddCloud(if wt1 < nsv then wt1 else Double.NaN, nsv, Color.GREEN, Color.CURRENT);

# === Crossover Signals on Oscillator ===
plot BullCross = if wt1 crosses above wt2 then wt1 else Double.NaN;
plot BearCross = if wt1 crosses below wt2 then wt1 else Double.NaN;

BullCross.SetPaintingStrategy(PaintingStrategy.POINTS);
BearCross.SetPaintingStrategy(PaintingStrategy.POINTS);
BullCross.SetDefaultColor(Color.GREEN);
BearCross.SetDefaultColor(Color.RED);
BullCross.SetLineWeight(3);
BearCross.SetLineWeight(3);

# === Labels ===
def wt1Up = wt1 > wt1[1];
def wt1Down = wt1 < wt1[1];
AddLabel(
    yes,
    "WT1: " + Round(wt1, 1) + " | WT2: " + Round(wt2, 1) + " | " +
    (if wt1Up then "Rising" else if wt1Down then "Falling" else "Flat"),
    if wt1 > nsc then Color.RED
    else if wt1 < nsv then Color.GREEN
    else if wt1Up then Color.LIGHT_GREEN
    else if wt1Down then Color.PINK
    else Color.GRAY
);
 
Last edited by a moderator:

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