TrendFusion for Thinkorswim

chewie76

Well-known member
VIP
VIP Enthusiast
I added another moving average and ATR based bands to the TrendFusion indicator. There are trade signals if you turn them on. Default averages are 35 and 63, but feel free to change them to your favorite averages. The bands are based on the "maPeriod" average. Trade signals can also be adjusted by changing the dmiPeriod and adx levels. You can view long and short signals, or just turn on long or short in the settings under "tradeType". This is a good trend indicator that also gives you good areas where price could be extended. Here is a picture of /GC on the four hour chart.

1756864328490.png



Code:
# TrendFusion with Bands (ThinkScript Conversion)
# Assembled by Chewie 9/1/2025


declare upper;

#----------------------------
# Inputs
#----------------------------
input colorbar = yes;
input showsignals = no;
input bands = yes;
input maPeriod = 35;
input maPeriod2 = 63;
input maType = {default EMA, SMA, WMA, ZLEMA, LinReg};
input dmiPeriod = 7;
input adxSmoothing = 14;
input adxTrendLevel = 21;
input tradeType = {default LongAndShort, Long, Short};


#----------------------------
# Functions
#----------------------------
script ZLEMA {
    input price = close;
    input length = 35;
    def lag = (length - 1) / 2;
    def emaData = price + price - price[lag];
    plot out = ExpAverage(emaData, length);
}

def ma;
switch (maType) {
case SMA:
    ma = Average(close, maPeriod);
case EMA:
    ma = ExpAverage(close, maPeriod);
case WMA:
    ma = WMA(close, maPeriod);
case ZLEMA:
    ma = ZLEMA(close, maPeriod);
case LinReg:
    ma = Inertia(close, maPeriod);
}

def ma2;
switch (maType) {
case SMA:
    ma2 = Average(close, maPeriod2);
case EMA:
    ma2 = ExpAverage(close, maPeriod2);
case WMA:
    ma2 = WMA(close, maPeriod2);
case ZLEMA:
    ma2 = ZLEMA(close, maPeriod2);
case LinReg:
    ma2 = Inertia(close, maPeriod2);
}

# DMI & ADX
def diPlus = DIPlus(dmiPeriod);
def diMinus = DIMinus(dmiPeriod);
def adx = ADX(adxSmoothing);

# Trend Conditions
def trendUp = adx > adxTrendLevel and diPlus > diMinus and ma > ma[1];
def trendDown = adx > adxTrendLevel and diPlus < diMinus and ma < ma[1];

#----------------------------
# Signals
#----------------------------
def isLong = trendUp and !trendUp[1] and tradeType != tradeType.Short;
def isShort = trendDown and !trendDown[1] and tradeType != tradeType.Long;
def isExitLong = trendUp[1] and !trendUp and tradeType != tradeType.Short;
def isExitShort = trendDown[1] and !trendDown and tradeType != tradeType.Long;

#----------------------------
# Plotting
#----------------------------


plot MAline = ma;
maline.setlineWeight(2);
maline.assignvalueColor(if close > maline then color.green else color.red);
plot MAline2 = ma2;
maline2.setlineWeight(2);
maline2.assignvalueColor(if close > maline2 then color.green else color.red);

AddCloud(ma2, ma, Color.DARK_RED, Color.CURRENT);
AddCloud(ma, ma2, Color.DARK_GREEN, Color.CURRENT);

plot long = if showsignals then islong else double.nan;
long.SetDefaultColor(Color.CYAN);
long.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_UP);

plot longE = if showsignals and isExitLong then high + ATR(60) / 2  else Double.NaN;;
longE.SetDefaultColor(Color.CYAN);
longE.SetPaintingStrategy(PaintingStrategy.POINTS);

plot short = if showsignals then isshort else double.nan;
short.SetDefaultColor(Color.magenta);
short.SetPaintingStrategy(PaintingStrategy.boolean_ARROW_down);

plot shortE = if showsignals and isExitShort then low - ATR(60) / 2  else Double.NaN;
shortE.SetDefaultColor(Color.magenta);
shortE.SetPaintingStrategy(PaintingStrategy.POINTS);


#Bands

input atrMultiplier1 = 2;
input atrMultiplier2 = 4;

input atrLength = 200; 
def source = FundamentalType.CLOSE;
def src = Fundamental(source);
def ATR = atr(Length = ATRlength);

def emaup    = MAline + (ATR*atrMultiplier1);
def emadw    = MAline - (ATR*atrMultiplier1);
def emaup2   = MAline + (ATR*atrMultiplier2);
def emadw2   = MAline - (ATR*atrMultiplier2);

plot Up = if bands then emaup else Double.NaN; 
plot Dn = if bands then emadw else Double.NaN; 
plot Up2 = if bands then emaup2 else Double.NaN; 
plot Dn2 = if bands then emadw2 else Double.NaN; 

up.setdefaultColor(color.dark_orange);
up2.setdefaultColor(color.magenta);
dn.setdefaultColor(color.light_green);
dn2.setdefaultColor(color.cyan);

AssignPriceColor(if colorbar and close >up2 then color.magenta else if close < dn2 then color.cyan else if close > maline2 then Color.GREEN else if close < maline2 then color.red else Color.current);
 

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