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,647 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

  #301 (permalink)
 maxreturn 
Grand Rapids, Michigan, United States
 
Experience: Intermediate
Platform: NinjaTrader
Trading: TF, 6E
Posts: 319 since Dec 2010
Thanks Given: 264
Thanks Received: 114

Hello Fat Tails. Yesterday afternoon I noticed that the visual SMA in strategy mode repainted plots a couple of times when I hit the f5 key. This morning I decided to watch the behavior of this indicator in both visual and strategy mode. I selected two times at random, took a before picture, then hit f5, then took an after picture. The indicator in visual mode seems to be working fine but in both instances, the plots in strategy mode changed. I've attached the before and after pictures. The first instance = before1 and after1. Second instance = before2 and after2.

Best Regards
Chuck

Attached Thumbnails
Click image for larger version

Name:	BEFORE1.jpg
Views:	235
Size:	69.3 KB
ID:	59257   Click image for larger version

Name:	AFTER1.jpg
Views:	212
Size:	69.3 KB
ID:	59258   Click image for larger version

Name:	BEFORE2.jpg
Views:	192
Size:	69.5 KB
ID:	59259   Click image for larger version

Name:	AFTER2.jpg
Views:	219
Size:	69.7 KB
ID:	59260  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Deepmoney LLM
Elite Quantitative GenAI/LLM
Are there any eval firms that allow you to sink to your …
Traders Hideout
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Better Renko Gaps
The Elite Circle
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
  #302 (permalink)
 maxreturn 
Grand Rapids, Michigan, United States
 
Experience: Intermediate
Platform: NinjaTrader
Trading: TF, 6E
Posts: 319 since Dec 2010
Thanks Given: 264
Thanks Received: 114

Picture before hitting f5 key and after in one tick correction mode. Same issue as with strategy mode.

Attached Thumbnails
Click image for larger version

Name:	OTCBEFORE.jpg
Views:	202
Size:	67.9 KB
ID:	59263   Click image for larger version

Name:	OTCAFTER.jpg
Views:	188
Size:	67.6 KB
ID:	59264  
Reply With Quote
  #303 (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



maxreturn View Post
Hello Fat Tails. Yesterday afternoon I noticed that the visual SMA in strategy mode repainted plots a couple of times when I hit the f5 key. This morning I decided to watch the behavior of this indicator in both visual and strategy mode. I selected two times at random, took a before picture, then hit f5, then took an after picture. The indicator in visual mode seems to be working fine but in both instances, the plots in strategy mode changed. I've attached the before and after pictures. The first instance = before1 and after1. Second instance = before2 and after2.

Best Regards
Chuck

The critical point is the transition from historical to real-time data, i.e. the moment you open or reload the chart. If you press F5 you replace real-time data with historical data. Also you shift the hybrid bar - the bar which NinjaTrader builds from historical and real-time ticks to the right.

If you observe differences after pressing F5, there can be three reasons:

(1) With F5 you replace real-time data with historical data. Historical bars are built from 1 tick, while real-time bars are built from many ticks, as many ticks as were observed during the bar period. For historical data bars that have the same time stamps will be aligned, while for real-time data this may be different. The NinjaTrader timestamps have a 1-second resolution. On historical data you lose sub-second information.

(2) NinjaTrader is event driven. As historical data is built from 1 tick, you know that the bar is complete, when this 1 tick is detected. This means that you can perform the indicator calculations with every tick and display the values on the chart. Real-time bars are built from many ticks. Although it would be theoretically possible for some bar types to count the ticks or the volume, you will not know for all bar types, when they are completed.

-> for minute bars you will have to wait for the first tick of the next minute to be able to perform calculations for the previous minute bar
-> for range bars you have to wait that the range is exceeded to calculate the value for the previous range bar

This means that you have a 1-tick delay on real-time data, which is due to the inherent logic of some bar types or NinjaTrader architecture, which is event driven.

When you press F5 in some cases the lag created by real-time data can be reduced an the indicator may show 1 tick earlier on historical data.

(3) Your observation relates to the hybrid bar. When you press F5 NinjaTrader inserts an artificial historical tick and then completes the bar with real-time ticks. This additional historical tick "irritates" the multi-timeframe indicator and it inserts an additional "node", which can be seen on the chart.

Once you press F5 the additional "node" will disappear, and eventually the lag will be reduced a little.

Conclusion:

You just need to accept that at the intersection of historical and real-time data there is a little "node", where the indicator deviates from its real value. If you do not press F5 all the time, this interface between historical and real-time data moves away and leaves the chart on the left side.

Example attached.

Attached Thumbnails
Click image for larger version

Name:	Transition Chart.jpg
Views:	221
Size:	108.4 KB
ID:	59278   Click image for larger version

Name:	Historical Chart.jpg
Views:	207
Size:	101.7 KB
ID:	59279  
Started this thread Reply With Quote
Thanked by:
  #304 (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


maxreturn View Post
Picture before hitting f5 key and after in one tick correction mode. Same issue as with strategy mode.

Referring to my previous post:

In one-tick-correction mode, the indicator will not be affected by the issues (1) and (2) as it is allowed to repaint one tick and can therefore compensate the lag on real-time data.

The issue(3) related to the transition bar remains, although I tried to reduce the impact of the artificial historical tick inserted. Your charts do not show a significant deviation except for the last bar, which is difficult to judge as it is incomplete.

In general the indicator should not change values when used in one-tick-correction or visual mode, maybe with the exception of the transition bar between historical and real-time data.

Started this thread Reply With Quote
Thanked by:
  #305 (permalink)
 maxreturn 
Grand Rapids, Michigan, United States
 
Experience: Intermediate
Platform: NinjaTrader
Trading: TF, 6E
Posts: 319 since Dec 2010
Thanks Given: 264
Thanks Received: 114

Hello Fat Tails. Thanks for the quick response. I figured that this was due to Ninja Trader limitations. I'm not a programmer but I think I understand the meat of what you were trying to tell me. If I understand you correctly this little aberration will correct itself once the next node appears?

I've attached another example of a recent before and after picture using the one tick correction mode. As you can see this difference is more dramatic. From where I am sitting it just appears that if one is depending on this indicator to trade real time, the only reliable mode is the visual mode.

Best Regards
Chuck

Attached Thumbnails
Click image for larger version

Name:	OTCBEFORE.jpg
Views:	190
Size:	65.4 KB
ID:	59291   Click image for larger version

Name:	OTCAFTER.jpg
Views:	179
Size:	67.3 KB
ID:	59292  
Reply With Quote
  #306 (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


maxreturn View Post
Hello Fat Tails. Thanks for the quick response. I figured that this was due to Ninja Trader limitations. I'm not a programmer but I think I understand the meat of what you were trying to tell me. If I understand you correctly this little aberration will correct itself once the next node appears?

I've attached another example of a recent before and after picture using the one tick correction mode. As you can see this difference is more dramatic. From where I am sitting it just appears that if one is depending on this indicator to trade real time, the only reliable mode is the visual mode.

Best Regards
Chuck

Maybe it is related to the way Renko bars are built. This can induce an additional lag. Personally I would not try to calculate moving averages from range or Renko bars, as you cannot really know how NinjaTrader builds them. If you use SMA from minute, tick or volume bars and apply them to other chart types you should be fine.

For example I have made tests calling the indicator, when it was loading range or Renko bars. There were huge errors, so you cannot call the indicator when these bar types are selected. The next version will take that into account as well.

By the way, if they are errors from retrieving a value for the hybrid bar, this error should correct itself over 3 secondary bars, as you have selected a bar period of 3.

Started this thread Reply With Quote
Thanked by:
  #307 (permalink)
 rdtw 
Des Moines Iowa United States
 
Experience: Intermediate
Platform: NT Ensign MT4
Trading: drums
Posts: 120 since Sep 2010
Thanks Given: 14,996
Thanks Received: 38


Fat Tails View Post
Maybe it is related to the way Renko bars are built. This can induce an additional lag. Personally I would not try to calculate moving averages from range or Renko bars, as you cannot really know how NinjaTrader builds them. If you use SMA from minute, tick or volume bars and apply them to other chart types you should be fine.

For example I have made tests calling the indicator, when it was loading range or Renko bars. There were huge errors, so you cannot call the indicator when these bar types are selected. The next version will take that into account as well.

By the way, if they are errors from retrieving a value for the hybrid bar, this error should correct itself over 3 secondary bars, as you have selected a bar period of 3.

Hi Fat Tails,

Can you please help me understand ... lag and errors can occur when a SMA is from or applied to range or Renko bars? If the SMA is from minute, tick or volume bars and applied to a range or Renko, would one still experience possible lag and errors?

Thank you for your time.

Reply With Quote
  #308 (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


rdtw View Post
Hi Fat Tails,

Can you please help me understand ... lag and errors can occur when a SMA is from or applied to range or Renko bars? If the SMA is from minute, tick or volume bars and applied to a range or Renko, would one still experience possible lag and errors?

Thank you for your time.

Any SMA lags by itself. That was not your question.

If you have a multi-timeframe indicator, it calculates an indicator values from a secondary bar series and this indicator value is only displayed when the next bar of the primary series closes. For simplicity, let us imagine a 2-min and a 3-min bar series. The 3-min bar series is used to calculate the indicator value. The result is then transferred to the 2-min bar series, which is visible on the chart for display.

Now imagine a common bar close at the full hour (60 can be divided by 2 and 3), for example at 8:00 AM. Then the next indicator value from the 3 minute bar series will be available at 8:03 AM. But there is no 2-minute bar closing at 8:03 AM, so this result will be transferred to the 8:04 bar of the visible bar series. The display of the result therefore lags by 1 minute.

When you plot an indicator from a different timeframe on your chart, you have the choice between

-> adding a secondary bar series to your chart (1)
-> adding a multi-timeframe indicator to your chart (2)

(1) will create no additional lag, but may cause non-equidistant bar spacing
(2) will maintain equidistant bar spacing, but create an additional lag

You simply can't have it all!

Due to the architecture of NinjaTrader the indicator may temporarily deviate a bit at the intersection of historical and real-time data. But this is just one point on your chart, i.e the moment when you connect. The VisualSMA and VisualEMA let you identify this point via the color of the nodes, as each node will show whether it is a historical or a real-time node.

Otherwise it is best to calculate the VisualSMA from minute, tick or volume charts. This is particularly true if you want to access the indicator in strategy mode from within a strategy.

Started this thread Reply With Quote
Thanked by:
  #309 (permalink)
 maxreturn 
Grand Rapids, Michigan, United States
 
Experience: Intermediate
Platform: NinjaTrader
Trading: TF, 6E
Posts: 319 since Dec 2010
Thanks Given: 264
Thanks Received: 114

Hello Fat Tails. I'm hoping you can add this request to your "to do" list. For a while now I have been experimenting with Zach's Multi MA Price Channel on a 12 tick renko chart (see image1). I'm not necessarily interested in all the ma types but would simply like to have a "MTF Visual SMA With Bands" indicator using the parameters and plots in image2.
Thanks for your consideration.

Best Regards
Chuck

Attached Thumbnails
Click image for larger version

Name:	Image1.jpg
Views:	254
Size:	99.5 KB
ID:	59485   Click image for larger version

Name:	Image2.JPG
Views:	234
Size:	151.3 KB
ID:	59486  
Reply With Quote
Thanked by:
  #310 (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



maxreturn View Post
Hello Fat Tails. I'm hoping you can add this request to your "to do" list. For a while now I have been experimenting with Zach's Multi MA Price Channel on a 12 tick renko chart (see image1). I'm not necessarily interested in all the ma types but would simply like to have a "MTF Visual SMA With Bands" indicator using the parameters and plots in image2.
Thanks for your consideration.

Best Regards
Chuck

Actually this would not be too difficult to do, but I still have too many other construction sites.

The easiest approach would be to make the VisualSMA callable. I actually have a version that can be called by another indicator. The only problem is the repainting of the distance between the last value and the prior node. So if the indicator is called by another indicator

-> the calling indicator needs to repaint synchronously with the VisualSMA, to do so a parameter needs to be transmitted specifying the number of bars being repainted
-> calling the VisualSMA will only work, if the latter loads minute, tick or volume bars (not possible to call it when it loads range or Renko bars), this is due to the NinjaTrader architecture

Sorry, I still need to update a lot of other indicators as well.

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