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

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 TraderBCL, Today, 04:38 AM
          2 responses
          7 views
          0 likes
          Last Post TraderBCL  
          Started by martin70, 03-24-2023, 04:58 AM
          14 responses
          105 views
          0 likes
          Last Post martin70  
          Started by Radano, 06-10-2021, 01:40 AM
          19 responses
          606 views
          0 likes
          Last Post Radano
          by Radano
           
          Started by KenneGaray, Today, 03:48 AM
          0 responses
          4 views
          0 likes
          Last Post KenneGaray  
          Started by thanajo, 05-04-2021, 02:11 AM
          4 responses
          471 views
          0 likes
          Last Post tradingnasdaqprueba  
          Working...
          X