Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade the Open of the Session

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

    Trade the Open of the Session

    This should be an easy one but for some reason cannot figure it out....probably missing something obvious. Not working on backtester.


    My Ask....I want to open an order at the open of the new Trading Session (6PM ET/5 PM CT).....based on criteria of the last session. To keep things simple here is a sample code (tried many things):

    if ((ToTime(Time[0]) >= 180000 && ToTime(Time[0]) <= 180010)) // so first 10 seconds of the new session
    {
    if (Close[0] >= Close[4]) // just one random idea....use the close of the last bar of the last session and compare to the close at 4PM ET (Stock market close) based on a 15 minute bar charts
    {
    EnterLong(QuantitySize, "LongOpen");
    }
    }


    I have other time criteria working without issues.....I just cannot seem to isolate just the open of the session for a specific signal.
    Last edited by BigT4X; 03-17-2023, 11:48 AM.

    #2
    Hello, thanks for writing in. Use a Print() method before and after the entry condition to see if it's becoming true or not. Using Prints is going the be the most valuable tool when you are debugging a strategy that does not work as expected. Right above EnterLong(), add a print to see if your entry condition is becoming true or not.

    Code:
    Print("Checking time constraint against " + ToTIme(Time[0]));
    if ((ToTime(Time[0]) >= 180000 && ToTime(Time[0]) <= 180010)) // so first 10 seconds of the new session
    {
    if (Close[0] >= Close[4]) // just one random idea....use the close of the last bar of the last session and compare to the close at 4PM ET (Stock market close)
    {
        Print("Enter Long Reached " + Time[0]);
        EnterLong(QuantitySize, "LongOpen");
    }
    }

    Comment


      #3
      I added additional prints you suggested (I had some already). There is no 180000 time.....so I changed it to 170000 (last bar of the day).

      All I am trying to do is buy the open of the new session......can you point me to how to isolate the new Session open? This is all I need.

      Changing to 170000.....is buying 15 mins after the open.....

      Results for Time[1] == 170000
      Checking time constraint against 163000
      03-16 16:59:59 PM ET STC LONG EXIT NQ Exit on session close = 12580.5
      Checking time constraint against 164500
      Checking time constraint against 170000
      Enter Long Reached 2023-03-16 6:15:00 PM
      03-16 18:18:38 PM ET LONG BTO NQ ENTRY LongOpen signal = 12575
      Checking time constraint against 181500


      Results for Time[0] == 170000
      Checking time constraint against 164500
      03-16 16:59:59 PM ET STC LONG EXIT NQ Exit on session close = 12580.5
      Checking time constraint against 170000
      Checking time constraint against 181500
      Last edited by BigT4X; 03-17-2023, 01:35 PM.

      Comment


        #4
        Hi, We do have the IsFirstBarOfSession property of the Bars object:


        if (Bars.IsFirstBarOfSession)
        {
        //OnBarUpdate called for the first bar of the session.
        }

        The timestamp you get from the Time[0] array depends on the time series you have selected, so if you hard code a certain time you must make sure the bar time stamps can "land" on that exact time or time range. Using non-time based bars can have random timestamps that are not equal distances away from each other resulting in unreliable time range comparisons.

        Kind regards,
        -ChrisL​

        Comment


          #5
          Yes that will not work because my strategy is set to 'Calculate = Calculate.OnBarClose;' I cannot switch to "OnPriceChange" because there is too much complicated logic.

          So everything I try does not kick in until 18:15:00 (using 15 minute charts) - I am in Eastern Time.

          There seems to be no way to have the 17:00:00 bar signal kick in the at open at 18:00:00. Likely kicking in at 17:00:00 but market closed.

          Comment


            #6
            Hi, this example should help you. This shows how to separate OnBarClose logic from OnEackTick/OnPriceChange.



            Alternate to this, you can add a 1 minute series to your script and check the time and initiate the trade from there, be careful of bar sequencing in the historical data though, per this help guide statement:

            Data processing sequence
            Understanding the sequence in which bars series process and the granularity provided by market data vendors is essential for efficient multi-series development. Let’s assume we have two series (primary and secondary) in our script, which is representing the same instrument, yet different intervals. During historical data processing, NinjaTrader updates the two series strictly according to their timestamps, calling the primary bar series of the corresponding timestamps first, and then calling the secondary series.

            Enabling tick replay will fix this at the cost of higher performance cost while processing historical data. Shared timestamps in both bar series will also result in the primary series being processed before the secondary series.

            Kind regards,
            -ChrisL​​

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, 03-13-2026, 05:17 AM
            0 responses
            95 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            153 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            80 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            54 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            70 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X