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

  #361 (permalink)
 
sudhirc's Avatar
 sudhirc 
detroit,mi
sc
 
Experience: Intermediate
Platform: NT
Broker: NT
Trading: ES
Frequency: Every few months
Duration: Hours
Posts: 417 since Sep 2011
Thanks Given: 1,709
Thanks Received: 471

@Fat Tails

Rather than importing directly via File->Utilities->Import Ninja Script i unziped the attachment and copied the .cs folder into NT and opened through Edit NinjaScript and then complied.
The following are the errors in detail.


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
  #362 (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


sudhirc View Post
@Fat Tails

Rather than importing directly via File->Utilities->Import Ninja Script i unziped the attachment and copied the .cs folder into NT and opened through Edit NinjaScript and then complied.
The following are the errors in detail.


You have probably an old version of the VisualSMA installed. Please uninstall vie File -> Utilities -> Remove Ninjascript Assembly.

Then import the latest version (August 2012) from the download section of this forum and it should work.

Prior to removing the assembly you will have to delete the access indicator, otherwise the assembly cannot be removed.

Started this thread Reply With Quote
Thanked by:
  #363 (permalink)
symphys
Earth
 
Posts: 18 since Feb 2010
Thanks Given: 3
Thanks Received: 6


Took a while to read the whole thread. And even after reading it I do not fully understand all the stuff involved.

But the indicator works and I'm really thankful Fat Tails!

Reply With Quote
Thanked by:
  #364 (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

Hello Fat Tails,

I finally downloaded and installed the latest version of both VisualSMAMTF and VisualEMAMTF. I followed the directions carefully and removed the previous assembly and restarted NT. All were working fine with the old version. Now I am having the same problem with both SMA and EMA. I want to plot a bar graph on an indicator panel with the settings shown in the attached screen shot of the “Indicator Setup Menu.” I am trying to plot an 8 period Renko type onto a 450 period Tick chart. What I get is the result shown in attachment labeled “Renko Setting.” I.e., nothing, not even the proper label. I merely change the period type from Renko to Minute and everything looks fine, as shown in the attached screen shot labeled “Minute Setting.” A list of the errors shown in the NinjaTrader Log is shown in the fourth screen shot.

Any ideas as to what is going on?

Thanks for your help and the wonderful indicators. Looking forward to getting back to “normal.”

HDT

Attached Thumbnails
Click image for larger version

Name:	Indicator Setup Menu.png
Views:	223
Size:	22.8 KB
ID:	89844   Click image for larger version

Name:	Renko Setting.png
Views:	369
Size:	112.1 KB
ID:	89845   Click image for larger version

Name:	Minute Setting.png
Views:	315
Size:	110.8 KB
ID:	89846   Click image for larger version

Name:	Errors For Vis EMA SMA.png
Views:	216
Size:	78.0 KB
ID:	89847  
Reply With Quote
  #365 (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


HighDesertTrader View Post
Hello Fat Tails,

I finally downloaded and installed the latest version of both VisualSMAMTF and VisualEMAMTF. I followed the directions carefully and removed the previous assembly and restarted NT. All were working fine with the old version. Now I am having the same problem with both SMA and EMA. I want to plot a bar graph on an indicator panel with the settings shown in the attached screen shot of the “Indicator Setup Menu.” I am trying to plot an 8 period Renko type onto a 450 period Tick chart. What I get is the result shown in attachment labeled “Renko Setting.” I.e., nothing, not even the proper label. I merely change the period type from Renko to Minute and everything looks fine, as shown in the attached screen shot labeled “Minute Setting.” A list of the errors shown in the NinjaTrader Log is shown in the fourth screen shot.

Any ideas as to what is going on?

Thanks for your help and the wonderful indicators. Looking forward to getting back to “normal.”

HDT

The indicator does not work with Renko bars, I have to take out that options. This is due to a NinjaTrader limitation, as normally you cannot add other bar series dynamically.

There would be two workarounds possible to solve the problem:

-> add as many secondary bar series to the indicator as there are options
-> code a VisualSMA which works on RenkoBars only

I have not had the time to further enquire into this. I am currently waiting on feedback on another problem, which limits the use of the indicator when called by a strategy.

Started this thread Reply With Quote
Thanked by:
  #366 (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 is an update of the VisualSMA and VisualEMA indicators.

Those who dare please test:

- I have removed the option for Renko bars, this did not work anyhow, as the Renko bars cannot be added to the indicator dynamically.
- There was a bug discovered by @mborin, which prevented that the indicator could be accessed via a strategy using Rising(VisualSMA) or Rising(VisualEMA).

The indicators should work now. Those who dare, please test the attached assemblies and let me know whatever happens.

Before installing the new versions, please remove the prior versions via File -> Utilities -> Remove Ninjascript Assembly.

Attached Files
Elite Membership required to download: VisualEMA.zip
Elite Membership required to download: VisualSMA.zip
Started this thread Reply With Quote
  #367 (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

I have updated the indicators in the download section. They are identical with the versions in the previous post # 366.



Started this thread Reply With Quote
  #368 (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

I just want to explain another time, how the indicators work and can be correctly accessed. The explanation refers to the VisualSMA but also applies to the VisualEMA


Strategy mode

Indicator collects data from secondary bar series. When a bar of the secondary bar series is complete, the value is displayed on the chart. This typically results in a step function.


One-Tick Repaint Mode

This mode corrects a weakness of the multi-barseries concept of NinjaTrader. OnBarUpdate() will be triggered for the primary bars and then for the secondary bars. Now imagine that you have a 15 min chart and want to display an hourly SMA. Then t the full hour NinjaTrader will first run the primary bars (allowing to write values to the chart) and then the secondary bars calculating the values from the hourly bars, which it should have written to the primary 15 min bars during the prior run of OnBarUpdate(). This mean that for the bar close of the 15 min bar, the last tick of the 60 min bar cannot be taken into account, because it is not available.

The solution adopted is to repaint the value to the prior bar with the first tick of the new 15 minute bar. The indicator therefore repaints the prior bar a single time, but only uses information from the prior 60 minute bar, which is unfortunately processed after the 15 min bar.

The result also is a step function, but the lag of 1 bar is eliminated when real-time data is processed.


Visual Mode

With each incoming tick the distance between the last node - in the example above that would be the close of the hourly bar - and the current value of the indicator is repainted by using a linear interpolation. In COBC = false mode you can see the last leg moving up and down.


Accessing the indicator

In strategy mode it is pretty easy to access the indicator via another indicator or a strategy. This is possible because the indicator does not repaint. However, there is a limitation. Any multi-timeframe indicator that loads range bars, cannot be properly accessed via another indicator or strategy. Sometimes the indicator values will be vertically shifted, that is the indicator values would be false.

Therefore the VisualSMA cannot be accessed when the period type selected via the indicator parameters is set to "Range".

If you want to access the VisualSMA in One-Tick Repaint or Visual mode you would need to take into account that the indicator repaints. When the indicator is accessed in One-Tick Repaint mode, you need to access the last 2 values for your strategy and let it recalculate. When you access the indicator in Visual mode, things are more complicated, as the indicator repaints over the last swinging leg. Here you would need to call all indicator values that cover this period.

The indicator offers you a Public IntSeries, which can be accessed and which tells you how many bars it paints back for the currennt value. The IntSeries can be accessed as VisualSMA(period, false, false, thisCalcMode, thisPeriodType, thisPeriodValue, thisPriceType).Repaint[0] and then used to collect the last indicator values. You can then use the integer to loop through the bars back to the last node, which is used as anchor point.

For those who are interested I have attached a model indicator that accesses the VisualSMA and plots the values on a chart. Please copy the model indicator into the directory NinjaTrader 7 -> bin -> custom -> Indicator and compile. It will only compile, if you have the VisualSMA installed.

In case that you have installed the model indicator or any other indicator or strategy that accesses the VisualSMA, do not forget to remove those indicators/strategies first before you uninstall the assembly.

Attached Files
Elite Membership required to download: AccessVisualSMA.cs
Started this thread Reply With Quote
  #369 (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,397 since Jun 2009
Thanks Given: 33,173
Thanks Received: 101,537

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
Thanked by:
  #370 (permalink)
 sburtt 
London, UK
 
Experience: Advanced
Platform: NinjaTrader
Trading: EUR/USD
Posts: 58 since Jul 2012
Thanks Given: 3
Thanks Received: 4


Hi guys, I've just finished reading this post. I must say it's really great. Thanks

I don't have strong programming skills and I am struggling trying to code a MTF strategy in NT7. I am sure this is simple and really would appreciate your help.

I have a few strategies that run on 10-15 min time frames, however I notice there are multiple fake signals that occur due to the fact that the strategies take-profit is very close and NT7 often enters&exits the trade within the same candle, ignoring the real price path. I think this issue could easily be solved by working on a Multi-Time-Frame Strategy. I tried using the Visual EMA when coding my strategy but it doesn't work. Probably because I am using the wizard to create the new strategy.

Lets assume I want to run the below strategy on 1 min time frame, but I want to use indicators (in the example below the 25 and 50 SMA) that refers to a 15 min time frame, and ALSO that I want to enter in position not more than once every 15 minutes. Could somebody please help me to figure out what code to use:

protected override void OnBarUpdate()
{
// Condition set 1
if (SMA,50 [0] > SMA,50 [1]
&& Close[0] > SMA, 25 [0])
{
EnterLongLimit(DefaultQuantity, SMA,25 [0], "");


Thanks for your help. This might be a stupid request but it's driving me crazy! Thanks

Reply With Quote




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