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

GetBar on multiseries

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

    GetBar on multiseries

    While I'm working with primary 1min bars (BarsInProgress = 0) how can I get the number of the bar with GetBar()? but i need the number of the bar for secondary 1hour timeframe? I have the time of the bar as input. I can't wait for BarsInProgress = 1 to happen to do my calculations.

    Something like GetBar(BarsArray[1], Time) ???
    Last edited by BankRobber; 01-18-2012, 06:27 PM.

    #2
    Unfortunately GetBar() would not allow to pass in another series - you would need to custom code this.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Unfortunately GetBar() would not allow to pass in another series - you would need to custom code this.
      Another question not related to the previous one.

      Lows[1][0] gives me previous hour low, where [1] = 60 minutes time frame.

      How can i get the current hour just forming 60min bar highs or lows.
      All calculations are done on lower time frame after FirstTickOfBar of lower time frame.

      Comment


        #4
        Do you ask for realtime trading or backtesting here BankRobber? If Realtime, do you run the script with CalculateOnBarClose = false?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          Do you ask for realtime trading or backtesting here BankRobber? If Realtime, do you run the script with CalculateOnBarClose = false?
          It seems to me that Lows[1][0] gives me past hour on historic and current hour realtime.
          Im running the script with CalculateOnBarClose = false, but calculations are done on FirstTickOfTheBar of the lowest timeframe

          Comment


            #6
            Hi BankRobber,

            Yes this is expected. Multiseries bars are referenced differently in historical compared to real time bars, COBC = false. This is detailed in the following link (Section How Bar Data is Referenced)
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Hello.
              This is my function to get bar index from any timeframe.
              It works good for me.

              (If to uncomment strings in the end of function, it will return exactly first bar after target_time.)

              Code:
              		int fGetBarMtf( int serie, DateTime target_time )
              		{
              			int ix_future  = 0;
              			int ix_past    = CurrentBars[serie];
              			int ix_current = (ix_past - ix_future)/2;
              			
              			while( ! (Times[serie][ix_current] <= target_time && target_time <= Times[serie][ix_current-1]) )
              			{				
              				// if target_time is earlier that new center
              				if( target_time < Times[serie][ix_current] )
              				{
              					ix_future = ix_current;
              					ix_current = ix_past - (ix_past - ix_future)/2;
              				}
              				
              				// if target_time is later that new center
              				if( target_time > Times[serie][ix_current] )
              				{
              					ix_past = ix_current;
              					ix_current = ix_past - (ix_past - ix_future)/2;
              				}				
              			}
              							
              			//if( target_time < Times[serie][ix_current+1] )  while( !( target_time > Times[serie][ix_current+1] ) && ix_current < CurrentBars[serie] ) ix_current++;
              			//else    	                                      while( !( target_time < Times[serie][ix_current]   ) && ix_current > 0                  ) ix_current--;
              			
              			return( ix_current );
              		}
              fx.practic
              NinjaTrader Ecosystem Vendor - fx.practic

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by samish18, Yesterday, 12:20 PM
              1 response
              12 views
              0 likes
              Last Post WaleeTheRobot  
              Started by Lancer, 01-29-2020, 10:15 PM
              6 responses
              460 views
              1 like
              Last Post neveral0n3  
              Started by Rogers101, Today, 11:30 AM
              1 response
              13 views
              0 likes
              Last Post WaleeTheRobot  
              Started by AndreiBig, Yesterday, 12:30 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Eduardo  
              Started by nicthe, Today, 07:38 AM
              2 responses
              15 views
              0 likes
              Last Post WaleeTheRobot  
              Working...
              X