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

  #421 (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


michaelf View Post
Hi @Fat Tails

do you consider to convert your VisualEMA and VisualSMA to NT8.

Missing does 2 a lot

Thanks
Michael


I have planned to do so, but still struggling with other work.


Harry

Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #422 (permalink)
ellinas
Cyprus, Nico
 
Posts: 33 since Mar 2019
Thanks Given: 10
Thanks Received: 9

Hello,

I am trying to download the codes of the VisualEMAX1 and VisualEMAX2 indicators in order me to use them into my strategy.
Alternatively (if not possible the codes) please provide me these indicators in a such a way in order me to be able to use them into my code of my automated strategy (I use NinjaTrader 7).

Thank you / George



Fat Tails View Post
This is another experimental indicator. It allows to display any EMA on your chart, for example you can display

- a 3 range EMA on a 275 tick chart
- a 60 min EMA on a 200 volume chart
- a 60 min EMA on a 15 min chart


Allows to plot indicators based on different bar types and time frames on evenly spaced charts

You can also display multi time frame indicators by adding a second data series to your chart. For example, if you trade a tick chart you can add a 60 min bar series and then display an EMA(9) calculated from that 60 min series. The only problem you will encounter is that your bars will be unevenly spaced. With a multi time frame indicator, you avoid this uneven spacing. You typically pay with a little lag, which can be neglected for larger time frames.


Three modes to display the EMA

The indicator has three modes to demonstrate the behavior of the dual bar series indicator.

StrategicMode: The first bar series collects the values from the secondary series with the little lag already described. The chart attached shows this slightly lacking series in orange.

FirstTickMode: To avoid the lag for minute bars with identical time stamps, the indicator is allowed to repaint the indicator value for the prior bar, after the first tick of the current bar has been registered. The chart below shows the first tick mode in red. You will not that the lag has been reduced.

Visual Mode: To make it easier to use the indicator visually, the indicator interpolates the distance between two consecutive bars of the secondary bar series. The interpolation algorithm works in real-time and simulates the CalculateOnBarClose = false mode for the indicator relative to the secondary bar series. It repaints the current leg of the indicator back to the prior bar of the secondary series. The interpolation adapts itself to equidistant or non-equidistant charts.


Something to play with

I have attached the indicator. It is a protected assembly, which will only run on NT 7.0.1000.3 or later, but which is licence free. The chart below has the indicator applied three times. The blue line is the EMA in VisualMode, which is easier to use than the step functions that can be typically seen in other MTF indicators.

It is the first indicator of this type that I have coded, so please report any issues.


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



ellinas View Post
Hello,

I am trying to download the codes of the VisualEMAX1 and VisualEMAX2 indicators in order me to use them into my strategy.
Alternatively (if not possible the codes) please provide me these indicators in a such a way in order me to be able to use them into my code of my automated strategy (I use NinjaTrader 7).

Thank you / George

Those were experimental indicators which are no longer up-to-date. I do not even have them anymore.

VisualEMA:

The main idea of the VisualEMA - hence the name - was to overcome the problem of non-equidistant bar spacing. This is a specific problem of NinjaTrader 7.
Example: You wish to display an EMA(5) calculated from 1 min bars on a renko chart. To do so you would

- add a secondary bar series of 1 min bars to your renko chart
- then set the secondary bars to transparent
- then apply the indicator to the invisible secondary bars

So far so good. The only problem that you will get is the distortion of the primary bars. Your chart will look similar to a battlefield after the fight. The VisualEMA addresses this problem, as it loads the secondary bars and calculates indicator values from those bars. The primary bars are no longer distorted and your chart will look nice and clean as always.

Repainting with default settings

In case you add a secondary bar series to the chart, the two last bars of the secondary bars would typically be at a larger distance than the primary bars. Therefore the VisualEMA will draw the last leg of the indicator plot over a larger distance - for example five primary bars. This means that the VisualEMA is a repainting indicator relative to the primary bars (it would not be repainting relative to the secondary bars). Repainting indicators cannot be easily used for a strategy.

Strategy Mode

Therefore the VisualEMA has a strategy mode (step mode) that allows its use with an automated strategy. You may visualize the strategy mode by adding the VisualEMA to a chart.
You will now see a lagging indicator that paints a steplike pattern on the chart. You may only use the VisualEMA with a strategy, if it is set to strategy mode.

Recommendation

If you add the VisualEMA to a strategy

- the strategy loads the Visual EMA
- the VisualEMA then loads the secondary bars

This is definitely not best practice. I would suggest to let the strategy load the secondary bars, and then apply a standard EMA to the secondary bars. This will lead to the same result as adding the VisualEMA, but it is a much cleaner solution. Furthermore, I would recommend to stop using NinjaTrader 7 and switch to NinjaTrader 8.

Started this thread Reply With Quote
Thanked by:
  #424 (permalink)
ellinas
Cyprus, Nico
 
Posts: 33 since Mar 2019
Thanks Given: 10
Thanks Received: 9

Regarding the VisualEMAX1 indicator : What I want to do is to write a simple piece of code with CrossAbove/Below of 2 different VisualEMAX1 indicators (with different parameters each one of them). Please see attaced chart. The problem is that this indicator is appeared ONLY into my chart's indicators list and NOT in my "Edit indicators" list, so I cannot code them in my automated strategy. Is there any way this indicator to be appeared in my "Edit indicator" list ?
Thanks/George



Fat Tails View Post
Those were experimental indicators which are no longer up-to-date. I do not even have them anymore.

VisualEMA:

The main idea of the VisualEMA - hence the name - was to overcome the problem of non-equidistant bar spacing. This is a specific problem of NinjaTrader 7.
Example: You wish to display an EMA(5) calculated from 1 min bars on a renko chart. To do so you would

- add a secondary bar series of 1 min bars to your renko chart
- then set the secondary bars to transparent
- then apply the indicator to the invisible secondary bars

So far so good. The only problem that you will get is the distortion of the primary bars. Your chart will look similar to a battlefield after the fight. The VisualEMA addresses this problem, as it loads the secondary bars and calculates indicator values from those bars. The primary bars are no longer distorted and your chart will look nice and clean as always.

Repainting with default settings

In case you add a secondary bar series to the chart, the two last bars of the secondary bars would typically be at a larger distance than the primary bars. Therefore the VisualEMA will draw the last leg of the indicator plot over a larger distance - for example five primary bars. This means that the VisualEMA is a repainting indicator relative to the primary bars (it would not be repainting relative to the secondary bars). Repainting indicators cannot be easily used for a strategy.

Strategy Mode

Therefore the VisualEMA has a strategy mode (step mode) that allows its use with an automated strategy. You may visualize the strategy mode by adding the VisualEMA to a chart.
You will now see a lagging indicator that paints a steplike pattern on the chart. You may only use the VisualEMA with a strategy, if it is set to strategy mode.

Recommendation

If you add the VisualEMA to a strategy

- the strategy loads the Visual EMA
- the VisualEMA then loads the secondary bars

This is definitely not best practice. I would suggest to let the strategy load the secondary bars, and then apply a standard EMA to the secondary bars. This will lead to the same result as adding the VisualEMA, but it is a much cleaner solution. Furthermore, I would recommend to stop using NinjaTrader 7 and switch to NinjaTrader 8.


MY CHART 1

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


ellinas View Post
Regarding the VisualEMAX1 indicator : What I want to do is to write a simple piece of code with CrossAbove/Below of 2 different VisualEMAX1 indicators (with different parameters each one of them). Please see attaced chart. The problem is that this indicator is appeared ONLY into my chart's indicators list and NOT in my "Edit indicators" list, so I cannot code them in my automated strategy. Is there any way this indicator to be appeared in my "Edit indicator" list ?
Thanks/George]


The code comes as an assembly and cannot be edited. As I have explained before, you do not need this indicator for writing a strategy. The strategy may not call it in visual mode. Simply let the strategy add a secondary bar series. Then directly apply the EMA to the secondary bars added. This is a much more reasonable approach and will give you at least similar results. In my opinion it is even an advantage to let the strategy add the secondary bars. Please compare

(1) Using VisualSMA: Strategy adds an indicator to the primary bars. Indicator loads secondary bars to calculate EMA. Result is then returned when the primary bars are called. This approach has two inconvenients

- the bars are loaded by the indicator which is loaded by the strategy
- in case you run it in Calculate.OnBarClose, indicator values calculated from secondary bars are only made available when the primary bar closes (additional lag)


(2) Adding secondary bars via strategy: Indicator is applied to secondary bars and indicator value is returned when the secondary bar closes.


Solution(2) should be preferred over solution(1), because it is a more stable and simpler approach which also does not create an additional lag. Please keep in mind, that the VisualEMA only had the purpose to address the non-equidistant bar spacing.

In case you insist using the VisualEMA, you may create a simple strategy with the strategy builder and unlock it. This will show you how to access the plots.

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