Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by trilliantrader, 04-18-2024, 08:16 AM
        5 responses
        22 views
        0 likes
        Last Post trilliantrader  
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        3 views
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        68 views
        0 likes
        Last Post jeronymite  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X