Essentials of MTF (multi-time frame) indicators - NinjaTrader Programming | futures io social day trading
futures io futures trading


Essentials of MTF (multi-time frame) indicators
Updated: Views / Replies:10,135 / 15
Created: by Fat Tails Attachments:1

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 1  
 
Thread Tools Search this Thread
 

Essentials of MTF (multi-time frame) indicators

  #11 (permalink)
Elite Member
Los Angeles, CA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, IB TWS
Broker/Data: Dorman/Rithmic, Interactive Brokers
Favorite Futures: NQ, CL
 
Posts: 103 since Sep 2013
Thanks: 151 given, 86 received


Fat Tails View Post
I have made the observation that for historical bars the value of CurrentBars[1] already changes when the primary bars are being processed. This allows me to access the indicator value calculated from CurrentBars[1] prior to the processing of the secondary bars, and I can avoid the lag. The changed indicator architecture is now
 
Code
if (CurrentBars[1] < currentBars1)
{
    currentBars1 = CurrentBars[1];
    // calculate indicator value here
}
if (BarsInProgress == 0)
{
    // set indicator value to plot here
}

Thanks a million Fat Tails!

Can you point me to sample code that uses the currentBars1 logic? I am not sure I quite understand how the above snippet would work as future bars are processed. I am currently focused on the historical data case, but eventually will want to handle all 3 cases. In particular, I don't understand how (CurrentBars[1] < currentBars1) could keep evaluating to true on each primary bar. Or does this calculation only apply to the very last bar of the chart?

[EDIT]
I found the answer to the above question in Fat Tails' anaOpeningRangeV42MTF indicator. The comparison sign should be reversed so that it looks like this:
 
Code
if (CurrentBars[1] > currentBars1)
{
    currentBars1 = CurrentBars[1];
    // calculate indicator value here
}
if (BarsInProgress == 0)
{
    // set indicator value to plot here
}
[/EDIT]


Second Question:

I have been struggling for days trying to align my secondary data series with my first. My primary series is a renko, let's say 3 tick for the sake of argument, and my secondary is a 1 tick series. I wish to accumulate volumes on 1 tick data for swings that I plot on the primary series. It worked fine for larger renko bars, but with smaller renko bars there could be situations in fast markets where several renko bars print with the exact same timestamps. This is when my indicator has problems synchronizing with the data computed from tick data series.

I should mention that I am actually using BetterRenko bars with a brick size of 1 as my primary series for this test case, which sometimes prints bricks that are actually 2 ticks tall.

Any help greatly appreciated!


Last edited by ganamide; September 7th, 2015 at 04:27 PM. Reason: Found answer to first question and clarified use of BetterRenko
Reply With Quote
The following user says Thank You to ganamide for this post:
 
  #12 (permalink)
Elite Member
Los Angeles, CA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, IB TWS
Broker/Data: Dorman/Rithmic, Interactive Brokers
Favorite Futures: NQ, CL
 
Posts: 103 since Sep 2013
Thanks: 151 given, 86 received

Example problem of MTF indicator with BetterRenko bars having same timestamps

I printed out a bunch of statements to figure out how to work around these insane NT 7 MTF bar processing behaviors. Hopefully this could help someone understand the problem, or better yet, maybe someone can suggest a solution!

Setup:
  • Primary data series is a 1 tick BetterRenko. This is a custom bar type I got from futures.io (formerly BMT).
  • Secondary data series is 1 tick (individual trades)
  • Code is an indicator with CalculateOnBarClose=false
  • Information is printed to Output window during OnBarUpdate events

Problem Test Case:
  • A set of 3 BetterRenko bars that all have the same timestamp
  • Corresponding tick data are 5 individual tick bars all having the same timestamp and volume of 1
  • Timestamp is 9/4/15 13:47:20 PST, which does not fall on a session boundary
  • NQ 09-15 contract data from NT historical data server

Output Results in order received in OnBarUpdate:
1. First BetterRenko bar (made from 1 tick)
2. First and only Tick bar of First BetterRenko bar

3. Second BetterRenko bar (made from 2 ticks)
4. First of two Tick bars of Second BetterRenko bar

5. Third BetterRenko bar (made from 2 ticks)
6. Second of two Tick bars of Second BetterRenko bar
7. First of two Tick bars of Third BetterRenko bar (same close and timestamp as previous tick)
8. Second of two Tick bars of Third BetterRenko bar
Hopefully it is clear how this is a problem. I can't be sure if an update on a tick bar is for the BetterRenko bar that came last, or one that came before that one. I suppose I could try to keep track of volume and prices to guess which BetterRenko bar each tick belongs to, but I don't feel confident that approach would work in all cases. Maybe this would work in conjunction with aligning ticks to timestamps, meaning that there seems to be no problem when a new tick has a different time stamp compared to the previous tick. This sort of re-synchs the two data series.

Reply With Quote
 
  #13 (permalink)
Elite Member
Los Angeles, CA, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, IB TWS
Broker/Data: Dorman/Rithmic, Interactive Brokers
Favorite Futures: NQ, CL
 
Posts: 103 since Sep 2013
Thanks: 151 given, 86 received

Primary BetterRenko + 1 Tick Secondary Alignment Solved!


I solved my problem after hours of toiling. In case anyone is interested, I did it by keeping two cumulative volume counts, one for the primary series and one for the secondary series. Whenever I wanted to align calculations made on the secondary series with the primary series, I would check the cumulative volumes to see which primary bar index aligned with the current secondary bar. Depending on the comparison, I would sometimes have to cycle back through the primary bar volumes to get the right index. I also wrote code to cycle forward, but I never needed to go forward more than 1 bar in my testing. At RTH session close, I had to go back 42 bars for alignment!

Now I can get back to the fun part of system development!

Reply With Quote
The following 2 users say Thank You to ganamide for this post:
 
  #14 (permalink)
Membership Temporarily Revoked
Россия
 
Futures Experience: Advanced
Platform: NinjaTrader 7
Broker/Data: Rithmic, CQG
Favorite Futures: CL, 6C
 
Posts: 6 since Dec 2014
Thanks: 0 given, 2 received

Yes, you need one counter for each period of chart.

Some related example of counting bar volume by cumulating volumes on every tick by bid\ask side
(works on any timeframe min, tick, range, volume etc.)

 
Code
		protected override void OnMarketData(MarketDataEventArgs e)
		{
                        ...
 			tradeSideVolumes.TickVolume = e.Volume;
			tradeSideVolumes.CumVolume += e.Volume; 
			
			if (lastBar == CurrentBar)  
			{ // we are inside higher timeframe bar
				tradeSideVolumes.BarVolume += e.Volume;
			}
                        ...

		protected override void OnBarUpdate()
		{
			if (BarsInProgress == 0) {   // higher time frame
				lastBar = CurrentBar;  // lastBar is custom indicator class member
				
				if (FirstTickOfBar)  
				{ // new bar on chart
					// set volumes collected in OnMarketData() and just traded for a new bar
                                        // this cause OnMarketData() for new bar triggered before OnBarUpdate()
					volumes[(int)TradeSide.Ask].BarVolume = volumes[(int)TradeSide.Ask].TickVolume;
                                        ...
                                 }

                		vol = volumes[(int)TradeSide.Ask].GetDisplayVolume( BarsPeriod.Id);
		                if (vol > 0)
         			   AskVolume.Set( vol);
                                 ...


		public class Volumes
		{
			public double TickVolume;
			public double BarVolume;			// 
			public double CumVolume;            // cumulate vols for 1 or more ticks (depends on indicator logic)
                        ...

                        public double GetDisplayVolume( PeriodType period)
			{
				if (period == PeriodType.Tick)
					return CumVolume;
				else
					return BarVolume;
			}

			public void NewAskBid()
			{
				CumVolume = 0;	
			}
                        ...

Reply With Quote
 
  #15 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,600 received
Forum Reputation: Legendary

One of the problems here is the 1-second granularity used by NinjaTrader 7. With NinjaTrader 8 and millisecond granularity things should improve.

Also there is a difference between bar processing in real-time and on historical data. High resolution bars are not being processed correctly on historical data, when they have the same time stamp.


Last edited by Fat Tails; October 10th, 2015 at 01:07 PM.
Reply With Quote
 
  #16 (permalink)
Membership Temporarily Revoked
Россия
 
Futures Experience: Advanced
Platform: NinjaTrader 7
Broker/Data: Rithmic, CQG
Favorite Futures: CL, 6C
 
Posts: 6 since Dec 2014
Thanks: 0 given, 2 received


Fat Tails View Post
One of the problems here is the 1-second granulatiry used by NinjaTrader 7. With NinjaTrader 8 and millisecond granularity things should improve.

Also there is a difference between bar processing in real-time and on historical data. High resolution bars are not being processed correctly on historical data, when they have the same time stamp.

in Market replay we have full data feed input with Level 2.
if you talking about msec TFs, you should use per tick processing anyway, t.i. event-driven algo.

Reply With Quote

Reply



futures io > > > > > Essentials of MTF (multi-time frame) indicators

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding Multi Time Frame (MTF) Indicators with NinjaTrader Fat Tails NinjaTrader 411 June 28th, 2016 08:34 AM
Troubleshooting multi time frame strategy jperales NinjaTrader Programming 4 October 9th, 2014 03:21 PM
multi time-frame questions -- this is different balance NinjaTrader Programming 4 January 12th, 2013 03:27 AM
ADX Multi Time Frame bellair NinjaTrader 9 November 10th, 2011 11:14 AM
Multi Volume/Time Frame Trading wh The Elite Circle 7 September 15th, 2009 05:55 PM


All times are GMT -4. The time now is 02:42 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-12 in 0.10 seconds with 20 queries on phoenix via your IP 54.90.207.75