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

Has IsFirstTickOfBar issues reported ?

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

    Has IsFirstTickOfBar issues reported ?

    I think there must be a problem with " IsFirstTickOfBar" cause I can't find any other cause. In the following simple code you can see the logic flow. If "IsFirstTickOfBar" is true, all statements should be triggered, but they doesn't.

    Here the code:
    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public class Trendline
    	{
    		public int Position;
    		public double Price; 
    		
    		public Trendline()   
    		{
    			Position=0;
    			Price=0.00;
    		}
    	}	
    	
    	public class R : Strategy
    	{		
    		Trendline[] Uptrend;			  	 															// Array of uptrends
    		Trendline[] Downtrend;																			// Array of uptrends
    		private int ARRAY_SIZE;																			// Array size
    		private int Uptrendcount;																		// Number of active uptrends
    		private int Downtrendcount;																		// Number of active Downtrends
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"";
    				Name										= "R";
    				Calculate									= Calculate.OnPriceChange;
    				MaximumBarsLookBack							= MaximumBarsLookBack.Infinite; 			
    			}
    			else if (State == State.Configure)
    			{
    				ARRAY_SIZE									= 100000;
    				Uptrendcount								= 0;
    				Downtrendcount								= 0;
    				Uptrend										= new Trendline[ARRAY_SIZE];
    				Downtrend									= new Trendline[ARRAY_SIZE];
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			if ( CurrentBar < 1 )
    			{
    				Uptrendcount=0;
    				Downtrendcount=0;
    				for (int i = 0; i <ARRAY_SIZE; i++)
    				{			
    					Uptrend[i]= new Trendline();
    					Downtrend[i]= new Trendline();
    				}
    				for (int i = 0; i <ARRAY_SIZE; i++)  // just in case this initialization was necessary to solve the issue
    				{			
    					Uptrend[i].Position=0;
    					Uptrend[i].Price=0.00;
    					Downtrend[i].Position=0;
    					Downtrend[i].Price=0.00;
    				}
    				return;
    			}			
    		    if (IsFirstTickOfBar) 
    		    {
    				if ( Uptrendcount==0 && Downtrendcount==0 )
    				{
    					Ps=0;
    				}
    				else
    				{
    					// certain code
    				}	
    				Uptrendcount+=1;
    				Downtrendcount+=1;		
    		    }
                        ...the continues relying on that at least are Uptrendcount=1 and Downtrendcount=1, but they're just 0....logically I got an array error outside of bounds
    So, I'd appreciate any apporach, idea, test...etc to perform in order to solve it. I'm thinking that perhaps is related to Tickreplay property.

    Thanks in advance
    Last edited by pstrusi; 09-11-2017, 11:47 AM.

    #2
    Hello pstrusi,

    Print the value of IsFirstTickOfBar along with the time.

    Is this true when you are expecting it? (and false when you are expecting it?)

    I've tested but I'm not able to reproduce any issues printing the IsFirstTickOfBar with Calculate set to OnEachTick in real-time or historically with TickReplay enabled.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello pstrusi,

      Print the value of IsFirstTickOfBar along with the time.

      Is this true when you are expecting it? (and false when you are expecting it?)

      I've tested but I'm not able to reproduce any issues printing the IsFirstTickOfBar with Calculate set to OnEachTick in real-time or historically with TickReplay enabled.
      Chelsea, a simple question:

      If I set " Calculate as Calculate.OnPriceChange ", but I didn't activate the Tick replay property in the Data series: would it "IsFirstTickOfBar" still work? Tickreplay seems to be a feature to evaluate in the historical data, but when it comes to realtime data, whay would I need to have activated Tickreplay ?

      Thanks

      Comment


        #4
        Hello pstrusi,

        This would depend on if you are looking at historical data or realtime data.

        if Calculate is set to OnPriceChange in real-time or historically with TickReplay enabled the behavaior should be the same. With TickReplay disabled, IsFIrstTickOfBar will always be true in historical data.

        From the help guide:
        "On a historical data set, only the OHLCVT of the bar is known and not each tick that made up the bar. As a result, State.Historical data processes OnBarUpdate() only on the close of each historical bar even if this property is set to OnEachTick or OnPriceChange. You can use TickReplay or a Multi-time frame script to obtain intrabar data."

        Below is a publicly available link to the help guide on Calculate.


        And TickReplay.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Christopher_R, Today, 12:29 AM
        0 responses
        9 views
        0 likes
        Last Post Christopher_R  
        Started by sidlercom80, 10-28-2023, 08:49 AM
        166 responses
        2,235 views
        0 likes
        Last Post sidlercom80  
        Started by thread, Yesterday, 11:58 PM
        0 responses
        3 views
        0 likes
        Last Post thread
        by thread
         
        Started by jclose, Yesterday, 09:37 PM
        0 responses
        8 views
        0 likes
        Last Post jclose
        by jclose
         
        Started by WeyldFalcon, 08-07-2020, 06:13 AM
        10 responses
        1,415 views
        0 likes
        Last Post Traderontheroad  
        Working...
        X