Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Logic for creating different Time Frame Open without MTF?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Logic for creating different Time Frame Open without MTF?

    Howdy.

    So I am creating an indicator that will sit on a one minute chart.

    I would like for example, to display the OPEN price of say a 6 hour bar. On that one minute chart (I will do other things too, but for now this should serve as an example). But the OPEN of a higher TF is all I want as I will calculate everything else I need with the 1 minute data.

    I can do this with a secondary series like so:
    Code:
            protected override void Initialize()
            {
                Overlay				= true;
    	    Add(PeriodType.Minute, 360);
    	    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "1) HTF_OPEN"));		//1
            }
    
            protected override void OnBarUpdate()
            {
    		if(CurrentBar==0)
    				ClearOutputWindow();
    			
        		if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
            		return;	
    
    		if (BarsInProgress == 1)	{
    			htf_Oprice = Open[-1];  htf_Obar =CurrentBars[0];
    			DrawVerticalLine("htfOpen"+CurrentBar,0,Color.Orange,DashStyle.Dash,1);
    			Print(Times[0][0]+" , "+htf_Oprice+" , "+htf_Obar);
    		}
    			
    		if (BarsInProgress == 0)
    		{
    			HTF_Open[0] = htf_Oprice;
    //			Print(Time[0]+" , "+htf_Oprice+" , "+htf_Obar);
    		}
    
            }
    In the attached picture this produces exactly what I want on a historical chart.

    So my question, is there any logic that will allow me to do this without using an MTF or seconary series?

    I'm sure I could just check on each bar if the time coincides with the open of whatever larger time frame bar I want. But then this would require re-coding anytime I want to change the larger TF.

    I could simply sum the smaller TF bars up to equal the number required to fit in the larger TF, but this seems kinda sloppy and sometimes there may not be exactly 360 one minute bars in every one.

    Has anyone had a similar need and if so what was your programming logic to do this?

    Thanks!
    Attached Files
    Last edited by forrestang; 02-09-2016, 12:31 PM.

    #2
    Hi forrestang,

    Just to be clear, you want to be able to get a small amount of data with a different time frame or instrument without having to add a secondary series to the script, is this correct?


    For NinjaTrader 7, there is not a supported way of achieving this, but there is an undocumented way you may be able to use.
    This would involve doing an out-of-sync data request using Data.Bars.GetBars().

    An example of this is in the Pivots indicator included with NinjaTrader 7.
    Tools -> Edit NinjaScript -> Indicator... -> Pivots -> OK


    With NinjaTrader 8 support to call data without adding this as a series is fully supported and documented.
    This can be done with a BarsRequest.

    Below is a link to the help guide on BarsRequest which includes an example.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi forrestang,

      Just to be clear, you want to be able to get a small amount of data with a different time frame or instrument without having to add a secondary series to the script, is this correct?
      I'm not sure if that is exactly what I mean.

      Say for example you are looking at a one minute chart... I'd essentially just like to know WHEN a new higher TF opens.

      So from the pic above, those horizontal yellow lines are just the price when the NEW higher TF bar opens.

      So as far as programming goes, I'd like to plot a vertical line each time a new higher TF bar opens to mark that place in time.

      So my question is really just if anyone can think of a simple logic that would do this?

      Comment


        #4
        Hello forrestang,

        If you want to detect when a larger time frame interval is updating, you would need a secondary data series or bars request with an update event.

        Adding up a smaller time frames bars would only work if you only allowed the script to work on a single time frame that would never change.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Ok thanks for the help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by algospoke, Yesterday, 06:40 PM
          2 responses
          19 views
          0 likes
          Last Post algospoke  
          Started by ghoul, Today, 06:02 PM
          3 responses
          14 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          45 views
          0 likes
          Last Post jeronymite  
          Started by Barry Milan, Yesterday, 10:35 PM
          7 responses
          20 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by AttiM, 02-14-2024, 05:20 PM
          10 responses
          181 views
          0 likes
          Last Post jeronymite  
          Working...
          X