Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade filter based on time to market open/close

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

    Trade filter based on time to market open/close

    Hi,

    I am backtesting a strategy over multiple markets and want to have a parameter that allows me to specify a time filter so that I don't trade x minutes prior to the market close. I could easily do this by specifying the time myself in each case but this is not ideal as some of these markets close at different times to others. Is there a way of writing code in the following way:

    // Test on trade entry
    if( time >= market open + nMins && time <= market close - nMins
    && //other tests )
    {
    enter trade
    }

    Where market open and close are universally understood time values that I don't need to specify in each case.

    Thanks,
    darmbk.

    #2
    darmbk, what you could look into adding / accessing from your script are the actual session begin / end times used for your instrument.



    Then you had a way to dynamically use the appropriate template for each unique instrument and set the trades times as needed including your offset nMins.

    Comment


      #3
      Hi Bertrand,

      I see from your link how to get the sessionEnd and as a Datetime object:

      if (Bars.FirstBarOfSession)
      Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);

      I can't find an example in the help where I would reduce a DateTime value (sessionEnd) by number of bars. Could you point me to an example please? I can see how to do it using AddHours or AddMinutes for a time difference.

      Thanks,
      darmbk.
      Last edited by darmbk; 10-01-2014, 07:00 AM. Reason: Correction, I only can't do it for the number of bars

      Comment


        #4
        Darmbk,

        You would need to add a calculation to the AddMinutes() for the Bar value * number of bars for time based bars

        You can use the DateTime object to test the time against.

        Time[0] >= sessionBegin.AddMinutes(BarsPeriod.Value * numberOfBars) && Time[0] <= sessionEnd.AddMinutes(-BarsPeriod.Value * numberOfBars)
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

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