Trend Magic MultiTime Frame Indicator for ThinkorSwim

For those interested here is v1.2 of the Trend Magic MTF, converted to a lower study with triangles
I have configured this for 15 min, 30 min and 1HOUR so run this at 15 min aggregation or lower.
Time frames are user selectable via the user interface

Code:
# Trend Magic MTF
# tomsk
# 11.26.2019

# V1.0 - 08.08.2019 - Horserider - Added MTF to Trend Magic
# V1.1 - 11.26.2019 - tomsk      - Optimized code structure, removed duplicate variables
# V1.2 - 11.26.2019 - tomsk      - Converted this study to a lower study with MTF triangles

declare lower;

# GLOBAL DEFINITIONS

DefineGlobalColor("TrendUp", CreateColor(0, 254, 30));
DefineGlobalColor("TrendDown", CreateColor(255, 3, 2));

input agg = AggregationPeriod.FIFTEEN_MIN;
input agg2 = AggregationPeriod.THIRTY_MIN;
input agg3 = AggregationPeriod.HOUR;

input lengthCCI = 50;
input lengthATR = 5;
input AtrFactor = 0.7;

input DotSize = 3;
input n = 3;

def n1  = n + 1;

# AGGREGATION 1

def c = close(period = agg);
def h = high(period = agg);
def l = low(period = agg);
def pricedata = HL2(period = agg);
def ATRcci = Average(TrueRange(h, c, l), lengthATR) * AtrFactor;
def price = c + l + h;
def linDev = lindev(price, lengthCCI);
def CCI = if lindev == 0 then 0 else (price - Average(price, lengthCCI)) / linDev / 0.015;
def MT1 = if CCI > 0
          then Max(MT1[1], pricedata - ATRcci)
          else Min(MT1[1], pricedata + ATRcci);
plot MT1_Dot = if IsNaN(close) then Double.NaN else 1;
MT1_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MT1_Dot.SetLineWeight(DotSize);
MT1_Dot.AssignValueColor(if c < MT1 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), 1, (agg/1000/60) + " min", Color.Yellow, yes);

# AGGREGATION 2

def c2 = close(period = agg2);
def h2 = high(period = agg2);
def l2 = low(period = agg2);
def pricedata2 = HL2(period = agg2);
def ATRcci2 = Average(TrueRange(h2, c2, l2), lengthATR) * AtrFactor;
def price2 = c2 + l2 + h2;
def linDev2 = lindev(price2, lengthCCI);
def CCI2 = if linDev2 == 0 then 0 else (price2 - Average(price2, lengthCCI)) / linDev2 / 0.015;
def MT2 = if CCI2 > 0
          then Max(MT2[1], pricedata2 - ATRcci2)
          else Min(MT2[1], pricedata2 + ATRcci2);
plot MT2_Dot = if IsNaN(close) then Double.NaN else 2;
MT2_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MT2_Dot.SetLineWeight(DotSize);
MT2_Dot.AssignValueColor(if c2 < MT2 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), 2, (agg2/1000/60) + " min", Color.Yellow, yes);

# AGGREGATION 3

def c3 = close(period = agg3);
def h3 = high(period = agg3);
def l3 = low(period = agg3);
def pricedata3 = HL2(period = agg3);

def ATRcci3 = Average(TrueRange(h3, c3, l3), lengthATR) * AtrFactor;
def price3 = c3 + l3 + h3;
def linDev3 = lindev(price3, lengthCCI);
def CCI3 = if linDev3 == 0 then 0 else (price3 - Average(price3, lengthCCI)) / linDev3 / 0.015;
def MT3 = if CCI3 > 0
          then Max(MT3[1], pricedata3 - ATRcci3)
          else Min(MT3[1], pricedata3 + ATRcci3);
plot MT3_Dot = if IsNaN(close) then Double.NaN else 3;
MT3_Dot.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
MT3_Dot.SetLineWeight(DotSize);
MT3_Dot.AssignValueColor(if c3 < MT3 then GlobalColor("TrendDown") else GlobalColor("TrendUp"));
AddChartBubble(!IsNaN(close[n1]) and IsNaN(close[n]), 3, (agg3/1000/60) + " min", Color.Yellow, yes);
# End Trend Magic MTF
[
[/QUOTE]

@tomsk thank for you this amazing indicator with the enhancements. I am using tick and Range charts in ThinkorSwim for ES futures. I see that this indicator only works with time based charts. So is it possible for this indicator to plot based on 3min, 5min and 15 min while my current chart is on Tick or Range charts.

Please do let me know.

Thanks in advance.


@tomsk thanks for the indicator, Since I am using Tick & Range charts I understand this indicator will not work on my current chart. but is it possible to create labels for the 3min, 5min and 15 min of this indicator with the same coloring of Green for Bullish and Red for Bearish, So I can use these labels as indicator on my Tick or Range charts. this would be really helpful. thanks in advance.
 
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
350 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