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,134 / 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

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

OpeningRangeV33MTFX3

Yes, I had the same problem with the GetNextBeginEnd() signature for the multi timeframe version of the Opening Range indicator. I have corrected it now and made a number of smaller improvements as well.

X3 means that it is the third eXperimental version of the indicator. When it is ripe, I will put it into the download section of this forum. I think it is close.

The chart show the opening range calculated from 1 minute data. The red highlighted range is the range of the first minute of trading. The night session high and low is shown as well.

The indicator should not throw any exceptions as was the case with the V32MTFX2 version.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-es-06-11-15-min-24_05_2011.jpg  
Attached Files
Register to download File Type: zip OpeningRangV33MTFX3.zip (9.0 KB, 106 views)
Reply With Quote
 
  #22 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary

VisualEMAX3


perryg View Post
Fat Tails,
I have used in real time the VisualSMAX3 on 1min and 5 min charts taking the moving average from a Range chart as well using typical. It is working perfectly with very good results. I have also tested the other way round of using range charts and putting a 5 min moving average onto the range chart. I can recommend the use of this indicator.
If you have time could you also add to the VisualEMA indicator the Typical as you did with the VisualSMA.

This is the enhanced version of the multi-timeframe EMA. As before you can select between the step mode, which reflects the values generated by the secondary bars and the interpolated visual mode, which smoothes out the step. This version now also allows to select the Input series, meaning that you can calculate the multi-timeframe EMA from the Close, High, Low, Median, Typical or Weighted series.

Indicator attached below.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-cl-07-11-5-min-24_05_2011.jpg  
Attached Files
Register to download File Type: zip VisualEMAX3.zip (40.1 KB, 167 views)
Reply With Quote
The following 10 users say Thank You to Fat Tails for this post:
 
  #23 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

How about a different Instrument?


Thanks for all this work, FT. This is great thinking! MTF Visual EMA indicator is excellent!

Because of rampant risk asset correlation it can be beneficial to track instruments other than the one you are trading. This suggests the idea of secondary indicators that would be based not only on a different time frame, but on a different instrument.

For example, on a 200 tick chart of the CL, display in an added panel the 20 period EMA of the 3 range ES... etc. while maintaining the equidistant bar spacing of the 200 tick CL in the Price Panel.


Last edited by Zondor; May 25th, 2011 at 03:17 AM.
Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #24 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Fat Tails said:


Quoting 
(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.


I wrote some indicators that display a secondary data series. What I found is that when BarsInProgress =1, there is always a new value of Closes[1][0] and any variables associated with it DO update. However, the new values are NOT shown on the chart until the next tick comes in for the primary series, where BarsInProgress = 0.

For example, I was showing a plot of ^TICK on a 250 tick chart (with equal bar spacing) of YM. During the customary YM super slow periods, could see that the ^TICK plot did not respond when the time and sales showed new values of ^TICK coming in. The ^TICK plot only updated when a new value of YM printed, although diagnostic statements printing to the output window showedthat new values of Closes[1][0] were indeed all coming in when they were supposed to.

In other words, the chart display only updated when BarsInProgress was equal to 0.

The solution that worked for my indicators : FORCE the chart display to update every time a new price tick comes in for the secondary series.

 
Code
if(!Historical && BarsInProgress == 1) ChartControl.Refresh();

Reply With Quote
The following 3 users say Thank You to Zondor for this post:
 
  #25 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


Zondor View Post
I wrote some indicators that display a secondary data series. What I found is that when BarsInProgress =1, there is always a new value of Closes[1][0] and any variables associated with it DO update. However, the new values are NOT shown on the chart until the next tick comes in for the primary series, where BarsInProgress = 0.

For example, I was showing a plot of ^TICK on a 250 tick chart (with equal bar spacing) of YM. During the customary YM super slow periods, could see that the ^TICK plot did not respond when the time and sales showed new values of ^TICK coming in. The ^TICK plot only updated when a new value of YM printed, although diagnostic statements printing to the output window showedthat new values of Closes[1][0] were indeed all coming in when they were supposed to.

In other words, the chart display only updated when BarsInProgress was equal to 0.

The solution that worked for my indicators : FORCE the chart display to update every time a new price tick comes in for the secondary series.

 
Code
if(!Historical && BarsInProgress == 1) ChartControl.Refresh();

Thank you for the suggestion, that makes sense.

If I refresh the chart with each incoming tick, when Barsarray[1] is processed , do you know whether that will override the chart display update interval?

I do not want to cause a NinjaTrader freeze by refreshing the chart for each incoming tick, if the market is moving fast.

Reply With Quote
 
  #26 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Fat Tails asked:

Quoting 
If I refresh the chart with each incoming tick, when Barsarray[1] is processed , do you know whether that will override the chart display update interval?

I do not want to cause a NinjaTrader freeze by refreshing the chart for each incoming tick, if the market is moving fast.

I am not sure whether the forced Refresh overrides the chart display interval. This could be checked by printing diagnostic messages with the Refresh times down to the millisecond to the Output Window. You could keep track of the time of the last Refresh and not allow the forced refresh to occur unless a certain number of milliseconds has elapsed since the last refresh.

 
Code
if(!Historical && BarsInProgress==1 &&  MostRecentRefreshTime.AddMilliseconds > UserSelectableMillisecondRefreshInterval) ChartControl.Refresh();
However I have NOT done this. The forced Refreshes on every update of the secondary series have not caused any problems with my indicators as long as the command is a separate statement near the end of OnBarUpdate. Have not seen any problems at all during fast markets.

Another condition you can subject it to is to only trigger if the value of what you are plotting has changed from its most recent previous value.

Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #27 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary


Zondor View Post
Fat Tails asked:
I am not sure whether the forced Refresh overrides the chart display interval. This could be checked by printing diagnostic messages with the Refresh times down to the millisecond to the Output Window. You could keep track of the time of the last Refresh and not allow the forced refresh to occur unless a certain number of milliseconds has elapsed since the last refresh.

 
Code
if(!Historical && BarsInProgress==1 &&  MostRecentRefreshTime.AddMilliseconds > UserSelectableMillisecondRefreshInterval) ChartControl.Refresh();
However I have NOT done this. The forced Refreshes on every update of the secondary series have not caused any problems with my indicators as long as the command is a separate statement near the end of OnBarUpdate. Have not seen any problems at all during fast markets.

Another condition you can subject it to is to only trigger if the value of what you are plotting has changed from its most recent previous value.

@Zondor

I really appreciate your input here. May main concern is CPU load. Let us assume - for the worse - that I have 15 indicators on my chart, out of which 3 are multi-timeframe indicators and 5 have custom plots (for example the pivots do have custom plots that can create a bit of CPU load)

How does NinjaTrader process the indicators internally?

Process A

1. new incoming tick
2. triggers OnBarUpdate for primary bars for indicators 1 to 15
3. plots (if time elapsed smaller display update interval)
4. trigger OnBarUpdate for secondary bars of first multiseries indicator
5. plots (if time elapsed smaller display update interval)
6. trigger OnBarUpdate for secondary bars of second multiseries indicator
7. plots (if time elapsed smaller display update interval)
8. trigger OnBarUpdate for secondary bars of third multiseries indicator
9. plots (if time elapsed smaller display update interval)

Process B

same as above, but additional 14 plots within the step 2.

The code snippet meant to assure that the refresh is not executed, if the last refresh was less than n milliseconds ago. Now I cannot know the last refresh time, unless I have an indicator with an override Plot() to collect it.So I am thinking about two options here

First Option: measure the difference between the last two incoming ticks and compared it to the display update interval (this assumes that the tick speed remains constant, and may at worst trigger one additional refresh, but not 100).

Second Option: Code a separate indicator that will automatically refresh, by using a user-selectable display update interval.

What is your opinion?

Reply With Quote
 
  #28 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

The OnBarUpdate event is only called ONCE per incoming tick. Refresh without fear!

Definition of BarsInProgress from Ninjatrader help:

An index value of the current Bars object that has called the OnBarUpdate() method. In a multi-bars script, the OnBarUpdate() method is called for each Bars object of a script. This flexibility allows you to separate trading logic from different bar events. In a single Bars script this property will always return an index value of 0 representing the primary Bars and instrument the script is running on.



(note: For primary instrument price series n=1, for second series n=2, third series n=3....nth series n=N)
(BIP=BarsInProgress, an integer returned for each OnBarUpdate event)
The OnBarUpdate event is always fired ONCE when a tick arrives. It's the same event no matter which bar series the tick comes from. The only difference is what value BIP is set to. For some reason, only when BIP=0 will OBU cause the chart to refresh. I consider this to be a Ninjatrader bug.

1. data feed sends a new incoming tick of primary instrument price series(n=1)
2. triggers OnBarUpdate in which the value of BIP is 0. All the code in OnBarUpdate executes... ONCE only.
3. BECAUSE the value of BarsInProgress is 0 the chart will refresh.
3. data feed sends a new incoming tick for instrument N
4. triggers OnBarUpdate in which the value of BIP is N-1. All the code in OnBarUpdate executes... ONCE only.
5. BECAUSE the value of BarsInProgress is NOT 0 the chart will NOT refresh. NINJA BUG
6. So we force the chart to refresh. if(!Historical && BarsInProgress >0...&& whatever)

OnBarUpdate is called ONCE each time there is a tick from ANY of the instruments, no matter how many instruments there are.

All the BarUpdate events DO occur exactly when they are supposed to. Whenever ANY of the series updates, OnBarUpdate DOES occur. OnBarUpdate events are driven directly by the different series in real time and are not dependent on each other in any way. However the APPEARANCE OF THE CHART only updates when BIP=0!

You can see this in the output window. OnBarUpdate events will fire with different values of BIP whenever any of the series generates a tick, but the chart will only refresh when BIP=0.

So far I do not see any indication that the forced refreshes cause any noticeable increase in CPU load.

Bonus! Did you know that you can index the CurrentBar expression to find where you are in each data series! Instead of CurrentBar write CurrenBars[N]. If you want to be sure you are looking at the CurrentBar of the primary series, you will have lots of "interesting' problems if you say CurrentBar instead of CurrentBars[0], because CurrentBar will keep returning values for different instruments!


Last edited by Zondor; May 25th, 2011 at 06:55 PM.
Reply With Quote
The following 4 users say Thank You to Zondor for this post:
 
  #29 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Error trapping needed in VisualEMAX3

The VisualEMAX with a period of 1 can be used as a proxy for the price of a series with any time frame including or other than that of the chart. But when I try to take advantage of this by runnng an indicator that calls the VisualEMAX3 I get the error:

Error on calling OnStartUp method for indicator VisualEMAX3, Object reference not set to instance of an object.

My indicator then displays nothing.

The same thing happens when I try to apply another indicator to the VisualEMAX3 using the NT7 indicator-of-an -indicator feature of the indicators dialog box.


Because the code is in a DLL I can't do anything about the error. FT, could you please consider adding try{ }catch error handlers to all of the methods of the indicator to make sure that all exceptions are handled to prevent crashing of indicator from unhandled exceptions. Thanks.

Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #30 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary



Zondor View Post
OnBarUpdate is called ONCE each time there is a tick from ANY of the instruments, no matter how many instruments there are.

All the BarUpdate events DO occur exactly when they are supposed to. Whenever ANY of the series updates, OnBarUpdate DOES occur. OnBarUpdate events are driven directly by the different series in real time and are not dependent on each other in any way. However the APPEARANCE OF THE CHART only updates when BIP=0!

You can see this in the output window. OnBarUpdate events will fire with different values of BIP whenever any of the series generates a tick, but the chart will only refresh when BIP=0.

So far I do not see any indication that the forced refreshes cause any noticeable increase in CPU load.

I understand that OnBarUpdate() is triggered for each bars array. So if datafeed produces a tick containing price data, this will be first processed for BarsArray[0], then for the other BarsArrays. What is confusing is the order of the other bars being processed. Let us assume that I apply a multi-timeframe indicatoro to a multi-dataseries chart. If the secondary bars objects of the MTF indicators matches the secondary bars objects of the underlying multi-series chart, NinjaTrader will not recreate the bars. So there will not be two 5 min bar series for ES 06-11, but only one, as the MTF indicator will use the already existing bars array of the multiseries chart. Could this inverse the order in which the BarsInProgress are selected?

Also I have observed some rare cases, where BarsInProgress=0 have been updated twice in a row (real-time), without any update of BarsInProgress=1 (double BIP), but I was not able to reproduce it.

Guess, I just will try out some code snippets and then see how it plays out in real-time.



Zondor View Post
Bonus! Did you know that you can index the CurrentBar expression to find where you are in each data series! Instead of CurrentBar write CurrenBars[N]. If you want to be sure you are looking at the CurrentBar of the primary series, you will have lots of "interesting' problems if you say CurrentBar instead of CurrentBars[0], because CurrentBar will keep returning values for different instruments!

All my multi timeframe indicators use CurrentBars[N] for clarity. Just had a problem in a custom plot, where CurrentBar returned false values. But CurrentBars[0] also did return false values, still have no idea why.

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)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

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 09:01 PM.

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-11 in 0.19 seconds with 20 queries on phoenix via your IP 54.83.122.227