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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        134 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        75 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        119 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        114 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        92 views
        0 likes
        Last Post CarlTrading  
        Working...
        X