Multi-timeframe (MTF) Moving Average Indicator for ThinkorSwim

L

lindosskier

Member
@lindosskier use imgur, all you need is drag and drop the screenshot. and in comment use the link attachment, not image.

Are you adding it multiple times and each one is different timeframe? like 1m,2m,3m and so on all the way up to whatever frame you want to track?
@SuryaKiranC that's probably it. I have not added the code multiple times. I tried starting to do it, but when I change the aggregation period, do i change it in both places, or just one? Check out the code you provided and the aggregation period I changed. The problem now is, that I do not see the Daily Bubble/Label. Any idea why?
Thank you.
 
L

lindosskier

Member
@SuryaKiranC that's probably it. I have not added the code multiple times. I tried starting to do it, but when I change the aggregation period, do i change it in both places, or just one? Check out the code you provided and the aggregation period I changed. The problem now is, that I do not see the Daily Bubble/Label. Any idea why?
Thank you.
Also, @SuryaKiranC I see the 5m and 15m bubbles that I input already, but they have a black background, when it should have been green now. Any idea why for that as well?
Thank you.
 
S

SuryaKiranC

Member
@lindosskier you don't change the "input period = AggregationPeriod.DAY;" it's an input parameter. Just add the script to studies multiple times, and go to properties of each instance and select a different time period. Look at my screenshot in the original response.
 
L

lindosskier

Member
@lindosskier you don't change the "input period = AggregationPeriod.DAY;" it's an input parameter. Just add the script to studies multiple times, and go to properties of each instance and select a different time period. Look at my screenshot in the original response.
@SuryaKiranC tried that, but it does now show the color of the background yet. It is pre-market, but this is the ES, so it should plot all day long right?
And secondly, it does not show the W and M time frame bubbles at all.

Thank you once again for your help. I feel like we are almost there.

 
S

SuryaKiranC

Member
@lindosskier Just for a good measure, grab the copy of the code from my original post, and overwrite (select all, delete and past) in your study one more time, you don't have to repeat this on every instance of the study, just once and save it will do.

Now once that is done, make sure you select have all the timeframes you desire to see, configured and save the studyset.

when you are on 1Min charts you should see all the selected timeframes from 1m to all they way up to 1D. (Please note they will only change color, if the active candle on the timeframe has one of the four signals, Buy/Momentum UP/Momentum Down and Sell, if there is no active signal it will remain dark, you should be able to see the configured timeframe, but barley.)

In-order to see a higher frames such as W or M or even Q on 1Min charts, your chart should present the data. ex: 1D, 1Min Configured timeframe will not have data more than a Day. hence you don't see W, M or Q even when the Study set is configured with a set for that timeframe.

if you must have a 1M data on that chart please configure a chart timeframe for 20D,1Min. Similarly if you must see the Q Data, I suggest your use a 90D Chart with desired Min configuration.


Hope this helps. and finally if you want a matching study of the original code you posted (matching colors as the MTF Study) let me know. I can post the modified code.
 
L

lindosskier

Member
@lindosskier Just for a good measure, grab the copy of the code from my original post, and overwrite (select all, delete and past) in your study one more time, you don't have to repeat this on every instance of the study, just once and save it will do.

Now once that is done, make sure you select have all the timeframes you desire to see, configured and save the studyset.

when you are on 1Min charts you should see all the selected timeframes from 1m to all they way up to 1D. (Please note they will only change color, if the active candle on the timeframe has one of the four signals, Buy/Momentum UP/Momentum Down and Sell, if there is no active signal it will remain dark, you should be able to see the configured timeframe, but barley.)

In-order to see a higher frames such as W or M or even Q on 1Min charts, your chart should present the data. ex: 1D, 1Min Configured timeframe will not have data more than a Day. hence you don't see W, M or Q even when the Study set is configured with a set for that timeframe.

if you must have a 1M data on that chart please configure a chart timeframe for 20D,1Min. Similarly if you must see the Q Data, I suggest your use a 90D Chart with desired Min configuration.


Hope this helps. and finally if you want a matching study of the original code you posted (matching colors as the MTF Study) let me know. I can post the modified code.
@SuryaKiranC thank you! now that you explained all these things, it makes sense and that's how the code works.
Can I ask for 1 last modification? How can we have the background of the bubbles/labels show the color that the candles are, at their respective time frames, AT ALL TIMES. So, if the 5min. candle is yellow and the 60min. candle is red, have the 5min and 60min. bubbles/labels, colors be and REMAIN yellow and red, until they change. Thank you once again, I appreciate your help.
 
S

SuryaKiranC

Member
@SuryaKiranC thank you! now that you explained all these things, it makes sense and that's how the code works.
Can I ask for 1 last modification? How can we have the background of the bubbles/labels show the color that the candles are, at their respective time frames, AT ALL TIMES. So, if the 5min. candle is yellow and the 60min. candle is red, have the 5min and 60min. bubbles/labels, colors be and REMAIN yellow and red, until they change. Thank you once again, I appreciate your help.

alright refresh the code in your Multi_EMAStudy.ts again from the post

https://usethinkscript.com/threads/...rage-indicator-for-thinkorswim.135/post-40067 (I updated the code in the same comment instead of making a new post, this way anybody new grabbing the code will be less confused, which version to grab.)

Also use the following as your chart study, basically add another study for the same Study Set, with the following code, Just so all the colors match up for you.
Code:
#Custom_EMAStudy.ts
#Mr Slim Miller at askSLIM dot com
#SlimRibbonCustom_markos9-7-18

input ShowChartBubbles = yes;

DefineGlobalColor("Buy", CreateColor(177, 245, 83));
DefineGlobalColor("Sell", CreateColor(179, 17, 5));
DefineGlobalColor("MomentumUp", CreateColor(72, 190, 194));
DefineGlobalColor("MomentumDown", CreateColor(235, 16, 122));

def price = close;
input superfast_length = 8;
input fast_length = 13;
input slow_length = 21;
input displace = 0;

def mov_avg8 = ExpAverage(close[-displace], superfast_length);
def mov_avg13 = ExpAverage(close[-displace], fast_length);
def mov_avg21 = ExpAverage(close[-displace], slow_length);

#moving averages
plot Superfast = mov_avg8;
plot Fast = mov_avg13;
plot Slow = mov_avg21;

def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;
def stopbuy = mov_avg8 <= mov_avg13;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);

plot Buy_Signal = buysignal[1] == 0 and buysignal == 1;
AddChartBubble(ShowChartBubbles and Buy_Signal, low , "Long", GlobalColor("Buy"),no);
Buy_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_Signal.SetLineWeight(4);
Buy_Signal.SetDefaultColor(GlobalColor("Buy"));
Buy_Signal.HideTitle();
Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Momentum_Down = buysignal[1] == 1 and buysignal == 0;
Momentum_Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Momentum_Down.SetDefaultColor(GlobalColor("MomentumDown"));
Momentum_Down.HideTitle();
Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;
def stopsell = mov_avg8 >= mov_avg13;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);

plot Sell_Signal = sellsignal[1] == 0 and sellsignal;
AddChartBubble(ShowChartBubbles and Sell_Signal, high , "Short", GlobalColor("Sell"),up=yes);
Sell_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Sell_Signal.SetLineWeight(4);
Sell_Signal.SetDefaultColor(GlobalColor("Sell"));
Sell_Signal.HideTitle();
Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
Momentum_Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Momentum_Up.SetDefaultColor(GlobalColor("MomentumUp"));
Momentum_Up.HideTitle();
Alert(condition = sellsignal[1] == 1 and sellsignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if Buy_Signal == 1 then 4 else if Momentum_Down then 3 else if Momentum_Up then 2 else if Sell_Signal then 1 else 0 ;
Colorbars.Hide();
AssignPriceColor(if Colorbars == 4 then GlobalColor("Buy") else if Colorbars == 3 then GlobalColor("MomentumDown") else if Colorbars == 2 then GlobalColor("MomentumUp") else if Colorbars == 1 then GlobalColor("Sell") else Color.CURRENT);
#end
 
Last edited:
L

lindosskier

Member
alright refresh the code in your Multi_EMAStudy.ts again from the post

https://usethinkscript.com/threads/...rage-indicator-for-thinkorswim.135/post-40067 (I updated the code in the same comment instead of making a new post, this way anybody new grabbing the code will be less confused, which version to grab.)

Also use the following as your chart study, basically add another study for the same Study Set, with the following code, Just so all the colors match up for you.
Code:
#Custom_EMAStudy.ts
#Mr Slim Miller at askSLIM dot com
#SlimRibbonCustom_markos9-7-18

input ShowChartBubbles = yes;

DefineGlobalColor("Buy", CreateColor(177, 245, 83));
DefineGlobalColor("Sell", CreateColor(179, 17, 5));
DefineGlobalColor("MomentumUp", CreateColor(72, 190, 194));
DefineGlobalColor("MomentumDown", CreateColor(235, 16, 122));

def price = close;
input superfast_length = 8;
input fast_length = 13;
input slow_length = 21;
input displace = 0;

def mov_avg8 = ExpAverage(close[-displace], superfast_length);
def mov_avg13 = ExpAverage(close[-displace], fast_length);
def mov_avg21 = ExpAverage(close[-displace], slow_length);

#moving averages
plot Superfast = mov_avg8;
plot Fast = mov_avg13;
plot Slow = mov_avg21;

def buy = mov_avg8 > mov_avg13 and mov_avg13 > mov_avg21 and low > mov_avg8;
def stopbuy = mov_avg8 <= mov_avg13;
def buynow = !buy[1] and buy;
def buysignal = CompoundValue(1, if buynow and !stopbuy then 1 else if buysignal[1] == 1 and stopbuy then 0 else buysignal[1], 0);

plot Buy_Signal = buysignal[1] == 0 and buysignal == 1;
AddChartBubble(ShowChartBubbles and Buy_Signal, low , "Long", GlobalColor("Buy"),no);
Buy_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Buy_Signal.SetLineWeight(4);
Buy_Signal.SetDefaultColor(GlobalColor("Buy"));
Buy_Signal.HideTitle();
Alert(condition = buysignal[1] == 0 and buysignal == 1, text = "Buy Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Momentum_Down = buysignal[1] == 1 and buysignal == 0;
Momentum_Down.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Momentum_Down.SetDefaultColor(GlobalColor("MomentumDown"));
Momentum_Down.HideTitle();
Alert(condition = buysignal[1] == 1 and buysignal == 0, text = "Momentum_Down", sound = Sound.Bell, "alert type" = Alert.BAR);

def sell = mov_avg8 < mov_avg13 and mov_avg13 < mov_avg21 and high < mov_avg8;
def stopsell = mov_avg8 >= mov_avg13;
def sellnow = !sell[1] and sell;
def sellsignal = CompoundValue(1, if sellnow and !stopsell then 1 else if sellsignal[1] == 1 and stopsell then 0 else sellsignal[1], 0);

plot Sell_Signal = sellsignal[1] == 0 and sellsignal;
AddChartBubble(ShowChartBubbles and Sell_Signal, high , "Short", GlobalColor("Sell"),up=yes);
Sell_Signal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Sell_Signal.SetLineWeight(4);
Sell_Signal.SetDefaultColor(GlobalColor("Sell"));
Sell_Signal.HideTitle();
Alert(condition = sellsignal[1] == 0 and sellsignal == 1, text = "Sell Signal", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Momentum_Up = sellsignal[1] == 1 and sellsignal == 0;
Momentum_Up.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Momentum_Up.SetDefaultColor(GlobalColor("MomentumUp"));
Momentum_Up.HideTitle();
Alert(condition = sellsignal[1] == 1 and sellsignal == 0, text = "Momentum_Up", sound = Sound.Bell, "alert type" = Alert.BAR);

plot Colorbars = if Buy_Signal == 1 then 4 else if Momentum_Down then 3 else if Momentum_Up then 2 else if Sell_Signal then 1 else 0 ;
Colorbars.Hide();
AssignPriceColor(if Colorbars == 4 then GlobalColor("Buy") else if Colorbars == 3 then GlobalColor("MomentumDown") else if Colorbars == 2 then GlobalColor("MomentumUp") else if Colorbars == 1 then GlobalColor("Sell") else Color.CURRENT);
#end
@SuryaKiranC the colors stay plotted on the background of each bubble/label, which is great, but a lot of them do not match the actual colors of the candles. For example, you can see from the picture below that the 30 and 60 min. bubbles show red, where in reality are green.
That's from using the original code (which I copied and pasted again, since you changed it). The last piece of code you posted does not change anything, it just plots long or short on the candles, when they change colors. Once again, thank you for your help in trying to figure this out.
 
S

SuryaKiranC

Member
@lindosskier Can you capture and post the part of the screen that is useful, with out the white?

Anyways, from what I can see your current chart is Green candle and the label us green. What is the issue here you were trying to point out?
are you saying if you are in 30 and 60 min charts at the time you are looking at this indicator they were green candles but the indicator is showing red? if yes you got to show . me that charts too.

@lindosskier if you are comparing with the timeframe, please do it with out any study, not even the orginal. the original study may be painting green or red based on some condition not the the plain charts. What I am trying to mimic is no study original candle color and paint the color for the 4 signals defined only.
 
Last edited by a moderator:
L

lindosskier

Member
@SuryaKiranC I see what you are saying and yes, your code achieves exactly that. But what I am trying to accomplish is to use the study that paints the candles green, yellow, or red, based on the study I provided. The idea is to use somewhat of a trend and stay in a trade, as long as the candles are at least yellow on different timeframes. Are you able to change the code to use the candle colors based on that study I provided, for the different timeframes? Thank you very much for your efforts!

The idea is that when i see the 5min become yellow, followed by the 15min becoming yellow and the 30min. becoming yellow (based on the 8/13/21 EMA study I provided ), then I know that there is a trend change most likely and to get out of a position. That's what I am trying to find out. Thank you!
 
Last edited by a moderator:

Similar threads

Top