Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical data

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

    Historical data

    I have developed strategy, that is supposed to run only based on real-time data (since it can't run on historical). Entry orders are set up only at predefined by parameters time.
    The problem with strategy is that sometimes it won't start at predefined time.
    Now when I come to test strategy on different contracts, some instances of strategy wont' start. I have added logging into onBarUpdate (see below). Messages are not printed as well.
    Code:
            protected override void OnBarUpdate()
            {
                if (Historical) return;
                
                Log("Processing bar : " + Time[0].ToString(), LogLevel.Information);
                if (Time[0].TimeOfDay == _startTime.TimeOfDay)
                       //Do the entry logic
            }
    So for example I start strategy and set up it to start at 23:20, 3 minutes before that time - strategy won't start.
    My question is why doesn't it start? Is that a problem with my feed - so in some cases it deems real-time data as historical?
    I would really appreciate any suggestions.

    #2
    Andreano,

    I would suggest changing this line :

    if (Time[0].TimeOfDay == _startTime.TimeOfDay)

    Use something more like a built in comparison method for DateTime objects :

    Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.


    Or the ToTime() function.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your suggestion.
      I guess I still can't get used to the idea that C# doesn't have operator overloading and that one should usually look for Compare method of IComparable interface to perform comparison of objects.
      TimeSpan objects are compared, not a DateTime though.
      TimeSpan == logically worked out as I expected it to.
      Указывает, равны ли два TimeSpan экземпляра.

      Anyway thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      64 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      149 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      99 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      286 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X