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 GLFX005, Today, 03:23 AM
        0 responses
        1 view
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        6 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Started by Waxavi, Today, 02:00 AM
        0 responses
        3 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X