Coding Multi Time Frame (MTF) Indicators with NinjaTrader - NinjaTrader | futures io social day trading
futures io futures trading


Coding Multi Time Frame (MTF) Indicators with NinjaTrader
Updated: Views / Replies:103,326 / 411
Created: by Fat Tails Attachments:161

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 161  
 
Thread Tools Search this Thread
 

Coding Multi Time Frame (MTF) Indicators with NinjaTrader

  #371 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received

@Fat Tails,

I have a question on multiple time frames. I am looking back in time and need to figure out exactly which CurrentBars[] match. I can get close but doesn't seems to match reliable and have started to record associated CurrentBar for the other time series to see if I can get around it.

So here is what I am trying to do, the "simple" case: I have a primary 1 Min bar on the chart and add a 5 min bar as part of a strategy. I am now at bar CurrentBars[0]=1567 for the 1min bar and need to look back 13 bars to find the SMA(1min)[13] and the SMA(5min)[X]. I am hoping there is a simple or internal record of the associate between the bars so I don't need to try an create this association.

So in the above case, the 1min reference bar would be 1567-13 = 1554, the 5min initial bar CurrentBars[1] ~1567/5=313 is the 13th bar back the truncated value of 1554/5 = ~310 bars back 313-310 or 3 bars. It seems like using the 13/5 = ~2.6 might not be a reliable bars back calculation due to starting points of the time series.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
 
  #372 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary


NJAMC View Post
@Fat Tails,

I have a question on multiple time frames. I am looking back in time and need to figure out exactly which CurrentBars[] match. I can get close but doesn't seems to match reliable and have started to record associated CurrentBar for the other time series to see if I can get around it.

So here is what I am trying to do, the "simple" case: I have a primary 1 Min bar on the chart and add a 5 min bar as part of a strategy. I am now at bar CurrentBars[0]=1567 for the 1min bar and need to look back 13 bars to find the SMA(1min)[13] and the SMA(5min)[X]. I am hoping there is a simple or internal record of the associate between the bars so I don't need to try an create this association.

So in the above case, the 1min reference bar would be 1567-13 = 1554, the 5min initial bar CurrentBars[1] ~1567/5=313 is the 13th bar back the truncated value of 1554/5 = ~310 bars back 313-310 or 3 bars. It seems like using the 13/5 = ~2.6 might not be a reliable bars back calculation due to starting points of the time series.

I do not think that it is possible to associate the indices of two different bar series. I have always accepted that each of the bar series has its own index whatever it is. With 1 and 5 minutes things may be still easy, but if you take other timeframes you will typically experience cut-off bars at the session end.

Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #373 (permalink)
Elite Member
Tampa, FL
 
Futures Experience: Beginner
Platform: NinjaTrader, Sierra Chart
Broker/Data: Mirus Futures/Zen-Fire
Favorite Futures: 6E, M6E, 6J
 
Xav1029's Avatar
 
Posts: 1,374 since Dec 2011
Thanks: 1,452 given, 3,354 received



NJAMC View Post
@Fat Tails,

I have a question on multiple time frames. I am looking back in time and need to figure out exactly which CurrentBars[] match. I can get close but doesn't seems to match reliable and have started to record associated CurrentBar for the other time series to see if I can get around it.

So here is what I am trying to do, the "simple" case: I have a primary 1 Min bar on the chart and add a 5 min bar as part of a strategy. I am now at bar CurrentBars[0]=1567 for the 1min bar and need to look back 13 bars to find the SMA(1min)[13] and the SMA(5min)[X]. I am hoping there is a simple or internal record of the associate between the bars so I don't need to try an create this association.

So in the above case, the 1min reference bar would be 1567-13 = 1554, the 5min initial bar CurrentBars[1] ~1567/5=313 is the 13th bar back the truncated value of 1554/5 = ~310 bars back 313-310 or 3 bars. It seems like using the 13/5 = ~2.6 might not be a reliable bars back calculation due to starting points of the time series.

I sometimes use a "sync" series that stores current bars of one bar series in a dataseries inside the other bar series. It helps with exotic bars ,but due to NT's MTF logic you still get that 1 bar discrepancy when bars close at the exact same moment.

London Calling
Reply With Quote
The following 2 users say Thank You to Xav1029 for this post:
 
  #374 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


Fat Tails View Post
I do not think that it is possible to associate the indices of two different bar series. I have always accepted that each of the bar series has its own index whatever it is. With 1 and 5 minutes things may be still easy, but if you take other timeframes you will typically experience cut-off bars at the session end.

@Fat Tails,

Thanks, I found another problem which you may already be aware of with the simple 1 -> 5 ratio. In the off hours, if there is 0 volume for 1 minute, you will only have 4 bars (or even less) per 5 minute bar!

I have tried to go with the sync method in an IntSeries for now. This is better, but still not right, maybe due to the NT MTF bar close issue. I have not tried this with 1 Min vs 3 Renko for example, not sure how things will work in that case. I am sure I can only go in one direction, but it might change based upon number of bars produced by each series. In this 1 Min/3Renko the number of bars/min for the renko is no longer correlated, could be more or less due to price action.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
 
  #375 (permalink)
Elite Member
Northern Germany
 
Futures Experience: Intermediate
Platform: NT
Favorite Futures: FDAX, CL
 
vvhg's Avatar
 
Posts: 1,583 since Mar 2011
Thanks: 1,016 given, 2,807 received


NJAMC View Post
@Fat Tails,

Thanks, I found another problem which you may already be aware of with the simple 1 -> 5 ratio. In the off hours, if there is 0 volume for 1 minute, you will only have 4 bars (or even less) per 5 minute bar!

I have tried to go with the sync method in an IntSeries for now. This is better, but still not right, maybe due to the NT MTF bar close issue. I have not tried this with 1 Min vs 3 Renko for example, not sure how things will work in that case. I am sure I can only go in one direction, but it might change based upon number of bars produced by each series. In this 1 Min/3Renko the number of bars/min for the renko is no longer correlated, could be more or less due to price action.

One workaround for that could be to reference a bar by its time instead of its index.
There is also an indicator with an example on synchronizing bars https://futures.io/ninjatrader/2437-correlation-indicator-ninjatrader-7-a.html#post23492

vvhg

Hic Rhodos, hic salta.
Reply With Quote
The following 3 users say Thank You to vvhg for this post:
 
  #376 (permalink)
Trading Apprentice
Earth
 
Futures Experience: Intermediate
Platform: NinjaTrader
 
Posts: 18 since Feb 2010
Thanks: 3 given, 6 received

I'm a little bit lost or maybe it's getting too late but I'd like to put up some question here if I'm doing things right:
My strategy has 1 Minute Bar Chart and CalculateOnBarClose false. Now I'd like to calculate the EMA of 5 min chart and save it to a DataSeries.

So to analyse when the bar has closed I wait for FirstTickOfBar then use the last Bar (barsAgo = 1 in realtime, for historical bars this has to be 0 I guess)

 
Code
if (historical)
    barsAgo = 0;
else
    barsAgo = 1;

if (FirstTickOfBar)
{
   double ema50 = VisualEMA(50, false, false, VisualEMACalcMode.Strategy, VisualEMAPeriodType.Minute, 5, VisualEMAPriceType.Close)[barsAgo];
   emaSeries.Set(barsAgo, ema50);
}

Would this code result in correct values (realtime and histocial)?

Reply With Quote
 
  #377 (permalink)
Elite Member
Taiwan
 
Futures Experience: Intermediate
Platform: TOS, Matlab
Broker/Data: IB, ToS
Favorite Futures: HSI, TF, CL
 
Posts: 15 since Aug 2011
Thanks: 5 given, 7 received


vvhg View Post
One workaround for that could be to reference a bar by its time instead of its index.
There is also an indicator with an example on synchronizing bars https://futures.io/ninjatrader/2437-correlation-indicator-ninjatrader-7-a.html#post23492

vvhg

In my project I have this issue all the time so here's the summary:

Most, if not all, of all bar referencing mechanism in NT is based on barsAgo, which is opposite to the internal 0-based array indexing. Since I need to record absolute indexing (array style), the following assumes absolute (0 is 1st bar) indexing:

If i is the array zero-based indexing, then its 'barsAgo' is always CurrentBar -i.

For two instruments in the same chart/indicator/strategy, assume their BarsArray index is p and q respectively,
then
the index of 'bar i (in timeframe p)' in timeframe q =

BarsArray[q].GetBar(Time[CurrentBars[p]-i])

For the reduced, and most likely case of p is the the 'current isntrument', then this is reduced to

BarsArray[q].GetBar(Time[CurrentBar-i])

This is the only way to get the correct answer.

Reply With Quote
 
  #378 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,653 since Mar 2010
Thanks: 4,226 given, 25,601 received
Forum Reputation: Legendary


symphys View Post
I'm a little bit lost or maybe it's getting too late but I'd like to put up some question here if I'm doing things right:
My strategy has 1 Minute Bar Chart and CalculateOnBarClose false. Now I'd like to calculate the EMA of 5 min chart and save it to a DataSeries.

So to analyse when the bar has closed I wait for FirstTickOfBar then use the last Bar (barsAgo = 1 in realtime, for historical bars this has to be 0 I guess)

 
Code
if (historical)
    barsAgo = 0;
else
    barsAgo = 1;

if (FirstTickOfBar)
{
   double ema50 = VisualEMA(50, false, false, VisualEMACalcMode.Strategy, VisualEMAPeriodType.Minute, 5, VisualEMAPriceType.Close)[barsAgo];
   emaSeries.Set(barsAgo, ema50);
}

Would this code result in correct values (realtime and histocial)?

If you use a multi-timeframe indicator in a strategy, then you definitely introduce an additional lag. Compare

-> value from 5 minute bar retrieved -> projected onto primary bars -> used by strategy
-> value from 5 minute bar retrieved -> directly used by strategy

The projection is only done after the bar close of the secondary 5 min bars. For example, if you project on a 1-min bar series - most unfavourable case when primary and secondary bars have identical time stamps - then you will the result of the 5-min EMA only one bar later, if you run the strategy in COBC = true.

The indicator addresses the lag by repainting in One-Tick-Correction and Visual mode. It can be run in COBC = false. But if you use the MTF indicator in a strategy then you do not want it to repaint. Actually, I have somewhere presented an example how to access the indicator in other than strategy mode in order to let the strategy repaint, but in fact this is pretty insane.

It is also insane to let the strategy run in COBC= false, but not update the indicator values. I don't understand why you are doing this.

What about simply adding a secondary bar series of 5 min bars and applying an EMA to that series?

Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
  #379 (permalink)
Trading Apprentice
Earth
 
Futures Experience: Intermediate
Platform: NinjaTrader
 
Posts: 18 since Feb 2010
Thanks: 3 given, 6 received


Fat Tails View Post
What about simply adding a secondary bar series of 5 min bars and applying an EMA to that series?

Thanks for the insight. I'll be using this approach...

Reply With Quote
 
  #380 (permalink)
Elite Member
Switzerland
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Dorman
Favorite Futures: Currency Futures, ES
 
mk77ch's Avatar
 
Posts: 76 since Oct 2010
Thanks: 12 given, 64 received


i am currently coding an indicator which is using a second dataseries.
the primary is a 1 minute chart and the second is a 5 minute.

could somebody please tell me how many bars of the second (m5) dataseries are getting loaded?
does it just load all available historical 5 minute bars or is there a way i can control this?

cheers,
mike

Reply With Quote

Reply



futures io > > > > Coding Multi Time Frame (MTF) Indicators with NinjaTrader

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Multi Time Frame Strategy Cancellation jthom NinjaTrader Programming 2 October 9th, 2014 12:00 PM
Close bar recognization in multi time frame strategy pinto552 NinjaTrader Programming 6 September 6th, 2011 10:07 AM
Multi-time frame strategy with periods of different size pequemec NinjaTrader Programming 2 February 24th, 2010 01:41 PM
visual multi-time frame scoring system. benbrooke Traders Hideout 1 October 4th, 2009 06:49 PM
Multi Volume/Time Frame Trading wh The Elite Circle 7 September 15th, 2009 05:55 PM


All times are GMT -4. The time now is 04:44 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-15 in 0.14 seconds with 20 queries on phoenix via your IP 54.234.255.29