NexusFi: Find Your Edge


Home Menu

 





Understanding MTF bars, bar closure times, etc.


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Jayswiss with 9 posts (0 thanks)
    2. looks_two srgtroy with 8 posts (1 thanks)
    3. looks_3 rleplae with 2 posts (0 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 4,271 views
    2. thumb_up 1 thanks given
    3. group 3 followers
    1. forum 18 posts
    2. attach_file 4 attachments




 
Search this Thread

Understanding MTF bars, bar closure times, etc.

  #11 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722


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.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
36 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
19 thanks
Spoo-nalysis ES e-mini futures S&P 500
18 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #12 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722

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:


Reply With Quote
Thanked by:
  #13 (permalink)
 Jayswiss 
San Francisco, CA / USA
 
Experience: Intermediate
Platform: NinjaTrader, TradingView
Trading: ES, TF, NQ, CL, GC
Posts: 29 since Jun 2016
Thanks Given: 4
Thanks Received: 3



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:


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.

Started this thread Reply With Quote
  #14 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722


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)
 Jayswiss 
San Francisco, CA / USA
 
Experience: Intermediate
Platform: NinjaTrader, TradingView
Trading: ES, TF, NQ, CL, GC
Posts: 29 since Jun 2016
Thanks Given: 4
Thanks Received: 3


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

Started this thread Reply With Quote
  #16 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722


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)
 Jayswiss 
San Francisco, CA / USA
 
Experience: Intermediate
Platform: NinjaTrader, TradingView
Trading: ES, TF, NQ, CL, GC
Posts: 29 since Jun 2016
Thanks Given: 4
Thanks Received: 3


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.

Started this thread Reply With Quote
  #18 (permalink)
 
srgtroy's Avatar
 srgtroy 
Los Angeles, California Republic
Legendary  R.I.P. 1965-2023 
 
Experience: None
Platform: Sierra Chart
Broker: CQG
Trading: ES
Posts: 1,928 since Jan 2011
Thanks Given: 1,375
Thanks Received: 3,722

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);
				}	
			
			}
          
        }
    }
}


Ok, play with it. Gotta run...

Reply With Quote
  #19 (permalink)
 Jayswiss 
San Francisco, CA / USA
 
Experience: Intermediate
Platform: NinjaTrader, TradingView
Trading: ES, TF, NQ, CL, GC
Posts: 29 since Jun 2016
Thanks Given: 4
Thanks Received: 3

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...

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

Started this thread Reply With Quote




Last Updated on July 8, 2016


© 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