Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy.Historical not works at specific situation

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

    Strategy.Historical not works at specific situation

    Hi

    Maybe that it is just some cache issue, but I found that in some case automated strategy has Historical == false even if it run on historical data.

    Let's consider this simple strategy, which do nothing, only log message.

    Code:
    protected override void Initialize() {
        Add(PeriodType.Day, 1);
    }
            
    protected override void OnBarUpdate()
    {
        if( Historical ) {
            return;
        }
                
        Log( "FooBar", LogLevel.Information );
    }
    In my case I run it on Sim101 account, the connection is on the MB Trading demo account, instrument ES 09-12. Add this strategy to your Strategy Tab and make it Enable. I would expect to have logged FooBar message only once a minute at realtime run, but I get a tons of FooBar messages logged into my Log Tab (check attachments), so this means that in this case NinjaTrader totally ignore Historical run and says it runs realtime. This violate what documentation says about Historical attribute:
    When running a live strategy, this property will be true until the strategy starts processing real-time data
    I found that secondary bars are important for this issue, because if you just comment Add of daily bars, the Historical works just fine. Also the period of secondary bars is important. For 15 minutes it is ok, for 480 minutes not. Looks like big ratio of primary and secondary period makes this issue.

    I also tried to SendMail at place where Log() is and NinjaTrader sent me hundred of email also from historical run.

    Is this just bad usage of Historical attribute or real issue?

    Dalibor
    Attached Files

    #2
    Hello Dalibor,
    Unfortunately i am not able to replicate it. If you try the below code then what prints you are getting.

    Code:
    if (Historical) return;
    Print("Historical = " + Historical.ToString() + " BIP " + BarsInProgress.ToString() + " Time= " + Time[0].ToString());

    I look forward to assisting you further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hi Joydeep,

      I attach the txt file with the print, the result is as expected. I tested the issue on my second computer and there I wasn't able to replicate problem too. So maybe some driver related problem? I remember that few days ago I installed Visual Studio 2012 on my first PC, should this have effect to this issue in any way?

      Dalibor
      Attached Files

      Comment


        #4
        Hello Dalibor,
        Glad you could get the correct values.

        No, installing VS 2010 wont affect NinjaTrader.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Hi Joydeep,

          I probably found the source of this problem!!! I found that this problem occur only if you setup Min. bars required as number higher than Days to load, than Historical attribute doesn't work as expected.

          Please check if you can reproduce problem now.

          Dalibor

          Comment


            #6
            Hello dalisdj,
            I loaded 5 days of daily data and have set BarsRequired to 20. With this setting the Historical property is working fine at my end. Can you please let me the exact steps to replicate the scenario.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              Same config makes my Historical false when true expected.

              I attach my configuration, because I really don't know steps to reproduce, maybe we differ still somewhere in setting. Please really make sure you have added 1 Day bars at strategy Initialize, because this is important.

              One another thing I found, if you set Min. bars required = 10, there is range for value Days to load from 14 to 17 where it is impossible to enable strategy, because if you check enabled, strategy automatically change to disabled without any log.
              Attached Files

              Comment


                #8
                Hello dalisdj,
                Yes, I can replicate it.

                The Bars required and days to load is also applicable for the secondary series. You are having a scenario where the number of daily bars is less than the bars to load property and thus facing the scenario. You have to make sure are loading adequate data or set thee bars required to 0 to overcome the scenario.


                Are you getting any messages in the Output Window for any reasons why the strategy gets disabled?

                To assist you further can you please send a toy NinjaScript code* replicating the behavior to support[AT]ninjatrader[DOT]com

                Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

                I look forward to assisting you further.

                *The "toy" just means something that is a stripped down version that isn't necessarily the whole logic. It makes things easier to rout out.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Hi Joydeep,

                  good you can replicate the issue now. Also sent you the "toy" you asked for.

                  I do not get any print to Output Window saying why the strategy was immediately disabled. Last print is **NT** Enabling NinjaScript strategy ... informing about enabling strategy, but strategy is no longer enabled in Strategies Tab.

                  I understand the requirements to correctly setup my strategies now and will follow them to avoid any unexpected behaviour.

                  But even if this issue is made by bad setup, this should be still considered as a bug, because no matter if strategy was setup good or bad, the Historical property has to be always True if works on historical data. e.g. as I mentioned SendMail() method send emails event if it is called on historical data (which is unpleasant situation, if you send email on every update of minute bar).

                  Dalibor

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by inanazsocial, Today, 01:15 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post inanazsocial  
                  Started by trilliantrader, 04-18-2024, 08:16 AM
                  5 responses
                  22 views
                  0 likes
                  Last Post trilliantrader  
                  Started by Davidtowleii, Today, 12:15 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Davidtowleii  
                  Started by guillembm, Yesterday, 11:25 AM
                  2 responses
                  9 views
                  0 likes
                  Last Post guillembm  
                  Started by junkone, 04-21-2024, 07:17 AM
                  9 responses
                  70 views
                  0 likes
                  Last Post jeronymite  
                  Working...
                  X