Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

if(Historical) return;

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

    if(Historical) return;

    if(Historical) return;

    Hi guys, this statement isn't working, any ideas? When i moved my new strat to production it began to print historical print statements.

    #2
    Hello,

    Thank you for the question.

    Can you provide an example of this not working so that I can see how you have implemented this? Also how are you running the strategy, in live data or is this in market replay or on simulated data?

    In general this can be placed before any statements that do not need to be run Historically as you know, depending on the placement anything before it would still be run anything after would not.

    I look forward to being of further assistance.

    Comment


      #3
      I have 1 primary series and 2 secondary series in a strategy. When I move the strategy to production it continues to print out historical values from previous days. Primary series is 2 betterrenko. I just also tested it on the 1 minute and its the same effect.

      Comment


        #4
        Hello,

        Thank you for the reply.

        I have not experienced this when using the if(Historical) bool.

        If you can provide an example of this in code that produces the issue I would be happy to take a look at it and see what is happening.

        Without an example to see how this is happening I can only tell you that this is the correct syntax you are using and that preventing historical data from being used would be its use.

        I look forward to being of further assistance.

        Comment


          #5
          Hey guys I think i may have found the cause of this error. It appears to occur when you refer to another dataseries while you are inside the 0 bar series that causes the historical statement to malfunction. Will post more info when I found the exact statement.

          Comment


            #6
            Hey guys this error just appears to be caused by adding more than 1 series to a strategy! hope you will be able to help me solve it here is the strategy as it stands now:

            Initialize:
            // Set calculation options
            CalculateOnBarClose = true;

            BarsRequired = 150;
            EntriesPerDirection = 3;

            Add("A", PeriodType.Minute, 1440);

            Add("ABC", PeriodType.Minute, 5);

            Add("ACT", PeriodType.Minute, 1);

            // Exit trade at end of session
            ExitOnClose = true;
            ExitOnCloseSeconds = 60;

            protected override void OnBarUpdate()
            {

            if(BarsInProgress==1)
            {
            if(Historical) return;
            }

            if(BarsInProgress==3)
            {
            if(Historical) return;
            }

            if(BarsInProgress==0)
            {
            if(Historical) return;
            }

            if(BarsInProgress==2)
            {
            if(Historical) return;
            }

            //THIS IS 5 MINUTE BAR SERIES
            if(BarsInProgress==2)
            {
            if(Historical) return;


            }


            if(BarsInProgress==0)
            {
            if(Historical) return;



            Print("this is a test for time series: " + Time[0]);




            } // END OF BAR 0
            }

            Comment


              #7
              As you can see, the print time statement should not be executing but it does in realtime, for example it prints from the bars from June today! Please advise.

              Comment


                #8
                Hello,

                In the code you have posted the print should be happening during live data because it is not historical data and that is what the condition is checking for.

                The if(Historical) return is returning for all historical bars and then when live data comes in it will allow the print.

                If you do not want something to happen in Live data you would want to use if(!Historical) or in English if not historical then

                I think you are looking for if(!Historical) return; this will not happen live if you do this.

                Please let me know if i may be of additional assistance.

                Comment


                  #9
                  Sorry, but I think you have misunderstood, the statement below executes on both historical and real-time bars:

                  if(BarsInProgress==0)
                  {
                  if(!Historical)
                  {
                  Print("this is a test for time series: " + Time[0]);
                  }

                  }

                  Comment


                    #10
                    Hello,

                    The code you had provided previously did not include this statement, and I have replied based on the code you provided.

                    In the new statement you provided I have tested this and yes your findings are correct. It would seem that the added bar series is not getting a request for historical data. This is a known limitation when adding multiple data series. In certain cases the historical data is not loaded so there are no historical bars to process.

                    The resolution I have found was to Open a chart with the instruments you are adding and request historical data so that it is downloaded.

                    Here is the code I was using for the test so that you can confirm on your end.

                    Code:
                    if(BarsInProgress == 0)
                    {
                         if (Historical)
                    	{
                    		Print("This will print historically");				
                    	}
                    		else if(!Historical)
                    	{
                    		Print("This will print during Live data");
                    	}
                    }
                    This is a known limitation when adding multiple data series, this is being looked into for future versions of NinjaTrader.

                    Please let me know if I may be of additional assistance.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    571 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    330 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    549 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    549 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X