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 189,562 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

  #321 (permalink)
 subterfuge 
uk
 
Experience: Intermediate
Platform: ninja
Broker: amp
Trading: ES
Posts: 179 since Aug 2009

I have a multi-timeframe indicator for metatrader which colours the background of the chart that i'm on, based on the MACD cross of whichever timeframe I choose.

Is there an NT7 version available?

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Cheap historycal L1 data for stocks
Stocks and ETFs
MC PL editor upgrade
MultiCharts
How to apply profiles
Traders Hideout
ZombieSqueeze
Platforms and Indicators
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
  #322 (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,103


subterfuge View Post
I have a multi-timeframe indicator for metatrader which colours the background of the chart that i'm on, based on the MACD cross of whichever timeframe I choose.

Is there an NT7 version available?

As far as I know, MetaTrader only uses minute charts. The best solution depends on your case:

(a) You can calculate the MACD values for a multiple of the original chart period (for example if you have a 5-minute chart, you can calculate the MACD for 10-minute, 15-minute, bars etc. , or if you have a 233-tick chart, you can calculate the MACD based on 466-tick bars, 699-tick bars. Those values can be calculated from the original bar series.

(b) To speed up the indicator you can use a different MACD formula to calculate them from the original bar series only. I have already coded such an indicator.

(c) A real multi-timeframe indicator is more difficult to code and needs to load a secondary bar series. There are some limitations to its use, when being called by a strategy. However you are very flexible, you can for example display an MACD calculated from 1000-volume bars on 8-Renko chart.

Comparison:

(a) requires synthetic bars, indicator coding is difficult

(b) fastest indicator, as there is a specific solution for the MACD (which is itself a derivative of EMAs)

(c) more work to code it properly

The difficulty is the treatment of the unstable period. To understand this imagine a MACD calculated from hourly bars displayed on a 5-min chart. When the hour is not closed, all hourly MACD values are preliminary, so if price moves up or down you would eventually need to repaint until the beginning of the hour, unless you accept to use the value at the end of the prior hour.

The solution (b) is a special approach which will work without repainting.

So you would need to explain, what you really need, and what you don't.

Started this thread Reply With Quote
  #323 (permalink)
 subterfuge 
uk
 
Experience: Intermediate
Platform: ninja
Broker: amp
Trading: ES
Posts: 179 since Aug 2009



Fat Tails View Post
As far as I know, MetaTrader only uses minute charts. The best solution depends on your case:

(a) You can calculate the MACD values for a multiple of the original chart period (for example if you have a 5-minute chart, you can calculate the MACD for 10-minute, 15-minute, bars etc. , or if you have a 233-tick chart, you can calculate the MACD based on 466-tick bars, 699-tick bars. Those values can be calculated from the original bar series.

(b) To speed up the indicator you can use a different MACD formula to calculate them from the original bar series only. I have already coded such an indicator.

(c) A real multi-timeframe indicator is more difficult to code and needs to load a secondary bar series. There are some limitations to its use, when being called by a strategy. However you are very flexible, you can for example display an MACD calculated from 1000-volume bars on 8-Renko chart.

Comparison:

(a) requires synthetic bars, indicator coding is difficult

(b) fastest indicator, as there is a specific solution for the MACD (which is itself a derivative of EMAs)

(c) more work to code it properly

The difficulty is the treatment of the unstable period. To understand this imagine a MACD calculated from hourly bars displayed on a 5-min chart. When the hour is not closed, all hourly MACD values are preliminary, so if price moves up or down you would eventually need to repaint until the beginning of the hour, unless you accept to use the value at the end of the prior hour.

The solution (b) is a special approach which will work without repainting.

So you would need to explain, what you really need, and what you don't.

The one of I have uses minute charts which is fine for me.
I can have open any timeframe chart, and can choose what 'macd timeframe' I want (which colours the background of my current chart, based on whether it's crossed up or down)

The issue of the unstable period is sometimes apparent. Yesterday my chart was light green as if the bigger timeframe MACD was crossed up, although if you went to the bigger timeframe, the macd was actually crossed down.
This I assume is because it was waiting for the bigger timeframe's bar to end. It later re-painted the indicator which I didn't much like.

In an ideal world, there'd maybe be a setting to be able to choose how it handles the unstable period, although for now, whilst playing around with some ideas, I'd be happy with anything.

Reply With Quote
  #324 (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,103


subterfuge View Post
The one of I have uses minute charts which is fine for me.
I can have open any timeframe chart, and can choose what 'macd timeframe' I want (which colours the background of my current chart, based on whether it's crossed up or down)

The issue of the unstable period is sometimes apparent. Yesterday my chart was light green as if the bigger timeframe MACD was crossed up, although if you went to the bigger timeframe, the macd was actually crossed down.
This I assume is because it was waiting for the bigger timeframe's bar to end. It later re-painted the indicator which I didn't much like.

In an ideal world, there'd maybe be a setting to be able to choose how it handles the unstable period, although for now, whilst playing around with some ideas, I'd be happy with anything.

The problem with the unstable period can be handled if you tweak the MACD formula. The MACD is based on a few EMAs and each of the EMAs has a smoothing constant k. All you need to do is to calculate a new smoothing constant for the higher timeframe. For example if your larger timeframe MACD is N times the bar period, then you can calculate the new smoothing constant k_new as 1 - Nth root of (1-k). This will not get you the original MACD, but something that comes very close, and you will benefit from two huge advantages

-> unstable period reduced to the last bar of the smaller timeframe
-> lower CPU load

I have already once tweaked a MACDOverlay, which is shown in the chart attached. However, this is not what you look for, as the four MACDs below are normalized to allow for the overlay. The classic MACD does not have any normalization.


Started this thread Reply With Quote
  #325 (permalink)
 
michaelf's Avatar
 michaelf 
Mérida, Mexico
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8
Broker: NinjaTrader Brokerage
Trading: MNQ
Frequency: Daily
Duration: Minutes
Posts: 559 since Mar 2011
Thanks Given: 1,435
Thanks Received: 581

Hi Fat Tails

short question, for the VisualEMA the data are from LAST, ASK or BID tick.

thanks

Michael

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #326 (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,103


michaelf View Post
Hi Fat Tails

short question, for the VisualEMA the data are from LAST, ASK or BID tick.

thanks

Michael

NinjaTrader does not store historical bid and ask data. The VisualSMA also works with historical data, and does not use bid or ask data. Basically no moving average does.

The Visual SMA loads a secondary bar series (minute, tick, volume, range or Renko) and calculates the moving average by using that bar series. All calculations use the last price traded either historical data from the historical data base, or real-time data when connected to a datafeed or replay data.

The result is then displayed on the chart with the primary bars. The main advantage of the VisualSMA is that you can calculate a moving average from a secondary bar series without paying the price of non-equidistant bar spacing. If you do not mind unevenly spread bars, then you do not need the VisualSMA.

Started this thread Reply With Quote
Thanked by:
  #327 (permalink)
 
michaelf's Avatar
 michaelf 
Mérida, Mexico
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8
Broker: NinjaTrader Brokerage
Trading: MNQ
Frequency: Daily
Duration: Minutes
Posts: 559 since Mar 2011
Thanks Given: 1,435
Thanks Received: 581


Fat Tails View Post
NinjaTrader does not store historical bid and ask data. The VisualSMA also works with historical data, and does not use bid or ask data. Basically no moving average does.

The Visual SMA loads a secondary bar series (minute, tick, volume, range or Renko) and calculates the moving average by using that bar series. All calculations use the last price traded either historical data from the historical data base, or real-time data when connected to a datafeed or replay data.

The result is then displayed on the chart with the primary bars. The main advantage of the VisualSMA is that you can calculate a moving average from a secondary bar series without paying the price of non-equidistant bar spacing. If you do not mind unevenly spread bars, then you do not need the VisualSMA.


When I look under Historical Data Manager, I see Historical Data from Bid and Ask!?

I have a big problem with Last data, it does not record correctely, thats the reason why I asked.

Like you can see on the screenshot, because of the wrong Last data the VisualSMA are a mess.

Perhaps you have an resolution for this or I have to try something else.

Thank you for you time

Michael

Edit: In Data Series, when I have Price based on - Bid, then the indicators are calculated with the Bid data and not with the Last data?

Attached Thumbnails
Click image for larger version

Name:	4 chart.JPG
Views:	273
Size:	343.5 KB
ID:	82635  
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #328 (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,103


michaelf View Post
Edit: In Data Series, when I have Price based on - Bid, then the indicators are calculated with the Bid data and not with the Last data?

That affects just the calculation of RJay'S Renko Hybrid, which are the primary bars. It has no impact on how the indicator calculates, as it always collects the last price.

I still have an issue with my version of the VisualSMA and Renko bars, which I have to check. Will take some time to answer.

Started this thread Reply With Quote
Thanked by:
  #329 (permalink)
 
michaelf's Avatar
 michaelf 
Mérida, Mexico
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader 8
Broker: NinjaTrader Brokerage
Trading: MNQ
Frequency: Daily
Duration: Minutes
Posts: 559 since Mar 2011
Thanks Given: 1,435
Thanks Received: 581

Hi Fat Tails

again me , sorry about that

Small question, on the visual's the nodes are always showed on the input panel, is it posible to change that so they showing always with the line no matter in wich panel they are.

thank you

michael

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


Hi @Fat Tails,

I 'm trying to use "VisualSMA" with displacement (positive number) and there is small issue with line plot color (last bar only) that paints with default gray color instead the selected rising/falling colors.
I've noticed that this behavior exist in all indicators that use "PlotColors[0][x]"
And my way to solve this in my indicators, is to use the inverse displacement value in "PlotColors"

I hope you will have time to check this issue.
Thanks

Erez

 
Code
protected override void OnStartUp(){PhaseShift = -1 * Displacement;}

 protected override void OnBarUpdate(){PlotColors[0][PhaseShift]}

Attached Thumbnails
Click image for larger version

Name:	VisualSMA.png
Views:	222
Size:	184.8 KB
ID:	85101  
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