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

  #1 (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

Coding Multi Time Frame (MTF) Indicators with NinjaTrader

I am still relying on NinjaTrader to code my indicators and have recently played around with adding secondary bar series to indicators, so I just want to share my experience and show what currently can be done and what can't be done.

Of course I hope that others will share their experience as well, allowing to better exploit the full potential that lies within this option which has recently been introduced with NinjaTrader 7.

With the first post I just want to summarize, what I have in mind, and what potential improvements can be made.


Increasing the Resolution of Indicators

Some indicators do not show correct values, because the information required to calculate them is not contained with the primary bar series. By adding a secondary high definition bar series, the indicators can be improved. There are three of them that come to my mind immediately.

The current session's VWAP:

If you calculate the volume weighted average price for a 30 min bar series, there is only one value after 30 minutes which could be the typical or any other price calculated from Open, High, Low and Close. It is obvious that this value will be far from reality and that the calculated value will be false. It would be much better to calculate the VWAP from a secondary 1 minute bar series, which would reduce the error to a minimum for all practical purposes.

The opening range indicator:

If you read "The Logical Trader" by Mark Fisher, you will not that he suggests an opening range of 20 minutes for ES. How can you display this range on a 15 min chart? The answer is: You can't. Unless you calculate the opening range from a secondary 1 min data bar series.

Volume profiles:

Let us assume that you want to display a market profile for the current session on a 17 minute chart by using one of the volume zones indicators (such as the dValueArea indicator). The problem which you will encounter here: You cannot calculate 30 min TPOs from 17 minute data. Also you cannot calculate any mode for the volume distribution of the current session from 17 min data, but you need higher resolution data. This again would be a case for a multi time frame indicator.


Displaying Higher Time Frame Signals on Your Chart

This is practically the opposite of the first way to use a secondary bar series. It is technically impossible to display smaller time frame signals on any chart, as the resolution of the chart, that is the grid defined by the visible bar series does not allow it. This limits the use of smaller bar series to cases, where more precision is needed to display some of the more complex indicators. Also smaller time frame traders can be considered as noise traders, so I am rather interested in what the larger time frame traders are doing.

Some of the indicators that are used are already MTF indicators as they tell us something about the actions of the other time frame traders. These indicators use reference points outside the visible fraction of the chart. So although indicator values are mostly calculated from price, and just represent a reduced version of price, it is their time frame transfer capability that makes them interesting for the trader.

Existing indicators include market profile, daily, weekly and monthly pivots, average daily range, fibonacci confluence indicators, which all add some information from the more distant past.

But now, with adding data series, anything should be possible. Moving averages, oscillators, divergence indicators, actually the whole set of NinjaTrader default indicators as a MTF version allowing you to calculate them on a 60 min bar series, but display the results on a 157 tick or 6 range chart.

However, there is a number of traps, which have to be avoided, when creating such indicators. My intention is to document some of those traps with a simple multi time frame EMA. I also want to release a modified version of the SuperTrend indicator.


Last edited by Fat Tails; April 10th, 2011 at 02:42 PM.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (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

Opening Range Indicator


One of my first indicators, which I have modified, is the Opening Range Indicator. This is an experimental version, so whoever uses it, is supposed to give some feedback whether it works as expected. The indicator has the following features:

-> it loads a separate 1-minute bar series which is used to calculate the opening range
-> the use of a session template including the RTH session for which you want to display the opening range is compulsory
-> it should work for any full minute opening range on all minute, range, volume and tick charts
-> it has an option to display the RTH open or the first 1-minute bar of the session
-> it colors the opening range, the opacity can be selected also allowing to unselect the fill color for the range
-> it also allows to display the night session range, or alternatively the range of the European or Asian session

Some general notes on secondary bar series:

(1) The session template:

The secondary bar series uses the same session template as the primary bar series. Another template cannot be used.

(2) The lag problem:

OnBarUpdate() always calls the secondary bar series after the primary bar series. This is one of the fundamental problems of MTF indicators. Let us assume that your primary bar series uses 15 minute bars and the secondary bar series uses 1-min bars. This means that when the first 15-minute bar closes, only the information generated by the prior 14 1-min bars is available. The last 1-minute bar will pass unnoticed by the 15-minute bar! This problem introduces an additional lag, as the full information will only be disclosed with the first tick of the second 15-minute bar.

This is very annoying for historical data. Historical bars are 1-tick bars, so the information from the last 1-minute bar of the first 15 minutes can only be displayed when the second 15 minute bar is completed, which is after 30 min. For real-time data this is less of a problem, as the first tick should arrive pretty fast after the first 15 min bar closed. An exception is the situation at the session close.

(3) The one-tick repainting option

Because of this lag problem, some of my MTF indicators have an option to repaint the prior bar after the first tick of the consecutive bar has arrived. This makes sense for visual display of historical bars and also for the visual display of real-time data. When running strategies, this option should be turned off, as repainting falsifies data in the way it arrives, so you would need to accept the lag introduced by the way OnBarUpdate() works.

The on tick repainting option should also be used with the last bar of a session, as otherwise you would need to wait until the new session starts to display the values calculated from the last secondary bar of the old session.

(4) Checking for bars

For any MTF indicator it is necessary to check for bars. The minimum shoud be BarsRequired = 0, which indicates that you do not attempt to run it on an empty bar series. OnBarUpdate() should always include a line as per below:

 
Code
if(CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired)
	return;
Attached is the experimental opening range indicator (labelled X1). Please report any issues. Further suggestions are welcome. An official version of this indicator will go to the download section after testing.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-opening-range-mtf.jpg  
Attached Files
Register to download File Type: zip OpeningRangeV32MTFX1.zip (8.8 KB, 364 views)

Last edited by Fat Tails; April 10th, 2011 at 05:57 PM.
Reply With Quote
The following 17 users say Thank You to Fat Tails for this post:
 
  #4 (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

A Multi Time Frame EMA

This is another experimental indicator. It allows to display any EMA on your chart, for example you can display

- a 3 range EMA on a 275 tick chart
- a 60 min EMA on a 200 volume chart
- a 60 min EMA on a 15 min chart


Allows to plot indicators based on different bar types and time frames on evenly spaced charts

You can also display multi time frame indicators by adding a second data series to your chart. For example, if you trade a tick chart you can add a 60 min bar series and then display an EMA(9) calculated from that 60 min series. The only problem you will encounter is that your bars will be unevenly spaced. With a multi time frame indicator, you avoid this uneven spacing. You typically pay with a little lag, which can be neglected for larger time frames.


Three modes to display the EMA

The indicator has three modes to demonstrate the behavior of the dual bar series indicator.

StrategicMode: The first bar series collects the values from the secondary series with the little lag already described. The chart attached shows this slightly lacking series in orange.

FirstTickMode: To avoid the lag for minute bars with identical time stamps, the indicator is allowed to repaint the indicator value for the prior bar, after the first tick of the current bar has been registered. The chart below shows the first tick mode in red. You will not that the lag has been reduced.

Visual Mode: To make it easier to use the indicator visually, the indicator interpolates the distance between two consecutive bars of the secondary bar series. The interpolation algorithm works in real-time and simulates the CalculateOnBarClose = false mode for the indicator relative to the secondary bar series. It repaints the current leg of the indicator back to the prior bar of the secondary series. The interpolation adapts itself to equidistant or non-equidistant charts.


Something to play with

I have attached the indicator. It is a protected assembly, which will only run on NT 7.0.1000.3 or later, but which is licence free. The chart below has the indicator applied three times. The blue line is the EMA in VisualMode, which is easier to use than the step functions that can be typically seen in other MTF indicators.

It is the first indicator of this type that I have coded, so please report any issues.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-cl-05-11-3-min-11_04_2011.jpg  
Attached Files
Register to download File Type: zip VisualEMAX1.zip (39.0 KB, 357 views)
Reply With Quote
The following 14 users say Thank You to Fat Tails for this post:
 
  #5 (permalink)
Elite Member
Germany
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: Mirus Futures/Zen-Fire
 
TempletonPeck's Avatar
 
Posts: 199 since Feb 2010
Thanks: 1,129 given, 200 received

First of all thanks for your continual improvements.

Just for clarification:
Because of the lag problem it is right that the indicator shows a OR High of 1,4497 from 14:50:01-14:55 CET. ( I have chosen an 30 min opening range from 14:20 - 14:50 CET). The new high 1,4499 occured between 14:49 and 14:50 (last 1-minute bar).
So the new OR High was displayed after the next 5 minute bar closed at 14:55:01.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-6e-06-11-5-min-12_04_201101.jpg   Coding Multi Time Frame (MTF) Indicators with NinjaTrader-6e-06-11-5-min-12_04_201102.jpg  
Reply With Quote
The following user says Thank You to TempletonPeck for this post:
 
  #6 (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


TempletonPeck View Post
First of all thanks for your continual improvements.

Just for clarification:
Because of the lag problem it is right that the indicator shows a OR High of 1,4497 from 14:50:01-14:55 CET. ( I have chosen an 30 min opening range from 14:20 - 14:50 CET). The new high 1,4499 occured between 14:49 and 14:50 (last 1-minute bar).
So the new OR High was displayed after the next 5 minute bar closed at 14:55:01.


Thanks for pointing this out. I also noticed the same thing.

If you use the indicator in CalculateOnBarClose = true (default setting), which you probably did, then this is what happens

14:49 -> the (incomplete opening range is calculated from the secondary bar series, which is 1 minute data)
14:50 -> the developing opening range is displayed for the period 14:20 - 14:49
14:50 -> the complete opening range is calculated via the secondary bar series
14:50 + 1 tick -> nothing, because OnBarUpdate() is not triggered
14:55 -> the result of the calculation made at 14:50 is now displayed

To NinjaTrader Developers: It is really a pity that BarSeries 0 is called prior to BarSeries 1.

Now this problem is very specific to your setup. It does not occur

- if the indicator is applied to tick, range or volume charts (time stamp of prior bar cannot be equal)
- if the duration of the opening range is not an integer multiple of the primary bar series (minute bars)
- for all consecutive bars of the chart

So for this problem to occur you need

- to select minute bars
- to select a bar period such that the opening range is an integer multiple of that bar period
- and watch out for that single bar for which the result will be displayed with a lag

In this specific case, you better use the simple version of the opening range indicator instead of the multi time frame version.

But you are absolutely right and did hit that little nail on its head.

Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
  #7 (permalink)
Elite Member
Rechovot
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: CQG
Favorite Futures: Index,Currency and Energy futures
 
perryg's Avatar
 
Posts: 1,703 since Jan 2010
Thanks: 504 given, 6,262 received


Fat Tails View Post
This is another experimental indicator. It allows to display any EMA on your chart, for example you can display

- a 3 range EMA on a 275 tick chart
- a 60 min EMA on a 200 volume chart
- a 60 min EMA on a 15 min chart


Allows to plot indicators based on different bar types and time frames on evenly spaced charts

You can also display multi time frame indicators by adding a second data series to your chart. For example, if you trade a tick chart you can add a 60 min bar series and then display an EMA(9) calculated from that 60 min series. The only problem you will encounter is that your bars will be unevenly spaced. With a multi time frame indicator, you avoid this uneven spacing. You typically pay with a little lag, which can be neglected for larger time frames.


Three modes to display the EMA

The indicator has three modes to demonstrate the behavior of the dual bar series indicator.

StrategicMode: The first bar series collects the values from the secondary series with the little lag already described. The chart attached shows this slightly lacking series in orange.

FirstTickMode: To avoid the lag for minute bars with identical time stamps, the indicator is allowed to repaint the indicator value for the prior bar, after the first tick of the current bar has been registered. The chart below shows the first tick mode in red. You will not that the lag has been reduced.

Visual Mode: To make it easier to use the indicator visually, the indicator interpolates the distance between two consecutive bars of the secondary bar series. The interpolation algorithm works in real-time and simulates the CalculateOnBarClose = false mode for the indicator relative to the secondary bar series. It repaints the current leg of the indicator back to the prior bar of the secondary series. The interpolation adapts itself to equidistant or non-equidistant charts.


Something to play with

I have attached the indicator. It is a protected assembly, which will only run on NT 7.0.1000.3 or later, but which is licence free. The chart below has the indicator applied three times. The blue line is the EMA in VisualMode, which is easier to use than the step functions that can be typically seen in other MTF indicators.

It is the first indicator of this type that I have coded, so please report any issues.

Fats Tails,
I am excited at what I see. Is it possible to put together a similar indicator for SMA. I use both EMA and SMA and this way I can test entry points using this idea. So far the EMA looks good in the Visual mode.

Reply With Quote
The following user says Thank You to perryg for this post:
 
  #8 (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


perryg View Post
Fats Tails,
I am excited at what I see. Is it possible to put together a similar indicator for SMA. I use both EMA and SMA and this way I can test entry points using this idea. So far the EMA looks good in the Visual mode.

Yes, it is possible to apply this concept to most of the NinjaTrader indicators. The only problem is, that it is really tricky. It has taken me five fruitless attempts of coding, before I managed to code that EMA, and I am still not sure that everything is working properly. I do not want to code a bunch of indicators that do not work. So I have decided to give this one a longer test, before proceeding.


Some Specific Problems

Here are the difficulties that I have encountered (for those who want to further explore the subject).

(1) Different logic of adding values for the historical and the real-time part for the chart. On the historical part you will only find one-tick bars. This means that OnBarUpdate() calls lots of bars of the primary bar series and occasionally one bar of the secondary series. For real-time data OnBarUpdate() calls alternatively bar series 0 and the secondary bar series. Also I have found some exceptions.

(2) Problems with the hybrid bar.

When switching from historical to real-time data, NinjaTrader creates a hybrid bar from historical and real-time data. Sometimes this bar does not behave as expected

(3) Different logic for time stamps on minute and tick bars. The lag problem, which can be solved with repainting, only occurs, if two fixed-period bars (minute or second bars) have the same time-stamp. When using MTF indicator with a combination of minute/tick or tick/tick series, the problem does not exist. As volume and range bars are being built from ticks, they show the same behavior.

(4) Lag compensation, if possible for the combination of two minute or second based bar series.

(5) Interpolation of the results. This requires a different algorithm for charts with equidistant and non-equidistant bar spacing. Also the CalcOnBarClose = false mode needs to be simulated for the last leg of the secondary bar series.


Testing is still needed.

To summarize: I am not sure that all this works correctly, so it needs some further testing. Expect a few minor bugs.

Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
  #9 (permalink)
Elite Member
Boston
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: Crude
 
PHXtrader's Avatar
 
Posts: 84 since Apr 2011
Thanks: 48 given, 76 received

This is awesome! Thanks so much for taking the time to do this. I'm using it on range charts and will def let you know if I see any bugs.


THANKS AGAIN.

Reply With Quote
The following user says Thank You to PHXtrader for this post:
 
  #10 (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


Following request, I have added the option to calculate the multi time frame EMA from Renko bars.

So, if you think that you need a tick chart, but want to calculate your EMA from 2-Renko bars, here comes your indicator.

The chart shows

- a primary series of tick bars (lime and red candlesticks)
- a secondary series of 2-Renko bars (gray and black candlesticks)

The secondary bar series is only used to check the multi time frame indicator.

Green: EMA(5) directly calculated from secondary bar series
Blue: EMA(5) calculated for the 2-Renko bars via multi time frame indicator and then inserted with the candles of the primary bar series.
Red: Same as blue but in first tick mode.
Yellow: Same as red but in strategy mode (covered by the red first tick mode EMA).

Indicator is attached. It is a protected assembly, which will only work with NT 7.0.1000.3 or later

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-es-06-11-30-tick-_-es-06-11-2-renko-10_05_2011.jpg  
Attached Files
Register to download File Type: zip VisualEMAX2.zip (39.6 KB, 220 views)
Reply With Quote
The following 6 users say Thank You to Fat Tails for this post:

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:43 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.21 seconds with 20 queries on phoenix via your IP 54.234.255.29