Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

time restrictions in code

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

    time restrictions in code

    My code is set up as below, whereas it restricts any trading during the Wednesday inventory report for a time.

    I would also like to add an additional time, which starts trading at 1701, and stops trading at 1529 the next day, but I can't figure out how to code this.


    {
    if (Time[0].DayOfWeek != DayOfWeek.Wednesday || ToTime(Time[0]) <= 091500 || ToTime(Time[0]) >= 094500)

    EnterLongLimit(Close[0] - 0 * TickSize);
    }

    Can you help?

    #2
    Hello,

    Thank you for the post.

    You can separate the logic used to first check the Wednesday condition, then check the time frame to trade after that.


    Example:

    Code:
    // Do not trade if Wednesday between 9:15 and 9:45 AM.
    if (Time[0].DayOfWeek == DayOfWeek.Wednesday && ToTime(Time[0]) >= 91500 && ToTime(Time[0]) <= 94500) return;
       
       // Only trade when time is greater than 5:01 PM or less then 3:29 PM.
    if (ToTime(Time[0]) <= 152900 || ToTime(Time[0]) >= 170100)
       {
        // Your trade logic here.
       }
    Please let us know if we may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 11-21-2017, 03:10 PM.

    Comment


      #3
      Thanks....I copied your code, as noted below...but it's giving me errors

      // Do not trade if Wednesday between 9:15 and 9:45 AM.
      if (Time[0].DayOfWeek == DayOfWeek.Wednesday && ToTime(Time[0]) >= 91500 && ToTime(Time[0]) <= 94500)) return;

      // Only trade when time is greater than 5:01 PM or less then 3:29 PM.
      if (ToTime(Time[0]) <= 152900 || ToTime(Time[0]) >= 170100)
      {
      EnterLongLimit(Close[0] - 0 * TickSize);
      }

      Comment


        #4
        Hello,

        Thanks for the reply.

        There was an extra parenthesis in the code, I edited my previous post.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        51 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        142 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        275 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X