Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trigger at a certain day and execute an order the next possible Session or Tick

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

    Trigger at a certain day and execute an order the next possible Session or Tick

    Hi guys, i'm new to this forum but looking for an answer i can't find so far or figure out myself.

    I'm working wit NJ8 and doing a lot of strategies and backtesting there. Now i'm trying something timebased but hit a brick wall. to As the title suggests, i'm trying to trigger at certain times, which can fall outside of trading hours. Sundays and holidays seem to be the issue here, where no signal is triggert.

    for example:
    DayOfTheMonth = 1;
    if (Time[0] == DayOfTheMonth )
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"");
    }

    I would have expected to get 12 entries (due to pending orders when outside trading hours). Didn´t happen.

    Tried to iterate it by reading the day:

    i.e. if (Time[0] == DayOfWeek.Sunday ) {...AddDays(1) } or {DayOfTheMonth+1}
    as well as stuff like if (TradingHours.Holidays.ContainsKey(currentDay.Date )) {...}

    but had no effect.

    Any ideas what i am doing wront or how to make it right so i'll get my n-triggers?

    Thanks a lot for your help.​

    #2
    Hello Seiko,

    Thank you for your post and welcome to the NinjaTrader forums!

    I recommend adding Print() statements to debug your script. For more information about using prints:


    For example, if you simply print the value of Time[0] the output would be a DateTime structure. The following line produces the output shown:
    Print("Time[0]: " + Time[0]);

    Output: Time[0]: 12/19/2022 9:10:00 AM
    World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.


    This means that checking if Time[0] = DayOfTheMonth with a value of 1 wouldn't be equal to each other. You would have to use the Day property like Time[0].Day. To get the day of the week from Time[0] it would be Time[0].DayOfWeek. For more information about DateTime and the properties available, please see the following publicly available page from the Microsoft website:


    Please let us know if we may be of further assistance.

    Comment


      #3
      Thank your for your reply.

      I did try that debugging via the print. But on saturday, sunday and holiday it won't be triggerd. And orders (i.e. EnterLong) won't be triggered if it is a holiday (i.e. January 1st.)

      For example:

      int DayOfTheMonth = 1;

      DateTime currentDay = Time[0].Date;


      if (currentDay.Day == DayOfTheMonth)
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), @"");
      }​

      -> used on ^SP500, 1.1.2022-18.12.2022 should generate 12 Entries, but does only 9.

      How to get the others, that wont trigger due to holidays?

      Comment


        #4
        Hello Seiko,

        Thank you for your reply.

        In some cases, there are different market hours on holidays or some markets are closed on a holiday or weekend. It is possible that there isn't data available for some of those days. To verify, you could go to Control Center > Tools > Historical Data and verify if there is data on the 1st of each month. If there is no data, then the backtest won't be able to process any historical order fills for that day.

        For example, October 1st of this year was a Saturday so the market was not open. This is not a limitation of NinjaTrader or the backtest; there is no market data available for that day due to the market hours.

        Please let us know if we may be of further assistance.

        Comment


          #5
          Hello Emily, and thx for your support.
          Unfortunatelly -no market data- seems to be the issue. Without, nothing seems to get triggered and so far i found no adaptive workaround. Guess i'm going to take a different approach now.

          Anyway, thanks for the assistance and happy holidays.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          627 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          359 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          105 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          562 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          567 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X