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

  #71 (permalink)
 SARdynamite 
Belgium
 
Experience: Advanced
Platform: SaxoTrader
Broker: SaxoBank
Trading: ESTX
Posts: 289 since Dec 2009
Thanks Given: 243
Thanks Received: 110


Fat Tails View Post
The indicator currently allows you to set a starting time for an anchor point, but then will use the same starting time for every day. Of course, it is possible to add many other options, maybe I will do that in my second life....

Lol thanks again for your help. I am going to test this tomorrow

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Increase in trading performance by 75%
The Elite Circle
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
MC PL editor upgrade
MultiCharts
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
15 thanks
GFIs1 1 DAX trade per day journal
15 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #72 (permalink)
 Prtester 
SE-Asia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Amp
Trading: ES
Posts: 151 since Jun 2009
Thanks Given: 66
Thanks Received: 124


gomi View Post
Here's my contribution : a class GomMultiTFIndicator you can derive from.
This class allows you to

Is there any limitation?, If I use a 1000 vol chart with a 4 Renko MTFVol , the indi throw an exception.

Reply With Quote
  #73 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505


Sorry, I saw little interest so I didn't update the indy. Please find enclosed latest version.

GomMultiTFIndicatorBase is base class with no public properties
you must manually set properties

PeriodTypeBase (Tick, Second, Minute, ...)
PeriodLengthBase,
ResetModeBase (Bar, Daily,Weekly,Monthly, Quarterly, Annually)
RTHOnlyBase


GomMultiTFIndicator is the same, but with public properties you can change in indicator properties window.


Here are the exposed methods :


 
Code
                            
        //exposed to subclasses
        
protected  PeriodType PeriodTypeBase 
            
{get {return period;} set {period=value;}}

        protected 
int PeriodLengthBase 
                
{get {return periodlength;} set {periodlength=value;}}

        protected 
ResetType ResetModeBase 
                
{get {return reset;} set {reset=value;}}

        protected 
bool RTHOnlyBase 
                    
{get {return rthOnly;} set {rthOnly=value;}}
        
        
//property that tells you if current bar is RTH
        
protected bool  IsRTH get {return isRTH[0];}}
        
        
//if you want
        
protected virtual void GomInitialize() { }
        protected 
virtual void GomOnStartUp() { }

        protected 
virtual void GomOnNewBar() { }
        protected 
virtual void GomOnNewDay() { }
        protected 
virtual void GomOnNewWeek() { }
        protected 
virtual void GomOnNewMonth() { }
        protected 
virtual void GomOnNewQuarter() { }
        protected 
virtual void GomOnNewYear() { }

        
//mandatory
        
protected abstract void GomOnReset();
        protected abstract 
void GomOnData(double opendouble highdouble lowdouble closeint volume);
        protected abstract 
void GomOnDataDone(); 
You must implement GomOnReset (happens at the end of each period as defined in ResetMode), GomOnData : data arriving form second time series, and GomOnDataDone : all data from second time series sent, updating main time series.

Keep in mind you never know on which time series you are, so always use CurrentBars[0], Highs[0][0] etc to be sure you are always on the main time series.

There also a public property IsRTH you can always call in your code, that will tell if you are RTH or not on your main Time Series.

Whatever reset mode is ,you can always also call GomOnNewBar, GomOnNewDay, GomOnNewWeek etc...

GomOnNewBar is called on the beginning of each bar, then all the GomOnData, then GomOnDataDone.

Attached Files
Elite Membership required to download: GomMultiTF1.1.zip
Reply With Quote
  #74 (permalink)
 Prtester 
SE-Asia
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Amp
Trading: ES
Posts: 151 since Jun 2009
Thanks Given: 66
Thanks Received: 124


gomi View Post
Sorry, I saw little interest so I didn't update the indy. Please find enclosed latest version.

Thank you for your hard work I will try again in the weekend to see if I can make it work on my end :-(

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


gomi View Post
Sorry, I saw little interest so I didn't update the indy. Please find enclosed latest version

@ gomi: I do not think that it is lack of interest.. I simply do not understand what you are doing, and then I do not know how to use it and how to make it work.

For example, I tried to set the indicator to RTH, but there was no impact on my chart. The RTH information is not stored in the master data for the instrument, so I am not astonished that there is not impact.

There are lots of variables defined in the Indicator Base, but I can't figure out what this all is needed for.

-> is OddType
-> is RTH
-> GetWeekNumber
-> OnNew (no idea what the resets are needed for)
-> MaxDate and MinDate

So the whole structure is unclear, I guess I need some guidance.

Attached Thumbnails
Click image for larger version

Name:	ES 09-11 (10 Min)  08_07_2011.jpg
Views:	286
Size:	94.9 KB
ID:	42934  
Started this thread Reply With Quote
  #76 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

No problem, please don't feel you have to test it because you're the OP ;-)


Fat Tails View Post
For example, I tried to set the indicator to RTH, but there was no impact on my chart. The RTH information is not stored in the master data for the instrument, so I am not astonished that there is not impact.

RTH info is fetched from the master instrument setting, so if the contract has a default session of 24/5, RTH info won't show


Fat Tails View Post
There are lots of variables defined in the Indicator Base, but I can't figure out what this all is needed for.

-> is OddType
-> is RTH
-> GetWeekNumber
-> OnNew (no idea what the resets are needed for)
-> MaxDate and MinDate

These objects are internal objects, you don't need them.
The OnNew events are triggered during bar progression : each new bar fires OnNewBar, each new Day fires OnNewDay etc...

OnReset is fired depending on the Reset property : if it's Daily, it fires on the start of each new day, if it's weekly it fires on the start of each new week etc...
You could use the OnNewDay and OnNewWeek, but the OnReset method has all the logic already built to be synchronized to Reset property, so you can create daily/monthly/weekly indies with zero line of code.


Fat Tails View Post
So the whole structure is unclear, I guess I need some guidance.

Yes, I know, what you mean is ..... aargh... documentation.!.

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


gomi View Post
RTH info is fetched from the master instrument setting, so if the contract has a default session of 24/5, RTH info won't show

But there is no information on RTH i nthe master data. When I set your volume indicator to RTH, the RTH session in my template is simply ignored. I am not astonished, because how shall the indicator find out, which session is the RTH session?


gomi View Post
You could use the OnNewDay and OnNewWeek, but the OnReset method has all the logic already built to be synchronized to Reset property, so you can create daily/monthly/weekly indies with zero line of code.

Strange, when I try to add a daily data series to an intraday data series, NinjaTrader always inserts the daily data in the middle of the day. Actually I have had cases, where the data was inserted, before it was available and other cases, where it was inserted one session too late. So how do you make sure that the data is inserted when it should be inserted and not earlier or later?

This problem was the reason that I did not include an option to calculate intraday indicators from daily data for my MTF indicators. It always yielded false results. The reason is that the heuristic of NinjaTrader to add daily timestamps is flawed, if you use a session template with more than one session per day.

So I do not see how to use MTF indicators in RTH mode (your volume MTF example did not work), and I do not see how to add daily data.

Started this thread Reply With Quote
  #78 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505


Fat Tails View Post
But there is no information on RTH i nthe master data. When I set your volume indicator to RTH, the RTH session in my template is simply ignored. I am not astonished, because how shall the indicator find out, which session is the RTH session?

I use the info here to define RTH:



Fat Tails View Post
Strange, when I try to add a daily data series to an intraday data series, NinjaTrader always inserts the daily data in the middle of the day. Actually I have had cases, where the data was inserted, before it was available and other cases, where it was inserted one session too late. So how do you make sure that the data is inserted when it should be inserted and not earlier or later?

This problem was the reason that I did not include an option to calculate intraday indicators from daily data for my MTF indicators. It always yielded false results. The reason is that the heuristic of NinjaTrader to add daily timestamps is flawed, if you use a session template with more than one session per day.

Well, I guess it won't work if session template has more than 1 session per day.
Concerning bar synchronization, session aligns the timestamps of the time series, and always starts with BarsInProgress=0 , the BarsInProgress=1 etc.. So you always know when the bars will arrive, don't you ?

I have only tested with intraday time frames, though. (not daily, weekly, etc...)

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


gomi View Post
I use the info here to define RTH:

If you add a second BarSeries to produce a standard MTF indicator, it will always use the same session template as selected for the primary DataSeries. Or does your indicator use a different method?

Under instruments settings I have typically defined a multi-session template, which reflects the contractual trading times of the instrument - imagine the trading day divided into the RTH session and the remaining parts of the Globex session.

What does the RTH option change in this case?

Started this thread Reply With Quote
Thanked by:
  #80 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505



Fat Tails View Post
If you add a second BarSeries to produce a standard MTF indicator, it will always use the same session template as selected for the primary DataSeries. Or does your indicator use a different method?

The indicator considers that the default session template used in the instrument manager is what defines RTH, whatever session template you use for your chart.


Fat Tails View Post
Under instruments settings I have typically defined a multi-session template, which reflects the contractual trading times of the instrument - imagine the trading day divided into the RTH session and the remaining parts of the Globex session.

What does the RTH option change in this case?

RTH option will consider all time intervals defined in the master instrument session template as RTH.
If you split the whole 24/24 interval in the master instrument session template, so that all the hours are contained in the session template, obviously the RTH option won't do anything.

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