NexusFi: Find Your Edge


Home Menu

 





Coding Multi Time Frame (MTF) Indicators with NinjaTrader


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 180 posts (562 thanks)
    2. looks_two Zondor with 19 posts (29 thanks)
    3. looks_3 madLyfe with 16 posts (10 thanks)
    4. looks_4 BankRobberNT with 14 posts (16 thanks)
      Best Posters
    1. looks_one gomi with 3.7 thanks per post
    2. looks_two Fat Tails with 3.1 thanks per post
    3. looks_3 Zondor with 1.5 thanks per post
    4. looks_4 BankRobberNT with 1.1 thanks per post
    1. trending_up 186,462 views
    2. thumb_up 743 thanks given
    3. group 87 followers
    1. forum 424 posts
    2. attach_file 166 attachments




 
Search this Thread

Coding Multi Time Frame (MTF) Indicators with NinjaTrader

  #221 (permalink)
 HighDesertTrader 
Albuquerque, New Mexico/USA
 
Experience: Intermediate
Platform: NinjaTrader-Continuum(Mirus)
Trading: emini Currency and Index Futures
Posts: 104 since Jan 2011
Thanks Given: 291
Thanks Received: 108


Fat Tails View Post
I have been further digging into the NinjaTrader architecture, and the result is a simpler version of the VisualSMA and the VisualEMA. The new versions were entirely recoded from scratch and the code is about 80 lines shorter than the code of the previous versions.

Simplicity always means performance gain and robustness, so here are some of the main improvements:

-> loading time of the indicator on historical data reduced by a factor 10
-> lag of the indicators reduced
-> indicators can be safely called from other indicator or strategy

The chart below shows the 20-period EMA and 20-period SMA, both calculated from a 5 minute chart, but displayed on a 50 tick chart of the FDAX 12-11.

The new indicators are attached below. After installation you will find them as NewVisualSMA or NewVisualEMA in the dropdown menu of the indicator dialogue box. These are not the final versions, but pre-versions for testing.

Hello FAT TAILS,

Thanks for these incredible indicators. They have made a huge impact on my trading. I was wondering if it is possible to write a version of these indicators (Visual SMA/EMA) that have a color selection capability for the slope of the indicator (e.g., slope up = green/slope down = red, slope flat = yellow, etc.)?

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
Deepmoney LLM
Elite Quantitative GenAI/LLM
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
27 thanks
GFIs1 1 DAX trade per day journal
18 thanks
The Program
18 thanks
  #222 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102

Here comes the next version of new VisualSMA and VisualEMA. I have now tested it for hours and days on range, tick, volume and minute charts. The indicator was fast and reliable. I have not found any serious bugs. There was a smaller bug in the interpolation algorithm for the last period (@ madLyfe: thank you for the hint!), and there were some smaller deviations at the intersection between historical and real-time data. This is the weak link of NinjaTrader bar processing, the composite bars built from historical and real-time ticks are quite strange and do not follow a simple logic. Fortunately there is only one transition bar on each chart. The indicator usually catches those transition bars in correctly. In rare cases - less than 1% - the composite bar of the secondary bar series is left out, and the last historical bar is directly connected to the first real-time bar.

The new indicators are attached. I am confident that I can upload the next version to the download section for general use.


Attached Files
Elite Membership required to download: VisualIndicatorsTest5.zip
Started this thread Reply With Quote
  #223 (permalink)
 Erez 
Haifa,,,
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CQG
Trading: Futures
Posts: 186 since Mar 2011
Thanks Given: 181
Thanks Received: 869



Fat Tails View Post
Here comes the next version of new VisualSMA and VisualEMA. I have now tested it for hours and days on range, tick, volume and minute charts. The indicator was fast and reliable. I have not found any serious bugs. There was a smaller bug in the interpolation algorithm for the last period (@ madLyfe: thank you for the hint!), and there were some smaller deviations at the intersection between historical and real-time data. This is the weak link of NinjaTrader bar processing, the composite bars built from historical and real-time ticks are quite strange and do not follow a simple logic. Fortunately there is only one transition bar on each chart. The indicator usually catches those transition bars in correctly. In rare cases - less than 1% - the composite bar of the secondary bar series is left out, and the last historical bar is directly connected to the first real-time bar.

The new indicators are attached. I am confident that I can upload the next version to the download section for general use.

Hi Fat Tails,
I'm trying to use your latest version of visual SMA (VisualIndicatorsTest5) within another indicator.
Red line represents NewVisualSMA.
Blue line represents NewVisualSMA data series when called from another indicator with identical parameters.
I'm doing something wrong? Or the data series doesn’t reflect exact plot values?
Thanks

Erez

Attached Thumbnails
Click image for larger version

Name:	Visual SMA 6E 12-11.png
Views:	245
Size:	107.4 KB
ID:	53970  
Reply With Quote
  #224 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Erez View Post
Hi Fat Tails,
I'm trying to use your latest version of visual SMA (VisualIndicatorsTest5) within another indicator.
Red line represents NewVisualSMA.
Blue line represents NewVisualSMA data series when called from another indicator with identical parameters.
I'm doing something wrong? Or the data series doesn’t reflect exact plot values?
Thanks

Erez

@ Erez: This is as expected, but thank you for putting up this question. The VisualEMA and VisualSMA have three different ways of displaying the moving average, which are Strategy Mode, One-Tick-Repainting Mode and Visual Mode. These three modes work in a different way. For showing the difference I have added two charts below, which shows the VisualEMA in Strategy Mode (green), One Tick Repaint Mode (red) and VisualMode (blue).

Strategy Mode: Whenever the indicator detects a new bar close for the secondary bar series, it will write the moving average value associated with the bar close to the DataSeries which will be used to plot the indicator. The indicator is therefore displayed as a step series. The indicator does not repaint in strategy mode.

One-Tick-Repainting Mode: For historical data this mode is similar as the strategy mode. However, on real-time data, the close of the bar (other than tick and volume bars, where you could use a counter) can only be detected with the first tick of the next bar. At that stage the prior value of the moving average calculated from the secondary is painted back one tick to the previous bar. This one tick repainting is not done to introduce a hindsight bias, but to compensate for one of the shortcomings of the event driven architecture of NinjaTrader.

Visual Mode: The visual mode is based on the one-tick-repainting mode. However it interpolates the distance between to steps of the step function. In doing this the exact visual appearance of the original other timeframe indicator is obtained. This interpolation requires that the indicator paints back from the current node (shown as blue or orange dot on the chart) to the previous node. This painting back is the exact equivalent of what NinjaTrader does with the current unstable period, if you set any indicator to CalculateOnBarClose = false.


Calling the VisualEMA or VisualSMA by another indicator or from within a strategy

The backpainting is only conceived as a visual aid for the discretionary trader. The real-time gain in one-tick-repaint mode is 1 tick, which results in a lag compensation of 1 bar. In visual mode the backpainting is only used for the distance back to the last node as represented by a blue or orange dot. I believe that the repainting issues are creating problems, if you wish to call the indicator from another indicator or strategy. This would require updating of prior values of your indicators as well. For that reason and to avoid confusion, the indicator will automatically switch to strategy mode, if it is called. The one-tick gain on real-time data is not worth the confusion created, and the visual interpolation is not necessary, if the indicator is used within the context of a strategy.





Started this thread Reply With Quote
  #225 (permalink)
 
prisonbreaker82's Avatar
 prisonbreaker82 
Rio de Janeiro
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire, IB
Trading: Equity & Futures
Posts: 312 since Jun 2010
Thanks Given: 58
Thanks Received: 141

Hi Fat Tails,

Still receives the message on version 5 (when trying to save the template). When I use your old anaVisualEMA I do not get it...

Thank you for your great contribution!



Fat Tails View Post
I suppose that you got that message, when you tried to save the template. I think that there is a NinjaTrader bug, which occasionaly hits and causes problems with the serialization. Best solution is to shutdown NinjaTrader and to restart it again.

If this does not help, please let me know what exactly you did to produce this message.

If anybody else has made the same observation, please let me also know.


Visit my NexusFi Trade Journal Reply With Quote
  #226 (permalink)
 Erez 
Haifa,,,
 
Experience: Intermediate
Platform: NinjaTrader
Broker: CQG
Trading: Futures
Posts: 186 since Mar 2011
Thanks Given: 181
Thanks Received: 869


Fat Tails View Post
@ Erez: This is as expected, but thank you for putting up this question. The VisualEMA and VisualSMA have three different ways of displaying the moving average, which are Strategy Mode, One-Tick-Repainting Mode and Visual Mode. These three modes work in a different way. For showing the difference I have added two charts below, which shows the VisualEMA in Strategy Mode (green), One Tick Repaint Mode (red) and VisualMode (blue).

Strategy Mode: Whenever the indicator detects a new bar close for the secondary bar series, it will write the moving average value associated with the bar close to the DataSeries which will be used to plot the indicator. The indicator is therefore displayed as a step series. The indicator does not repaint in strategy mode.

One-Tick-Repainting Mode: For historical data this mode is similar as the strategy mode. However, on real-time data, the close of the bar (other than tick and volume bars, where you could use a counter) can only be detected with the first tick of the next bar. At that stage the prior value of the moving average calculated from the secondary is painted back one tick to the previous bar. This one tick repainting is not done to introduce a hindsight bias, but to compensate for one of the shortcomings of the event driven architecture of NinjaTrader.

Visual Mode: The visual mode is based on the one-tick-repainting mode. However it interpolates the distance between to steps of the step function. In doing this the exact visual appearance of the original other timeframe indicator is obtained. This interpolation requires that the indicator paints back from the current node (shown as blue or orange dot on the chart) to the previous node. This painting back is the exact equivalent of what NinjaTrader does with the current unstable period, if you set any indicator to CalculateOnBarClose = false.


Calling the VisualEMA or VisualSMA by another indicator or from within a strategy

The backpainting is only conceived as a visual aid for the discretionary trader. The real-time gain in one-tick-repaint mode is 1 tick, which results in a lag compensation of 1 bar. In visual mode the backpainting is only used for the distance back to the last node as represented by a blue or orange dot. I believe that the repainting issues are creating problems, if you wish to call the indicator from another indicator or strategy. This would require updating of prior values of your indicators as well. For that reason and to avoid confusion, the indicator will automatically switch to strategy mode, if it is called. The one-tick gain on real-time data is not worth the confusion created, and the visual interpolation is not necessary, if the indicator is used within the context of a strategy.

@Fat Tails,

Thanks for this detailed explanation, I'm aware of to repainting issue after bar is close in secondary series.
I'm trying to do some calculation on this MTF line, but this can be done only on visual mode data series, this data also required to display the visual mode line as is.
Can you release experimental version with exposed visual mode data series?
I assume I can add some code in my indicator, to recognize these events of repaint and sync with it.
Thanks

Erez

Reply With Quote
  #227 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Erez View Post
@Fat Tails,

Thanks for this detailed explanation, I'm aware of to repainting issue after bar is close in secondary series.
I'm trying to do some calculation on this MTF line, but this can be done only on visual mode data series, this data also required to display the visual mode line as is.
Can you release experimental version with exposed visual mode data series?
I assume I can add some code in my indicator, to recognize these events of repaint and sync with it.
Thanks

Erez


@Erez: I am not posting this publicly, because I know that there will be a huge number of issues.

If you are interested send me a private message and I will produce a specific version for you. Basically what would be required is an additional variable, which needs to be exposed and will allow you to catch the current value for the numbers of bars that are being painted back. Then you have the information, how many bars you need to set when calling the indicator.

Started this thread Reply With Quote
Thanked by:
  #228 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


prisonbreaker82 View Post
Hi Fat Tails,

Still receives the message on version 5 (when trying to save the template). When I use your old anaVisualEMA I do not get it...

Thank you for your great contribution!

@prisonbreaker82: I can save the template here. Do not really know, what causes your problem. If you wish contact me via private message, so that I can have a look at your chart template.

Started this thread Reply With Quote
  #229 (permalink)
 HighDesertTrader 
Albuquerque, New Mexico/USA
 
Experience: Intermediate
Platform: NinjaTrader-Continuum(Mirus)
Trading: emini Currency and Index Futures
Posts: 104 since Jan 2011
Thanks Given: 291
Thanks Received: 108


gpquigley View Post
Hello FAT TAILS,

Thanks for these incredible indicators. They have made a huge impact on my trading. I was wondering if it is possible to write a version of these indicators (Visual SMA/EMA) that have a color selection capability for the slope of the indicator (e.g., slope up = green/slope down = red, slope flat = yellow, etc.)?


Perhaps not. Thanks anyway!

Reply With Quote
  #230 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



gpquigley View Post
Perhaps not. Thanks anyway!

I had already answered this question:



First comes the indicator.

Colors and alerts and the capability of sending an e-mail to your girl friend, when the moving average is sloping upwards will come later.

Started this thread Reply With Quote
Thanked by:




Last Updated on April 19, 2022


© 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