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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        57 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X