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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        580 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        335 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        102 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        554 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X