Converting Indicator To Multi-TimeFrame (MTF) In ThinkOrSwim

Multi Time Frame Stochastics
Need help adding aggregated time period to standard TOS slow stochastics. Not great at coding can someone help please?
 
Last edited by a moderator:
I'm having trouble trying figure out why my indicator doesn't fit into overbought/oversold like the indicator in the other image.
Can someone help me out? Script is below, I basically added some code to standard TOS slow Stochastics indicator. Also from the image is there a way that I can smooth out the lines? @MerryDay


declare lower;

input agg = AggregationPeriod.FOUR_DAYS;
input over_bought = 80;
input over_sold = 20;
input Zeroline = 50;
input KPeriod = 12;
input DPeriod = 3;
def priceH = high;
def priceL = low;
def priceC = close;
input averageType = AverageType.SIMPLE;
input showBreakoutSignals = {default "No", "On SlowK", "On SlowD", "On SlowK & SlowD"};

plot SlowK = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageType).FullK;
plot SlowD = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,priceH,priceL,priceC,3,averageType).FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;
plot zerobase = zeroline;

def upK = SlowK crosses above OverSold;
def upD = SlowD crosses above OverSold;
def downK = SlowK crosses below OverBought;
def downD = SlowD crosses below OverBought;

plot UpSignal;
plot DownSignal;
switch (showBreakoutSignals) {
case "No":
UpSignal = Double.NaN;
DownSignal = Double.NaN;
case "On SlowK":
UpSignal = if upK then OverSold else Double.NaN;
DownSignal = if downK then OverBought else Double.NaN;
case "On SlowD":
UpSignal = if upD then OverSold else Double.NaN;
DownSignal = if downD then OverBought else Double.NaN;
case "On SlowK & SlowD":
UpSignal = if upK or upD then OverSold else Double.NaN;
DownSignal = if downK or downD then OverBought else Double.NaN;
}

UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");

SlowK.setDefaultColor(GetColor(5));
SlowD.setDefaultColor(GetColor(0));

OverBought.SetDefaultColor(GetColor(1));
OverSold.SetDefaultColor(GetColor(1));
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
 
Last edited:
I'm having trouble trying figure out why my indicator doesn't fit into overbought/oversold like the indicator in the other image.
Can someone help me out? Script is below, I basically added some code to standard TOS slow Stochastics indicator. Also from the image is there a way that I can smooth out the lines? @MerryDay
The jagged jerky lines are built-into MTF indicators. Flat lines are due the the delay between the close of the previous candle and the next candle on the higher aggregation. The candle finally closes, it re-writes the final placement of the flat line and jags up to flat-lining the next candle.
 
Hello, Im trying to get some guidance/assistance in adjusting a code so that I can choose what timeframe aggregate a study from while viewing it on a different timeframe. For example, I want to be able to see the study aggregating from the D timeframe while looking at a lower timeframe chart. As you can see, ive gotten as far as to add the input, but im not too educated in code so dont know much beyond this. Here is the code below:

#Define the desired aggregation
input timeframe = AggregationPeriod.DAY;

DefineGlobalColor("Loose", Color.DARK_GRAY);
DefineGlobalColor("Regular", Color.RED);
DefineGlobalColor("Tight", Color.YELLOW);

def bbu = reference BollingerBands().UpperBand;
def bbl = BollingerBands().LowerBand;
def kc1u = KeltnerChannels(factor = 1.0).Upper_Band;
def kc1l = KeltnerChannels(factor = 1.0).Lower_Band;
def kc2u = KeltnerChannels(factor = 1.5).Upper_Band;
def kc2l = KeltnerChannels(factor = 1.5).Lower_Band;
def kc3u = KeltnerChannels(factor = 2.0).Upper_Band;
def kc3l = KeltnerChannels(factor = 2.0).Lower_Band;

# Loose squeeze
def cloudBUSqz3 = if bbu < kc3u then bbu else Double.NaN;
def cloudKC2USqz3 = if bbu < kc3u then kc3u else Double.NaN;
def cloudBLSqz3 = if bbl > kc3l then bbl else Double.NaN;
def cloudKC2LSqz3 = if bbl > kc3l then kc3l else Double.NaN;

AddCloud(cloudBUSqz3, cloudKC2USqz3, GlobalColor("Loose"), GlobalColor("Loose"), showBorder = yes);
AddCloud(cloudBLSqz3, cloudKC2LSqz3, GlobalColor("Loose"), GlobalColor("Loose"), showBorder = yes);
AddCloud(cloudBUSqz3, cloudKC2USqz3, GlobalColor("Loose"), GlobalColor("Loose"), showBorder = yes);
AddCloud(cloudBLSqz3, cloudKC2LSqz3, GlobalColor("Loose"), GlobalColor("Loose"), showBorder = yes);

# normal squeeze
def cloudBUSqz2 = if bbu < kc2u then bbu else Double.NaN;
def cloudKC2USqz2 = if bbu < kc2u then kc2u else Double.NaN;
def cloudBLSqz2 = if bbl > kc2l then bbl else Double.NaN;
def cloudKC2LSqz2 = if bbl > kc2l then kc2l else Double.NaN;

AddCloud(cloudBUSqz2, cloudKC2USqz2, GlobalColor("Regular"), GlobalColor("Regular"), showBorder = yes);
AddCloud(cloudBLSqz2, cloudKC2LSqz2, GlobalColor("Regular"), GlobalColor("Regular"), showBorder = yes);
AddCloud(cloudBUSqz2, cloudKC2USqz2, GlobalColor("Regular"), GlobalColor("Regular"), showBorder = yes);
AddCloud(cloudBLSqz2, cloudKC2LSqz2, GlobalColor("Regular"), GlobalColor("Regular"), showBorder = yes);

# tightest squeeze
def cloudBUSqz1 = if bbu < kc1u then bbu else Double.NaN;
def cloudKC2USqz1 = if bbu < kc1u then kc1u else Double.NaN;
def cloudBLSqz1 = if bbl > kc1l then bbl else Double.NaN;
def cloudKC2LSqz1 = if bbl > kc1l then kc1l else Double.NaN;

AddCloud(cloudBUSqz1, cloudKC2USqz1, GlobalColor("Tight"), GlobalColor("Tight"), showBorder = yes);
AddCloud(cloudBLSqz1, cloudKC2LSqz1, GlobalColor("Tight"), GlobalColor("Tight"), showBorder = yes);
AddCloud(cloudBUSqz1, cloudKC2USqz1, GlobalColor("Tight"), GlobalColor("Tight"), showBorder = yes);
AddCloud(cloudBLSqz1, cloudKC2LSqz1, GlobalColor("Tight"), GlobalColor("Tight"), showBorder = yes);
 
Hello, Im trying to get some guidance/assistance in adjusting a code so that I can choose what timeframe aggregate a study from while viewing it on a different timeframe. For example, I want to be able to see the study aggregating from the D timeframe while looking at a lower timeframe chart. As you can see, ive gotten as far as to add the input, but im not too educated in code so dont know much beyond this.
Requests for the coding of MTF indicators do not often get fulfilled given the repainting issues detailed in the top post of this thread.
This easy MTF tutorial was posted as an option for those non-programmers interested in creating their own MTF indicators.
 
Last edited:
The jagged jerky lines are built-into MTF indicators. Flat lines are due the the delay between the close of the previous candle and the next candle on the higher aggregation. The candle finally closes, it re-writes the final placement of the flat line and jags up to flat-lining the next candle.
Is there a way to add some sort of "Enable approximation" modifier to get a smoother line from the higher time frame charts on to the smaller time frame charts?
 
Is there a way to do this with an indicator LinearRegCurve ?
i add two lines as stated in the very first post but it doesn't work

here is his code
#
# TD Ameritrade IP Company, Inc. (c) 2008-2023
#

input displace = 0;
input length = 9;
input price = close;

plot LinReg = Inertia(price[-displace], length);
LinReg.setDefaultColor(GetColor(1));


I would like to show lines from the daily chart on the minute chart
 
Is there a way to do this with an indicator LinearRegCurve ?
i add two lines as stated in the very first post but it doesn't work

here is his code
#
# TD Ameritrade IP Company, Inc. (c) 2008-2023
#

input displace = 0;
input length = 9;
input price = close;

plot LinReg = Inertia(price[-displace], length);
LinReg.setDefaultColor(GetColor(1));


I would like to show lines from the daily chart on the minute chart
As the tutorial explained where you see the price, you need to add the aggregation.
So it would look like:

Ruby:
#
# TD Ameritrade IP Company, Inc. (c) 2008-2023
#
input agg =  AggregationPeriod.DAY;
def price= close(Period =agg) ;
input displace = 0;
input length = 9;

plot LinReg = Inertia(price[-displace], length);
LinReg.setDefaultColor(GetColor(1));
 

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