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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        46 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        14 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        20 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X