• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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.
        http://ninjatrader.com/support/helpG.../calculate.htm

        And TickReplay.
        http://ninjatrader.com/support/helpG...ick_replay.htm
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ajay8000, Yesterday, 11:31 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by simjs, Yesterday, 11:23 PM
        0 responses
        5 views
        0 likes
        Last Post simjs
        by simjs
         
        Started by akuntysh, Yesterday, 10:41 PM
        0 responses
        4 views
        0 likes
        Last Post akuntysh  
        Started by Wolf1, Yesterday, 08:26 PM
        0 responses
        7 views
        0 likes
        Last Post Wolf1
        by Wolf1
         
        Started by pparmley, Yesterday, 04:30 PM
        0 responses
        9 views
        0 likes
        Last Post pparmley  
        Working...
        X