• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

No entries at certain times

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

    No entries at certain times

    Hi, I have the following:

    if(ToTime(Time[0]) >= 170000 || ToTime(Time[0]) <= 154500)
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if (Condition)
    {
    EnterLong();
    }

    How do I add to the script if I do not want to enter any positions during 12am – 2am nor 6am – 8am and if there are any positions prior to 12am or 6am to exit based on the strategy instead of exiting at that given time.
    Thanks

    #2
    Hello 2Look4me,

    Thanks for your post.

    You could check something like the following to check that you are within your desired time frame and call ExitLong/ExitShort to exit positions if the strategy is not flat.

    Code:
    if (Time[0] >= 0 && ToTime(Time[0]) <= 20000))
    {
        if (Position.MarketPosition != MarketPosition.Flat)
        {
            ExitLong();
            ExitShort();
        }
    }
    Similarly, you can make time checks to check if the time is between 6am and 8am with a check like the following and perform your same logic to exit if you are not flat.

    Code:
    if (Time[0] >= 60000 && ToTime(Time[0]) <= 80000))
    You can then use else statements with these checks for when trading should occur outside of these time checks.

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim, thanks for the prompt reply. It seems like your suggestion is to exit the position outright. Is there a function/command/script that will not allow entries based on the strategy at those given times of 12a-2am and 6a-8am, but will allow "Exits" based on the strategy if the entry happened before 12am or 6am?

      Comment


        #4
        Hello 2Look4me,

        There would not be built in method for this. This would involve building logic using time checks to control when your strategy should do certain actions. You could set some bool variables in your script to control when "AllowEntries" should be set to true/false and when "AllowExits" should be set to true/false. You could then use those bools to control your logic throughout your script.

        Alternatively, you can write your script so your desired actions take place within your time checks.

        Please let me know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Thanks for you suggestions.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TazoTodua, Today, 04:26 PM
          0 responses
          1 view
          0 likes
          Last Post TazoTodua  
          Started by ScorpioTravis, Today, 04:26 PM
          0 responses
          1 view
          0 likes
          Last Post ScorpioTravis  
          Started by ralett, Today, 03:09 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by martyn73, Today, 02:54 PM
          2 responses
          13 views
          0 likes
          Last Post martyn73  
          Started by Zigfried, Today, 01:59 PM
          4 responses
          14 views
          0 likes
          Last Post Zigfried  
          Working...
          X