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 188,581 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

  #121 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,440 since Jun 2009
Thanks Given: 33,207
Thanks Received: 101,599


Fat Tails View Post
Have modified the indicator code to include 1-tick repainting in VisualMode and FirstTickMode for other bar types than fixed period bars.

The 1-tick repainting will be activated, when

-> the primary bar series and the secondary bar series called by the indicator use the same bar type
-> the closing time of the primary and secondary candles is identical
-> VisualMode or FirstTickMode is selected

In StrategyMode nothing will be repainted, but the result of the calculation from the secondary bar series will only be used for the next bar of the primary bars.

Update notifications sent.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Exit Strategy
NinjaTrader
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
22 thanks
My NQ Trading Journal
16 thanks
HumbleTraders next chapter
9 thanks
  #122 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217

Fat Tails,

I'm using the latest version of the anaVisualSMA and today I noticed the following on my charts :

You can see on the attached pictures that the first one(TRADE#8) was taken yesterday while I was trading, and the second one was taken at the exact same spot today(after shutting down my computer and closing ninja).

The VisualSMA's look different but everything else is in place.

Thanks.

B

Attached Thumbnails
Click image for larger version

Name:	TRADE#8.JPG.jpg
Views:	234
Size:	98.5 KB
ID:	48266   Click image for larger version

Name:	Capture.JPG
Views:	252
Size:	89.7 KB
ID:	48267  
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #123 (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



Braulio View Post
Fat Tails,

I'm using the latest version of the anaVisualSMA and today I noticed the following on my charts :

You can see on the attached pictures that the first one(TRADE#8) was taken yesterday while I was trading, and the second one was taken at the exact same spot today(after shutting down my computer and closing ninja).

The VisualSMA's look different but everything else is in place.

Thanks.

B

On the charts

-> it is not clear which are the VisualSMAs
-> you have hidden all indicator settings, which makes it impossible to analyze any problem

Please, if you post a chart next time, make sure that the indicator settings are visible and that the indicators are labeled.

Started this thread Reply With Quote
  #124 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217

Sorry about that...here goes.

I've also attached the template I used.

Thanks.


Fat Tails View Post
On the charts

-> it is not clear which are the VisualSMAs
-> you have hidden all indicator settings, which makes it impossible to analyze any problem

Please, if you post a chart next time, make sure that the indicator settings are visible and that the indicators are labeled.


Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	214
Size:	113.5 KB
ID:	48269  
Attached Files
Elite Membership required to download: TESTING.xml
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #125 (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


Braulio View Post
Sorry about that...here goes.

I've also attached the template I used.

Thanks.

I have checked it and not found a problem so far. If you use multi-timeframe indicators, range charts are quite particular. For minute, tick and volume charts, you can find the higher time-frame bars by combining two of them. For example two 5-minute bars will make up for one 10-minute bar, three 233-tick bars will make up for one 699-tick bar etc. However, for range bars this relationship does not hold. In a sideways moving market it may well take 10 or 15 4-range bars to produce an 8-range bar, and the typical price of the current 8-range bar remains constant.

The template abuses the VisualSMA to find the typical price of a secondary bar series. Honestly this is nonsense. It takes a few minutes to code an indicator, which displays the typical price of the a secondary and tertiary bar series. No need to use a complex indicator with interpolation algorithms. But of course the VisualSMA(1) will give you the close, if you apply it to the close, or the typical price, if you apply it to the typical price.


If you want to check the values of the VisualSMA, this is what you can do:

Just for testing, add two new DataSeries to your chart, one with 8-range bars and another one with 10-range bars. Then apply a SMA(Typical, 1) to each of the DataSeries. The values shown should be identical with the values displayed by the VisualSMA in visual mode. If they are not, something is wrong.

Started this thread Reply With Quote
Thanked by:
  #126 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217

Thank you for the explanation and honest comments.

I've attached 3 more trades where the VisualEMA's do not match the before and after restarting Ninja.

I've also noticed that they normally match my trades before 01:30PM(GMT) before big news came out. See the pic I've attached called 'Going Crazy', the EMA's are completely off, am I right? Are they plotting correctly there?

I followed you suggestion on the last pic and yes, they seem to plot at the exact same place on both dataseries, but if you don't mind me saying (you're the expert here)... that doesn't mean there isn't a problem and I believe there is, we just haven't figured out how to find it. There has to be an explanation for the difference we see on the charts!

Here's what I think might be causing this:
1. From your explanation I understood that range bars are quite particular and not as linear as minute or tick. So although the plotting of the VisualSMA may seem OK now, in real-time things might be different.
2. Or yesterday was a special day right at 01:30PM, where the market went bezerk and messed everything up. I would sure like to have a picture right at that time for before/after comparison of the VisualSMA's.

There's one other thing we can try : run market replay and see what happens.

But from what I understood and please correct me if I'm wrong, you created these VisualSMA and VisualEMA indicators primarily not for equal dataseries and same bar types like 8range+10range but different ones like 8range+5min or 377tick+5min, am I right?

Also, if I'm not asking for too much (and I understand if I am) would you point me in the right direction about coding what you've mentioned? something that displays the typical price of the a secondary and tertiary bar series? I have some coding experience and with your help I could try making a simpler version. I tried a while ago to code a MTF indicator but as soon as I added a secondary dataseries I didn't know how the reference both in the code.

Thank you.

B


Fat Tails View Post
I have checked it and not found a problem so far. If you use multi-timeframe indicators, range charts are quite particular. For minute, tick and volume charts, you can find the higher time-frame bars by combining two of them. For example two 5-minute bars will make up for one 10-minute bar, three 233-tick bars will make up for one 699-tick bar etc. However, for range bars this relationship does not hold. In a sideways moving market it may well take 10 or 15 4-range bars to produce an 8-range bar, and the typical price of the current 8-range bar remains constant.

The template abuses the VisualSMA to find the typical price of a secondary bar series. Honestly this is nonsense. It takes a few minutes to code an indicator, which displays the typical price of the a secondary and tertiary bar series. No need to use a complex indicator with interpolation algorithms. But of course the VisualSMA(1) will give you the close, if you apply it to the close, or the typical price, if you apply it to the typical price.


If you want to check the values of the VisualSMA, this is what you can do:

Just for testing, add two new DataSeries to your chart, one with 8-range bars and another one with 10-range bars. Then apply a SMA(Typical, 1) to each of the DataSeries. The values shown should be identical with the values displayed by the VisualSMA in visual mode. If they are not, something is wrong.


Attached Thumbnails
Click image for larger version

Name:	TRADE#4.JPG.jpg
Views:	202
Size:	101.3 KB
ID:	48288   Click image for larger version

Name:	TRADE#4_After.JPG
Views:	163
Size:	115.9 KB
ID:	48289   Click image for larger version

Name:	TRADE#5.JPG
Views:	197
Size:	95.7 KB
ID:	48290   Click image for larger version

Name:	TRADE#5_After.JPG
Views:	182
Size:	109.0 KB
ID:	48291   Click image for larger version

Name:	TRADE#6.JPG.jpg
Views:	172
Size:	96.1 KB
ID:	48292   Click image for larger version

Name:	TRADE#6_After.JPG.jpg
Views:	161
Size:	116.1 KB
ID:	48293   Click image for larger version

Name:	Going Crazy.JPG
Views:	184
Size:	170.5 KB
ID:	48294   Click image for larger version

Name:	Data Series.JPG
Views:	208
Size:	197.5 KB
ID:	48295  
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #127 (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


Braulio View Post
Thank you for the explanation and honest comments.

I've attached 3 more trades where the VisualEMA's do not match the before and after restarting Ninja.

I've also noticed that they normally match my trades before 01:30PM(GMT) before big news came out. See the pic I've attached called 'Going Crazy', the EMA's are completely off, am I right? Are they plotting correctly there?

I followed you suggestion on the last pic and yes, they seem to plot at the exact same place on both dataseries, but if you don't mind me saying (you're the expert here)... that doesn't mean there isn't a problem and I believe there is, we just haven't figured out how to find it. There has to be an explanation for the difference we see on the charts!

@ Braulio: Lots of details, I would be interested to discuss this via Skype. The multi-timeframe indicators are sensitive to the use of real-time versus historical data, and the results may also depend on the session template used.

Looking at your charts in detail: Chart 1, 3, 5 and 7 do not show indicator settings. The indicators are probably calculated from real-time data. The indicator values do not look correct, but again, I cannot check the settings.

The charts 2, 4, 6, and 8 look about right. In particular chart 8 confirms that the VisualSMA displays correct values on historical data. The SMA on the lower panel is set to CalculateOnBarClose = true, which explains that the last swing is missing.

So if there is a problem with the indicator, the problem only occurs on real-time data. I can only check this, when the market is open, and then the easiest way to do it would be to run the template of chart 8 and compare the visual appearance of the VisualSMA and the SMA, which is directly applied to an 8-range chart.


Braulio View Post
Here's what I think might be causing this:
1. From your explanation I understood that range bars are quite particular and not as linear as minute or tick. So although the plotting of the VisualSMA may seem OK now, in real-time things might be different.
2. Or yesterday was a special day right at 01:30PM, where the market went bezerk and messed everything up. I would sure like to have a picture right at that time for before/after comparison of the VisualSMA's.

1. This is not specifically related to range bars. If there is a problem, it occurs with real-time data only and will affect various bar types.

2. Do not know.


Braulio View Post
There's one other thing we can try : run market replay and see what happens.

But from what I understood and please correct me if I'm wrong, you created these VisualSMA and VisualEMA indicators primarily not for equal dataseries and same bar types like 8range+10range but different ones like 8range+5min or 377tick+5min, am I right?

Market replay makes sense. Try to run the VisualSMA and the SMA on an 8-range chart in parallel with market replay. The market replay will use real-time data, so that should reproduce the problem.

The indicators can be used for equal dataseries and different dataseries. For equal dataseries I have another, simpler indicator, which can be used instead.


Braulio View Post
Also, if I'm not asking for too much (and I understand if I am) would you point me in the right direction about coding what you've mentioned? something that displays the typical price of the a secondary and tertiary bar series? I have some coding experience and with your help I could try making a simpler version. I tried a while ago to code a MTF indicator but as soon as I added a secondary dataseries I didn't know how the reference both in the code.

Will come back with a separate post.

Started this thread Reply With Quote
Thanked by:
  #128 (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


Braulio View Post
Also, if I'm not asking for too much (and I understand if I am) would you point me in the right direction about coding what you've mentioned? something that displays the typical price of the a secondary and tertiary bar series? I have some coding experience and with your help I could try making a simpler version. I tried a while ago to code a MTF indicator but as soon as I added a secondary dataseries I didn't know how the reference both in the code.

MTF indicators are not easy to understand. First of all, the VisualSMA repaints in VisualMode or FirstTickMode. In only repaints the unstable period, exactly as the SMA does which is directly applied to the 8-range or 10-range bar series. The unstable period covers all 4-range bars, which fall into the time period of the last incomplete 8-range bar. If the market moves sideways, this can be quite a lot.

So if you want to base any strategy on the VisualSMA, you should only use it in StrategyMode. In StategyMode it does not repaint but only uses the indicator value retrieved from the secondary bar series, once the secondary bar has closed. This introduces a lag of one bar.

The repainting in VisualMode only affects the time period from the second but the last (closed) bar of the secondary bars and the last (incomplete) bar of the secondary bars. The repainted values are calculated by two interpolation algorithms, one for equidistant and another one for non-equidistant bar spacing.

If you just want to use the typical price, why the hell would you want to run a multi-timeframe SMA that uses interpolation algorithms?

I have attached a simple indicator that I have coded for one of the other followers of Perry's method. It just shows how you can calculate your arrows by directly using the typical price from the secondary bars to get your entry conditions. Note that the real-time data is not identical with historical data. Historical range bars are 1-tick-bars, real-time data is made up of multi-tick bars. Multi-tick bars can trigger arrows intrabar, which will disappear again once the bar has closed.

The indicator attached draws an arrow up, if the three following conditions are met

(a) the typical price (also known as SMA(Typical,1)) has crossed above the SMA(Typical,3)
(b) the typical price of an 8-range bar is greater than the typical price of the previous 8-range bar
(c) the typical price of a 10-range bar is greater than the typical price of the previous 10-range bar

Down arrows follow a similar logic.

Attached Files
Elite Membership required to download: CrossingArrowsMTF.zip
Started this thread Reply With Quote
  #129 (permalink)
 shah1266 
hartford
 
Posts: 52 since Jun 2011

dont know what you just said Fat brains,but I will throw it on my charts and see if it sticks!

Reply With Quote
  #130 (permalink)
 
Braulio's Avatar
 Braulio 
Portugal
 
Experience: Beginner
Platform: Ninjatrader, Multicharts
Broker: Amp Futures/Zen-Fire
Trading: ES, 6E
Posts: 229 since Aug 2009
Thanks Given: 407
Thanks Received: 217


Charts 1,3,5 are pictures from real-time data.
Charts 2,4,6 with "_After" are historical while disconnected from my datafeed (today).
The settings are the same on all charts from the template I posted.

I also believe the problem only occurs in real-time.

Is the CrossingArrowsMTF the simpler indicator you talk about?
I don't wanna be a party spoiler but I've already identified a situation where the CrossingArrowsMTF should be plotting a down arrow but there isn't one...yes, I'm that fast... see the pic, I also attached the template.

Awesome! I cannot thank you enough for this.

P.S. - will PM my skype ID.

B

EDIT : wait! I just read the conditions....on the attached pic that means only when the Typical(8) is BELOW Typical (10) will the arrow plot? That's why we don't see an arrow on the chart, am I right? If so, we need to change it and add this condition...

EDIT2 : forget the previous edit....that's not true...I just looked at the code and it should be drawing an arrow....

Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	272
Size:	129.4 KB
ID:	48312  
Attached Files
Elite Membership required to download: TESTING.xml
Visit my NexusFi Trade Journal 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