Trend Magic MultiTime Frame Indicator for ThinkorSwim

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@shizah Hmmm maybe. Not sure. Not a fan of alerts so not good at creating them. Not tested. So let us know if they work.

Try something like these.

# Three plots agree Red and Green
Alert(c < MT1 and c2 < MT2 and c3 < MT3,"", Alert.BAR, Sound.Chimes);
Alert (c > MT1 and c2 > MT2 and c3 > MT3,"", Alert.BAR, Sound.Chimes);

# Individual plots turn red or green
Alert(c < MT1, "", Alert.BAR, Sound.Bell);
Alert(c2 < MT2,"", Alert.BAR, Sound.Bell);
Alert(c3 < MT3,"", Alert.BAR, Sound.Bell);
Alert(c > MT1,"", Alert.BAR, Sound.Bell);
Alert(c2 > MT2,"", Alert.BAR, Sound.Bell);
Alert(c3 > MT3,"", Alert.BAR, Sound.Bell);
 
Great idea. For some reason though this family of indicators ( based on CCI+ATR with MTF) are not working on my daily chart with weekly/monhtly secondary aggregations. HMMM
 
@skynetgen Worked for me. Daily chart with 3 day, wk, month

RlurKlH.png
 

Attachments

  • RlurKlH.png
    RlurKlH.png
    188.8 KB · Views: 267
@horserider Is there a way that to make the Trend Magic indicator be part of the lower study and have the lines transformed into dots that are symmetrically spaced? Please refer to the pic.

I was able to set the Trend Magic indicator as a lower study...and I switched from a line to dots...but the dots are all out of whack as they still seem to be following the candle trend in the upper study. I want them to look exactly as the Mobius SuperTrend just below...

Since you did enhanced this indicator would you be willing to do what I requested above?

Its a really good indicator but I don't want it to clutter the upper study with all 3 aggregations running...IF you could do this that would be awesome...

 
Folks, I took a look at post #1 of the Trend Magic MTF study that was posted in August. It appears that several variables have identical values and can be combined.

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

input lengthCCI2 = 50;
input lengthATR2 = 5;
input AtrFactor2 = 0.7;

input lengthCCI3 = 50;
input lengthATR3 = 5;
input AtrFactor3 = 0.7;

Additionally I noticed several repetitions of the following code

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

I cleaned up the code, essentially it functions exactly the same as before but now is code optimized
Additionally I moved the definition of the different aggregation TF to the globals section for easier accessibility

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

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

# 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 data1 = MT1;
data1.AssignValueColor(if c < MT1 then Color.RED else Color.GREEN);

# 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 data2 = MT2;
data2.AssignValueColor(if c2 < MT2 then Color.RED else Color.GREEN);

# 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 data3 = MT3;
data3.AssignValueColor(if c3 < MT3 then Color.RED else Color.GREEN);
# End Trend Magic MTF
 
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
 
@tomsk WOW! This is GREAT! Exactly what I was looking for...THANK YOU!

Just to be clear...this can be used for 5 min 15 min and 30 min...right? But what about 1 hour 2 hour 4 hour? I was able to set it to those settings as well ( 1h 2h 4h) and it seems to display just fine...Just want to double check if the calculations to run on higher timeframes will work...Reason being...the Mobius SuperTrend from the pic that I posted above needed a different aggregation coding for anything above 15 min...or something to that nature.
 
Works under any aggregation timeframe, just make sure the aggregation chosen are stacked.
Meaning agg selected should be less than agg2, and agg2 should be less than agg3.
 
I also have tried to create a scanner but it hasn't worked for me either. I tried to use the lower study by tomsk and see how many bars have passed from it turning green or red.
 
Hey everyone, Its been a while since anyone posted in this thread, but I too tried to create a scanner for this indicator and couldn't get it to work. Anyone have any luck creating a scanner over the last year?
 
@stryde1 Studies with multiple aggregations cannot be scanned.
You could take out the three aggregations out of the study then run the scan on the 1st timeframe, save the results to a watch list. Run the scan on the 2nd timeframe against just that watch list. Save those results to another watch list and then run your 3rd scan w/ your 3rd timeframe against the 2nd watch list and that should give you an approximate set of results.
 
@stryde1 Studies with multiple aggregations cannot be scanned.
You could take out the three aggregations out of the study then run the scan on the 1st timeframe, save the results to a watch list. Run the scan on the 2nd timeframe against just that watch list. Save those results to another watch list and then run your 3rd scan w/ your 3rd timeframe against the 2nd watch list and that should give you an approximate set of results.
Thanks MerryDay. Good idea.
 
Something interesting that I came across that has me a little baffled. So I am using the indicator on the Daily chart with a look back of 2 years. My settings on the Trend Magic are Agg1: Daily / Agg2: 3 Days / Agg3: Week.

If I change the look back period on the Daily chart from 2 years to 1 year (without changing the settings on the indicator at all) the results change drastically. Not sure why.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
341 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