Understanding MTF bars, bar closure times, etc. - NinjaTrader Programming | futures io social day trading
futures io futures trading


Understanding MTF bars, bar closure times, etc.
Updated: Views / Replies:875 / 18
Created: by Jayswiss Attachments:4

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
 4  
 
Thread Tools Search this Thread
 

Understanding MTF bars, bar closure times, etc.

  #11 (permalink)
Elite Member
Los Angeles, California Republic
 
Futures Experience: Intermediate
Platform: Sierra Chart
Favorite Futures: ES, Mongolian Horse Futures
 
srgtroy's Avatar
 
Posts: 1,456 since Jan 2011
Thanks: 1,009 given, 2,238 received


Jayswiss View Post
Ah I see. I am actually running a drawing rectangles with start 0 end 30 in(to draw a 30 minute long rectangle). But in the case mentioned above, it winds up overlapping in some of those spots where the is no data.. Using your code and start 0 end 1 bars, it seems to draw them correctly now. I just need to figure out how to draw until the next bar instead of fixed 30 mins.

What do you mean draw until the next bar? You mean you want a rectangle that goes the length of the 30 mins? Generally speaking, the rectangle shape is usually used in the price bar area but I suppose you could use it below, although I've never tried that. You may be better off, however, drawing a square, as I did, every minute. In other words, at the end of every minute, you check your higher timeframe condition and draw a colored square based on whether it is true or false. That way it will look exactly how it looks in the example you gave above.


Last edited by srgtroy; July 7th, 2016 at 02:04 AM.
Reply With Quote
 
  #12 (permalink)
Elite Member
Los Angeles, California Republic
 
Futures Experience: Intermediate
Platform: Sierra Chart
Favorite Futures: ES, Mongolian Horse Futures
 
srgtroy's Avatar
 
Posts: 1,456 since Jan 2011
Thanks: 1,009 given, 2,238 received

For example, let's use an easy sample condition. If the close of the thirty minute bar is greater then the close of the previous thirty minute bar, the square is green; if it less, the square will be red.

Here's the code:

 
Code
Using declarations


namespace NinjaTrader.Indicator
{
    
    
    public class test : Indicator
    {
        
	#region Variables
		
		private bool thirty;
			
	#endregion
		
		
	protected override void Initialize()
        {
            Overlay			= false;
	    DrawOnPricePanel	= false;
			
	    Add(PeriodType.Minute, 30);
	    BarsRequired = 1;
        }

        
        protected override void OnBarUpdate()
        {
            if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired) return;
			
			if (BarsInProgress == 1)
			{
				if (Closes[1][0] > Closes[1][1])
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Green);
				thirty = true;	
				}
				
				if (Closes[1][0] < Closes[1][1])
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Red);
				thirty = false;	
				}	
			}
			
			if (BarsInProgress == 0)
			{
				if (thirty == true)
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Green);
				}
			
				if (thirty == false)
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Red);
				}	
			
			}
          
        }
    }
}

This is what it looks like:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Reply With Quote
The following user says Thank You to srgtroy for this post:
 
  #13 (permalink)
Elite Member
San Francisco, CA / USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, TradingView
Favorite Futures: ES, TF, NQ, CL, GC
 
Posts: 29 since Jun 2016
Thanks: 4 given, 3 received



srgtroy View Post
For example, let's use an easy sample condition. If the close of the thirty minute bar is greater then the close of the previous thirty minute bar, the square is green; if it less, the square will be red.

Here's the code:

 
Code
Using declarations


namespace NinjaTrader.Indicator
{
    
    
    public class test : Indicator
    {
        
		#region Variables
		
			private bool thirty;
			
		#endregion
		
		
		protected override void Initialize()
        {
                        Overlay			= false;
			DrawOnPricePanel	= false;
			
			Add(PeriodType.Minute, 30);
			BarsRequired = 1;
        }

        
        protected override void OnBarUpdate()
        {
            if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired) return;
			
			if (BarsInProgress == 1)
			{
				if (Closes[1][0] > Closes[1][1])
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Green);
				thirty = true;	
				}
				
				if (Closes[1][0] < Closes[1][1])
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Red);
				thirty = false;	
				}	
			}
			
			if (BarsInProgress == 0)
			{
				if (thirty == true)
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Green);
				}
			
				if (thirty == false)
				{
				DrawSquare("a1" + CurrentBars[0], false, 0, 1, Color.Red);
				}	
			
			}
          
        }
    }
}

This is what it looks like:

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Ah..perfect! That's a great starting point for me and I can now see a couple things I was doing wrong (I'm still just a few days in to learning Ninjascript). Thanks so much for the assistance.

Reply With Quote
 
  #14 (permalink)
Elite Member
Los Angeles, California Republic
 
Futures Experience: Intermediate
Platform: Sierra Chart
Favorite Futures: ES, Mongolian Horse Futures
 
srgtroy's Avatar
 
Posts: 1,456 since Jan 2011
Thanks: 1,009 given, 2,238 received


Jayswiss View Post
Ah..perfect! That's a great starting point for me and I can now see a couple things I was doing wrong (I'm still just a few days in to learning Ninjascript). Thanks so much for the assistance.

You are welcome. However, there is still one problem with the code as it currently stands. Instead of plotting this line at the value of "1". You will probably want to plot it at the value of "30". That way you can have a line for "1", "5", "15", "30", etc...I can show you how to do that or you can try yourself, your choice.

Reply With Quote
 
  #15 (permalink)
Elite Member
San Francisco, CA / USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, TradingView
Favorite Futures: ES, TF, NQ, CL, GC
 
Posts: 29 since Jun 2016
Thanks: 4 given, 3 received


srgtroy View Post
You are welcome. However, there is still one problem with the code as it currently stands. Instead of plotting this line at the value of "1". You will probably want to plot it at the value of "30". That way you can have a line for "1", "5", "15", "30", etc...I can show you how to do that or you can try yourself, your choice.

Oh I would appreciate any tips or assistance you can provide on this topic. I did notice your boxes are "1" , I would try to do 0-1, 0-5, 0-15, 0-30, etc. as appropriate if that's what you mean

Reply With Quote
 
  #16 (permalink)
Elite Member
Los Angeles, California Republic
 
Futures Experience: Intermediate
Platform: Sierra Chart
Favorite Futures: ES, Mongolian Horse Futures
 
srgtroy's Avatar
 
Posts: 1,456 since Jan 2011
Thanks: 1,009 given, 2,238 received


Jayswiss View Post
Oh I would appreciate any tips or assistance you can provide on this topic. I did notice your boxes are "1" , I would try to do 0-1, 0-5, 0-15, 0-30, etc. as appropriate if that's what you mean

The proper parameters for the DrawSquare method should be:
 
Code
DrawSquare("a1" + CurrentBars[0], true, 0, 30, Color.xxx);

So autoscale gets changed to "true" and the y value gets set to 30 (or whatever higher timeframe you are referring to).

Reply With Quote
 
  #17 (permalink)
Elite Member
San Francisco, CA / USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, TradingView
Favorite Futures: ES, TF, NQ, CL, GC
 
Posts: 29 since Jun 2016
Thanks: 4 given, 3 received


srgtroy View Post
You are welcome. However, there is still one problem with the code as it currently stands. Instead of plotting this line at the value of "1". You will probably want to plot it at the value of "30". That way you can have a line for "1", "5", "15", "30", etc...I can show you how to do that or you can try yourself, your choice.

Hmm yeah now that I start working with it, it's a bit confusing as to how I would also show the primary series on another row (at bottom) with the 30 min tf in this case.

Reply With Quote
 
  #18 (permalink)
Elite Member
Los Angeles, California Republic
 
Futures Experience: Intermediate
Platform: Sierra Chart
Favorite Futures: ES, Mongolian Horse Futures
 
srgtroy's Avatar
 
Posts: 1,456 since Jan 2011
Thanks: 1,009 given, 2,238 received

Actually, this code is better. I've included a 5 minute line and a 30 minute line plus made it more efficient:

 
Code
Using declarations

namespace NinjaTrader.Indicator
{
    
    [Description("Enter the description of your new custom indicator here")]
    public class test : Indicator
    {
        
		#region Variables
		
			private bool five;
			private bool thirty;
			
		#endregion
		
		
		protected override void Initialize()
        {
            Overlay				= false;
			DrawOnPricePanel	= false;
			
			Add(PeriodType.Minute, 5);
			Add(PeriodType.Minute, 30);
			BarsRequired = 1;
        }

        
        protected override void OnBarUpdate()
        {
            if (CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired || CurrentBars[2] < BarsRequired) return;
			
			if (BarsInProgress == 2)
			{
				if (Closes[2][0] > Closes[2][1])
				{
					thirty = true;	
				}											///Thirty Minute Conditions
				
				if (Closes[2][0] < Closes[2][1])
				{
					thirty = false;	
				}	
			
			}
			
			if (BarsInProgress == 1)
			{
				if (Closes[1][0] > Closes[1][1])
				{
					five = true;	
				}
															///Five Minute Conditions
				if (Closes[1][0] < Closes[1][1])
				{
					five = false;	
				}	
				
				
			}
			
			if (BarsInProgress == 0)
			{
				if (five == true)
				{
				DrawSquare("five" + CurrentBars[0], true, 0, 5, Color.Green);
				}
			
				if (five == false)
				{
				DrawSquare("five" + CurrentBars[0], true, 0, 5, Color.Red);
				}																				///One Minute Drawings
				
				if (thirty == true)
				{
				DrawSquare("thirty" + CurrentBars[0], true, 0, 30, Color.Green);
				}
			
				if (thirty == false)
				{
				DrawSquare("thirty" + CurrentBars[0], true, 0, 30, Color.Red);
				}	
			
			}
          
        }
    }
}
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Ok, play with it. Gotta run...

Reply With Quote
 
  #19 (permalink)
Elite Member
San Francisco, CA / USA
 
Futures Experience: Intermediate
Platform: NinjaTrader, TradingView
Favorite Futures: ES, TF, NQ, CL, GC
 
Posts: 29 since Jun 2016
Thanks: 4 given, 3 received

Great! I've been expanding on it a bit and it's coming together nicely. Thank you.

Is it possible somehow to overlay a dot/circle on top of the square for the actual timeframe bar? If not, I suppose I could use a circle only (red or green) for the bar that indicates the actual close of the specific timeframes bar. For example on a 5 minute it might look like...

■■■■●■■■■●■■■■●■■■■●■■■■●■■■■


Last edited by Jayswiss; July 8th, 2016 at 04:05 AM.
Reply With Quote

Reply



futures io > > > > > Understanding MTF bars, bar closure times, etc.

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
BBANDS DOTS MTF FOR RANGE BARS fdtrader NinjaTrader Programming 22 May 27th, 2014 06:07 PM
Learning about secondary bar series and using MTF in Ninjatrader podski NinjaTrader 2 May 13th, 2013 12:04 AM
MTF Different Instruments Same time but handling missing bars leinster NinjaTrader 0 March 19th, 2013 09:03 AM
understanding Volume Tick Range bars Angelo1 Platforms and Indicators 2 November 29th, 2012 07:46 AM
Bar Type with User controlled start times DavidHP NinjaTrader 0 May 30th, 2011 11:42 AM


All times are GMT -4. The time now is 11:48 PM.

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.12 seconds with 20 queries on phoenix via your IP 54.234.255.29