NexusFi: Find Your Edge


Home Menu

 





Multiple Timeframe for MACD


Discussion in ThinkOrSwim

Updated
    1. trending_up 6,802 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 3 posts
    2. attach_file 1 attachments




 
Search this Thread
  #1 (permalink)
gcorrea
Puerto Rico
 
Posts: 1 since Jan 2014
Thanks Given: 1
Thanks Received: 0

Hi, This is the first time I participate in your forum (and to be honest a newby on TOS ThinkScripts Programming).

I want to add a thinkscript code for a Multiple Time Frame for MACD. My main chart is 5 minutes and wanted to have MACD for 15 and 60 minute on my 5 minutes chart.

So far, this is what my 5 min TOS Chart currently has:

input averagefastLength = 9;
input averageslowLength = 27;
input macdLength = 7;
input averageType = {SMA, default EMA};

def diff = reference MACD(averagefastLength, averageslowLength, macdLength, averageType).Diff;
def exit = EntryPrice();


Your help on this type of aggregation will be very appreciated.

Thanks


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Warsh Opens Today, Hormuz June 19 -- WTI Below $80, Fran …
Prediction Markets & Event Contracts
Iran Forward Curve: June 30 at 56% vs June 15 at 28% -- …
Prediction Markets & Event Contracts
Rubios Good News Within Hours and the 30-Day Math: Why H …
Prediction Markets & Event Contracts
S&P 500 Holds the Line: No Fast Track for SpaceX, Op …
Stocks and ETFs
Six Days to Kickoff: World Cup Prediction Markets Hit $1 …
Prediction Markets & Event Contracts
 
  #2 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 439

Gave it a shot; it gets a bit fugly the higher the timeframe. The lines in bold were added/edited from the default MACD.
 
Code
declare lower;

input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
input TimeFrame = AggregationPeriod.Day;

plot Value = MovingAverage(averageType, close(period = TimeFrame), fastLength) - MovingAverage(averageType, close(period = TimeFrame), slowLength);
plot Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = Value - Avg;
plot ZeroLine = 0;

Value.SetDefaultColor(GetColor(1));
Avg.SetDefaultColor(GetColor(8));
Diff.SetDefaultColor(GetColor(5));
Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.SetLineWeight(3);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.AssignValueColor(if Diff >= 0 then if Diff > Diff[1] then Diff.color("Positive and Up") else Diff.color("Positive and Down") else if Diff < Diff[1] then Diff.color("Negative and Down") else Diff.color("Negative and Up"));
ZeroLine.SetDefaultColor(GetColor(0));

https://toslc.thinkorswim.com/center/charting/thinkscript/tutorials/Chapter-12---Referencing-Secondary-Aggregation.html

https://toslc.thinkorswim.com/center/charting/thinkscript/reference/Constants/AggregationPeriod.html


Attached Files
Elite Membership required to download: _MACDmultipletimeframesSTUDY.ts
Reply With Quote
Thanked by:
  #3 (permalink)
LorraineP
Tyler, TX/USA
 
Posts: 21 since Jan 2015
Thanks Given: 6
Thanks Received: 8


I've used TOS. And I've used MacD and several variations of it on TOS. I believe it automatically changes when you change your time frame.

So I don't get why you are trying to recreate the wheel?


Reply With Quote
  #4 (permalink)
 
rmejia's Avatar
 rmejia 
Puerto Rico
 
Experience: Intermediate
Platform: thinkorswim
Broker: TD Ameritrade
Trading: Options
Posts: 379 since Oct 2010
Thanks Given: 3,614
Thanks Received: 439


LorraineP View Post
I've used TOS. And I've used MacD and several variations of it on TOS. I believe it automatically changes when you change your time frame.

So I don't get why you are trying to recreate the wheel?

He wants to be able to have a different timeframe on the MACD from the chart:


gcorrea View Post
My main chart is 5 minutes and wanted to have MACD for 15 and 60 minute on my 5 minutes chart.


Reply With Quote




Last Updated on August 16, 2015


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts