Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical but Not Real-Time Fill

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

    Historical but Not Real-Time Fill

    I have searched the forums and read the blurb in the manual about the bool "Historical" but haven't figured out to achieve what I desire:

    When running historically, i would like the strategy to exit, but when this exit is encountered in real-time, I want it to be ignored.

    I tried this:

    Code:
    protected override void OnBarUpdate()
    {
    //load a 1 minute chart ES 09-08 with only 1 day history
          if (Historical)
          {
                if (ToTime(Time[0]) == 120000)
                      EnterLong();
                if (ToTime(Time[0]) == 120500)
                      ExitLong();
          }
    }
    For some reason this doesn't plot the markets on my chart, (and yes I have PlotExecutions = Text and Markers). It seems Historical is not becoming true perhaps? I think I probably misunderstand how to use it.

    I'm basically trying to have an entry that I use each day but just use the exit virtually-- just to force the strategy to think it is flat after some arbitrary time ONLY IF the exit bar is a historical bar.

    #2
    Print some values out to see what is happening. Try using TraceOrders = true also. Check Control Center logs for any error messages.


    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Historical Keyword Not Working With Greater Than One Dataseries

      Actually, after a bit more debugging I think I may have found a semi-bug with the Historical boolean keyword.

      I can get it work using only 1 dataseries (i.e. the dataseries applied to the chart). As soon as I use the Add() keyword in initialize section to add a secondary dataseries (another symbol on the same bar interval), the Historical keyword NEVER returns true for either dataseries' OnBarUpdate() event. That is, no historical bars are processed when there is more than 1 dataseries.

      here's an example... just uncomment or comment in the Add() line in the Initalize section and you'll see that when there is more than 1 data series, the Historical keyword never returns true.

      Code:
              protected override void Initialize()
              {
                  ExitOnClose = false;
                  BarsRequired = 0;
                  CalculateOnBarClose = true;
                  TraceOrders = true;
                  
                  //primary series is "ER2 09-08" on 3 second interval with simulator datafeed on
                  //and 10 bars back set on chart
                  
                  //!!! comment this in and out to test
                  Add("EMD 09-08", PeriodType.Second, 3);
                  //!!! comment this in and out to test
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
                  Print(CurrentBar.ToString() + " " + Historical.ToString());
                  if (Historical)
                  {
                      if (BarsInProgress == 0 && CurrentBar == 1)
                      {
                          Print("Historical returned True on DataSeries 0.");
                      }
                      if (BarsInProgress == 1 && CurrentBar == 1)
                      {
                          Print("Historical returned True on DataSeries 1.");
                      }
                  }
              }
      Why is this happening and is this a bug?

      One guess is that when you use the Add() method to add another symbol, the simulator does not backfill it...?
      Last edited by geoMEAN; 09-10-2008, 10:54 PM.

      Comment


        #4
        I don't know why you are getting your behavior. This is what I get:
        Code:
        9/8/2008 1:30:03 AM CurrentBar: 10 BarsInProgress: 1 Historical: True
        9/8/2008 1:54:15 AM CurrentBar: 11 BarsInProgress: 1 Historical: True
        9/8/2008 3:15:39 AM CurrentBar: 12 BarsInProgress: 1 Historical: True
        9/8/2008 3:16:00 AM CurrentBar: 13 BarsInProgress: 1 Historical: True
        9/8/2008 3:20:09 AM CurrentBar: 14 BarsInProgress: 1 Historical: True
        9/8/2008 3:30:06 AM CurrentBar: 15 BarsInProgress: 1 Historical: True
        9/8/2008 3:53:00 AM CurrentBar: 1 BarsInProgress: 0 Historical: True
        9/8/2008 3:54:00 AM CurrentBar: 2 BarsInProgress: 0 Historical: True
        9/8/2008 3:54:36 AM CurrentBar: 16 BarsInProgress: 1 Historical: True
        9/8/2008 3:55:15 AM CurrentBar: 17 BarsInProgress: 1 Historical: True
        9/8/2008 3:55:39 AM CurrentBar: 18 BarsInProgress: 1 Historical: True
        9/8/2008 3:56:00 AM CurrentBar: 3 BarsInProgress: 0 Historical: True
        9/8/2008 3:58:21 AM CurrentBar: 19 BarsInProgress: 1 Historical: True
        9/8/2008 3:58:30 AM CurrentBar: 20 BarsInProgress: 1 Historical: True
        9/8/2008 3:58:39 AM CurrentBar: 21 BarsInProgress: 1 Historical: True
        9/8/2008 3:59:06 AM CurrentBar: 22 BarsInProgress: 1 Historical: True
        9/8/2008 4:00:24 AM CurrentBar: 23 BarsInProgress: 1 Historical: True
        9/8/2008 4:00:54 AM CurrentBar: 24 BarsInProgress: 1 Historical: True
        9/8/2008 4:02:00 AM CurrentBar: 4 BarsInProgress: 0 Historical: True
        9/8/2008 4:02:36 AM CurrentBar: 25 BarsInProgress: 1 Historical: True
        9/8/2008 4:02:57 AM CurrentBar: 26 BarsInProgress: 1 Historical: True
        Notice historical prints true for everything. Please ensure you have data for all your instruments. I suggest you just use Add(PeriodType.Minute, 5); instead of 3 seconds on a separate instrument.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Josh,

          Thank you. Problem solved.

          The problem was that I did not have history for the 2nd symbol. If you use the Simulator to generate fake data and don't have fake history for that symbol, it just starts at the current live bar.

          However, when I open a second fake simulator chart of the EMD 09-08 and let it create some fake history, and then I apply the strategy I posted above to the ER2 09-08 chart, I get Historical to return true.

          Thanks again for help with this seemingly unimportant problem.

          Comment

          Latest Posts

          Collapse

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