NexusFi: Find Your Edge


Home Menu

 





help code multiple Time Frame indicator


Discussion in ThinkOrSwim

Updated
      Top Posters
    1. looks_one zentrade with 6 posts (2 thanks)
    2. looks_two onnb with 6 posts (1 thanks)
    3. looks_3 druM3 with 3 posts (0 thanks)
    4. looks_4 Xav1029 with 2 posts (0 thanks)
      Best Posters
    1. looks_one jdella with 1 thanks per post
    2. looks_two Big Mike with 0.5 thanks per post
    3. looks_3 zentrade with 0.3 thanks per post
    4. looks_4 onnb with 0.2 thanks per post
    1. trending_up 41,607 views
    2. thumb_up 5 thanks given
    3. group 9 followers
    1. forum 25 posts
    2. attach_file 1 attachments




 
Search this Thread

help code multiple Time Frame indicator

  #11 (permalink)
 
zentrade's Avatar
 zentrade 
Wilson, NC
 
Experience: Intermediate
Platform: thinkorswim
Trading: NQ
Posts: 18 since Dec 2010
Thanks Given: 1
Thanks Received: 5

onnb, basically I did this in the script i posted...



#
# thinkorswim, inc. (c) 2007
#

input length = 8;
input displace = 0;
input agperiod = { "1 min", default "5 min", "15 min", "30 min", "60 min", "4 hours"};

plot AvgExp = ExpAverage(close(period = agperiod)[-displace], length);
AvgExp.SetStyle(Curve.SHORT_DASH);
AvgExp.SetLineWeight(4);
AvgExp.SetDefaultColor(GetColor(1));


but if you try to calculate a more complicated indicator like macd or stochastics, for some reason the calculations aren't correct when you try to use the calculation in an if-then-else expression or use the def variable (with the higher aggregation period) in another calculation.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Are there any eval firms that allow you to sink to your …
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Deepmoney LLM
Elite Quantitative GenAI/LLM
Exit Strategy
NinjaTrader
 
  #12 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3


zentrade View Post
Is this what you are looking for? I just took the stock Exponential moving avg script and added input for a new time period. I think it would be better if you could gather the OHLC info using the rec statement, but this works fine.

BTW, if anyone knows how to do this using the "rec" statement please let me know.

in order to use the rec command, just replace the "plot" keyword with "rec" and you should be good to go.

Reply With Quote
  #13 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3



zentrade View Post
onnb, basically I did this in the script i posted...

but if you try to calculate a more complicated indicator like macd or stochastics, for some reason the calculations aren't correct when you try to use the calculation in an if-then-else expression or use the def variable (with the higher aggregation period) in another calculation.

yeah - i got that too. not sure why. what you can though is just put the stochastic or macd implementation into your mutli timeframe code like this (just change the aggregation period as you like):

declare lower;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period = 3;

plot FullK = Average((close(period = AggregationPeriod.WEEK) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) / (Highest(high(period = AggregationPeriod.WEEK), KPeriod) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) * 100, slowing_period);

plot FullD = Average(Average((close(period = AggregationPeriod.WEEK) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) / (Highest(high(period = AggregationPeriod.WEEK), KPeriod) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) * 100, slowing_period), DPeriod);

the above is taken from ToS documentation, nothing genius on my part

Reply With Quote
  #14 (permalink)
 
zentrade's Avatar
 zentrade 
Wilson, NC
 
Experience: Intermediate
Platform: thinkorswim
Trading: NQ
Posts: 18 since Dec 2010
Thanks Given: 1
Thanks Received: 5


onnb View Post
yeah - i got that too. not sure why. what you can though is just put the stochastic or macd implementation into your mutli timeframe code like this (just change the aggregation period as you like):

declare lower;
input KPeriod = 10;
input DPeriod = 10;
input slowing_period = 3;

plot FullK = Average((close(period = AggregationPeriod.WEEK) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) / (Highest(high(period = AggregationPeriod.WEEK), KPeriod) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) * 100, slowing_period);

plot FullD = Average(Average((close(period = AggregationPeriod.WEEK) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) / (Highest(high(period = AggregationPeriod.WEEK), KPeriod) - Lowest(low(period = AggregationPeriod.WEEK), KPeriod)) * 100, slowing_period), DPeriod);

the above is taken from ToS documentation, nothing genius on my part

I thought about doing that too but the scripts I make like this are extremely slow to load. Was thinking that a "rec" solution would be much faster and cleaner.

Reply With Quote
  #15 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3


zentrade View Post
I thought about doing that too but the scripts I make like this are extremely slow to load. Was thinking that a "rec" solution would be much faster and cleaner.

what do you mean by a "rec" solution?

Reply With Quote
  #16 (permalink)
 
zentrade's Avatar
 zentrade 
Wilson, NC
 
Experience: Intermediate
Platform: thinkorswim
Trading: NQ
Posts: 18 since Dec 2010
Thanks Given: 1
Thanks Received: 5


onnb View Post
what do you mean by a "rec" solution?

creating this multi timeframe indicator using the "rec" statement instead of changing the aggregation period in the CLOSE statement

Reply With Quote
  #17 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3


zentrade View Post
creating this multi timeframe indicator using the "rec" statement instead of changing the aggregation period in the CLOSE statement

ah...this can sometimes get quite complex - especially if you are developing a general solution to handle all cases.

anyways, so let me see if i get this. say you are doing an average. its the same in principal for stochastic or any other indicator so lets take the average as an example. for the sake of example, lets say we want an average of closing prices.

so your algorithm might look like this:

1. decide where to start the aggregation - on the first bar of the chart might be one possibility. another, more logical to me, might be to always start on a round hour / or 30 min or 5 min - depending on the granularity.

2. next keep a rec variable that holds the closing price after each granularity period and zero otherwise. so for example:

say you are doing 30 min aggregation on a 5 min chart.

closing price on the 5 min chart over the last 7 bars: 1, 2, 3, 4, 5, 6, 7, 8 ,9, 10
your rec variable over this period might look like this: 0, 0, 3, 0, 0, 0, 0, 8, 0, 0, etc.

3. on each time the study is called, you check the time of the current bar. if it is the end of your aggregation period, you store that value in the rec value for this iteration. if it s not the end of the aggregation period, you just put there zero.

4. now, you calculate the average - so for a simple average, you would iterate over the rec variable going back to "length" number of non zero values adding them up and dividing by length.

once you get this down, there are optimizations you can do to this but i wouldn't get into them till i have something that is working as basis first. besides, it might run fast enough so that you don't need the optimizations.

hope this helps,
Onn

Reply With Quote
  #18 (permalink)
 
zentrade's Avatar
 zentrade 
Wilson, NC
 
Experience: Intermediate
Platform: thinkorswim
Trading: NQ
Posts: 18 since Dec 2010
Thanks Given: 1
Thanks Received: 5


onnb View Post
ah...this can sometimes get quite complex - especially if you are developing a general solution to handle all cases.
Onn

I guess it can get a little complicated. I'm not very good with think script and wouldn't know where to start with something this tricky. I wish the calculation issues I mentioned earlier wrt using a def assignment from a different aggravation period was fixed. Writing a mtf indicator would be much easier. Is writing mtf indicators much easier in other platforms?

Reply With Quote
  #19 (permalink)
 onnb 
Vancouver, Canada
Onn
 
Experience: Intermediate
Platform: NinjaTrader, SierraCharts, thinkorswim
Trading: Stocks
Posts: 10 since Sep 2011
Thanks Given: 0
Thanks Received: 3


zentrade View Post
. Is writing mtf indicators much easier in other platforms?


i mostly have experience with ToS and SierraChart and a little bit with NT. my 2 cents is that your experience with ToS is similar to the others meaning:

they provide a pretty easy and straightforward way to implement mtf indicators. if you go down this path it is pretty straight forward. this does come with a price in performance though. this price is usually because they implement a general solution to handle all cases that users might require. you can try and improve the performance by implementing it directly on your own (like you are thinking). you improve on performance cuz you can build something very specific and optimize it for your requirements - but that becomes a bit more tricky as you need to understand exactly how the mtf works and all of the outlier cases.

hope this helps,
Onn

Reply With Quote
  #20 (permalink)
 
druM3's Avatar
 druM3 
belfast, UK
 
Experience: Intermediate
Platform: Ninja Trader 7 / TOS
Broker: Amp
Trading: ES
Posts: 46 since Mar 2012
Thanks Given: 6
Thanks Received: 33


Hi

Is there a version of the MTF EMA that will show time based emas on the range charts?


Thanks

"Just A Dollar And A Dream"
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on March 3, 2014


© 2024 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 - Privacy Policy - Downloads - Top
no new posts