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

  #261 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Interactive Brokers
Favorite Futures: forex
 
Posts: 38 since Aug 2011
Thanks: 9 given, 25 received


Fat Tails View Post
The code can be used for a strategy, however - even if compared with the strategy mode of the VisualEMA - it is quite a bit different.

Accuracy on Backtests:

I will only compare it to the strategy mode. The strategy mode of the VisualEMA is specificly designed for use with historical data, and has the lag eliminated as much as possible, without repainting. On the chart below you will see that the real VisualEMA leads the indicator which was coded as above by one bar. This increases the accuracy of any backtest.

The VisualMode is even more accurate, but it repaints over the interpolation period. It should not be compared to the code snippet above. The same applies to the One-Tick-Correction mode.

CalculateOnBarClose = false:

Again the VisualEMA can be used in CalculateOnBarClose = false mode in strategy mode. There is a small lag for the first bars after the transition from historical to real-time data, but this is the price to be paid for the lag reduction on historical data. You cannot have both. The yellow indicator which follows the code above, cannot be easily used in CalculateOnBarClose = false mode, as it will neither produce a step function nor an interpolated indicator.

The posted code is just an example, an idea how it can be done. I like "drunken sailor" very funny, however let me post some charts.

Here is the setup:
On the left side we have 15min chart with regular EMA 12, 30min EMA 12, 60min EMA12 and 60min SMA20
On the right side we have 4tick Better Renko chart with VisualEMA 12period 15min(orange), 30min(Aqua Blue) 60min(Dark blue) and Visual SMA20 60min(White)
VisualEMA and VisualSMA are thicker 2pixel lines, MY code (NOT the one posted) are the 1 pixel thinner line same colors.

only 15min are set to 'Calculate on bar close = false' the rest is set to 'true'
VisualEMA and VisualSMA just lags and gives us wrong results.
My code (thinner line same color) match with charts on the left side.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-ema-comparision4.jpg   Coding Multi Time Frame (MTF) Indicators with NinjaTrader-ema-comparision5.jpg  
Reply With Quote
The following 3 users say Thank You to BankRobberNT for this post:
 
  #262 (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,600 received
Forum Reputation: Legendary


grofzr View Post
Only 15min are set to 'Calculate on bar close = false' the rest is set to 'true'
VisualEMA and VisualSMA just lags and gives us wrong results.
My code (thinner line same color) match with charts on the left side.

Your chart does not show anything, even the indicator settings cannot be seen.

The VisualSMA has three different modes:

VisualMode: No lag mode for discretionary trading.
One-Tick-Correction Mode: No lag mode for discretionary trading, step function.
StrategyMode: The strategy mode is designed for historical data (backtest) and has no lag on historical data.

There is a trade-off. The strategy mode will lag on real-time data just after the transition from historical data to real-time data. This cannot be easily changed. It can be explained by the fact that both SMA and EMA use a recursive formula.

Otherwise there is no lag (meaning the minimum lag between the close of the secondary bar and the close of the next primary bar).

Below chart showing the original EMA directly applied to a 5 min bar series (gray bars) and the VisualEMA (red), which tracks the original EMA as close as possible, given that it can only show the values via the primary bar series. The simple MTF EMA repeats its drunken sailor performance.

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-fdax-12-11-4-betterrenko-_-fdax-12-11-5-min-22_11_2011.jpg  
Reply With Quote
The following 2 users say Thank You to Fat Tails for this post:
 
  #263 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Interactive Brokers
Favorite Futures: forex
 
Posts: 38 since Aug 2011
Thanks: 9 given, 25 received


Same setup 15 seconds chart on the right side
Only orange is calculated on bar close = false (drunken sailor)

Attached Thumbnails
Coding Multi Time Frame (MTF) Indicators with NinjaTrader-ema-comparision6jpg.jpg   Coding Multi Time Frame (MTF) Indicators with NinjaTrader-ema-comparision7jpg.jpg  
Reply With Quote
 
  #264 (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,600 received
Forum Reputation: Legendary


grofzr View Post
Same setup 15 seconds chart on the right side
Only orange is calculated on bar close = false (drunken sailor)

I would love to see something on your chart, but I can't. Could you post a chart with just two or three indicators, so that they can be compared?


Last edited by Fat Tails; November 22nd, 2011 at 12:47 PM.
Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #265 (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,600 received
Forum Reputation: Legendary


grofzr View Post
only 15min are set to 'Calculate on bar close = false' the rest is set to 'true'
VisualEMA and VisualSMA just lags and gives us wrong results.

@grofzr: I have further tested the VisualSMA and VisualEMA in mode CalculateOnBarClose = true. Although I could not see it on your chart, you are absolutely right.

The indicators lag, when they are set to CalculateOnBarClose = true. Thanks again for pointing this out.

Actually I had never tested them thoroughly in CalculateOnBarClose = true, as I was happy that they worked well tick by tick, when CalculateOnBarClose = false. The correction is not difficult to do, so I will update the indicators today or tomorrow.

The change will have no impact on the way the indicators display on historical data or in mode CalculateOnBarClose = false.


Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #266 (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,600 received
Forum Reputation: Legendary

I have made the changes, now testing them:

Below is a chart which shows two bar series, 3-range bars (colored) and 5-minute bars (gray). The chart uses non-equidistant bar spacing, because there are two data series. The 5-minute bars have only been added for controlling the multi-timeframe indicators.

On the chart you can see

-> the default NinjaTrader EMA directly applied to the 5-min bars (blue) - this is the benchmark
-> the VisualEMA prior to correction in CalculateOnBarClose = true mode, which lags (red)
-> the VisualEMA after correction in CalculateOnBarClose = true mode (green), which closely follows the EMA
-> the MTF EMA, which lags on historical data, and oscillates between the two versions of the VisualEMA on real-time data (orange)

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
 
  #267 (permalink)
Membership Temporarily Revoked
NYC
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Interactive Brokers
Favorite Futures: forex
 
Posts: 38 since Aug 2011
Thanks: 9 given, 25 received

First kudos to you for all your work on many great indicators. Yes, the main problem was on Calculate on Bar Close = true. I'd suggest you to do testing on 15, 30 and 60 minutes, because I've noticed the biggest differences there. I use code other than posted for my testing. For some reason 5 minutes has given almost identical results on both code(Visual EMA and my test code).You can see 5minute VisualEMA on my charts colored Ivory. I'll try post more charts later.


Last edited by BankRobberNT; November 22nd, 2011 at 04:13 PM.
Reply With Quote
The following user says Thank You to BankRobberNT for this post:
 
  #268 (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,600 received
Forum Reputation: Legendary


grofzr View Post
First kudos to you for all your work on many great indicators. Yes, the main problem was on Calculate on Bar Close = true. I'd suggest you to do testing on 15, 30 and 60 minutes, because I've noticed the biggest differences there. I use code other than posted for my testing. For some reason 5 minutes has given almost identical results on both code(Visual EMA and my test code).You can see 5minute VisualEMA on my charts colored Ivory. I'll try post more charts later.

Still testing, will post tomorrow.

Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
 
  #269 (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,600 received
Forum Reputation: Legendary

Update VisualSMA and VisualEMA

As was discovered by @grofzr, both indicators were lagging when set to CalculateOnBarClose = true. I admit that the original design of the indicators was adapted to CalculateOnBarClose = false setting, which is more difficult, so I somehow neglected this part.

Testing everything is near-impossible. You add range bars to volume bars, then there is a session break, although the indicator works on historical data and on real-time data, it may have a problem with the transition as NinjaTrader builds a hybrid bar from historical and real-time tick in a non-reproducible manner, there is the possibility of CalculateOnBarClose = false setting or CalculateOnBarClose = true setting, there are technical breaks to be considered where there is no data, as the NinjaTrader heuristics for a trading day does not allow to exclude those session breaks via a session template. Let us say it is sort of a large headache until it works.

I have now tested the updated versions with CalculateOnBarClose = true setting, and so far they passed the test.

https://futures.io/download/ninjatrader-7/indicators/942-download.html?view
https://futures.io/download/ninjatrader-7/indicators/939-download.html?view

Reply With Quote
The following 11 users say Thank You to Fat Tails for this post:
 
  #270 (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,600 received
Forum Reputation: Legendary

Calling MTF indicators


I have made some tests with various multi-timeframe indicators, how they behave when they are called from other indicators or strategies. Let us consider three different cases:

(1) You have a multi-timeframe indicator which loads minute bars.
(2) You have a multi-timeframe indicator which loads tick bars.
(3) You have a multi-timeframe indicator which loads range bars.

Now let us proceed to perform a test. We open any chart (no importance) and first add the original MTF indicator. Then we also add the second indicator, which is calling the MTF indicator to retrieve its values. Both indicators are in CalculateOnBarClose = true and should display identical values for the indicator.

In cases (1) and (2) this works as expected. However, if you try (3) to access an indicator which loads range bars to calculate indicator values, the result is negative. The values transmitted to the calling indicator lag, and there is a growing error term between the original indicator and the indicator which accesses it.

Conclusion

You cannot access any MTF indicator built from range bars via another indicator or strategy in real.time. You can only use the original indicator. However it seems, that there are no deviations on historical data, so I am confident that you can access the MTF indicator for a backtest, but I am not sure.

I believe that the problem is related to the way range bars are built. The range bar is only completed with the first tick of the next bar, which is required to confirm its completion. This probably introduces a lag of one tick between the original indcator and the calling indicator. The gaps once created propagates to the next bar because of the recursive formula of the SMA, which was used.

If you want to reproduce the issue, I have attached two very basic indicators just for documenting it. You can test it on your machine. One indicator is a simple MTF indicator, the other one accesses it and should display the same value.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Attached Files
Register to download File Type: zip AccessTestMTF.zip (5.7 KB, 72 views)

Last edited by Fat Tails; November 24th, 2011 at 12:53 PM.
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)

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 02:33 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-12 in 0.16 seconds with 20 queries on phoenix via your IP 54.90.207.75