Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Closing time depending on a chosen parameter

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

    Closing time depending on a chosen parameter

    I would like to know which string add to my strategy to make it closes automatically every open position depending on a parameter of my choice.
    es
    if the parameter is true the system must close positions at 12:00, reactivate at 13:00 and close positions at 21:00
    if that parameter is false must close positions only at 21:00

    thanks for any help

    #2
    Hello Radagast,

    Thank you for your post.

    You can use DateTime objects to ensure you only trade within certain time periods. These can also be used to close any open positions from your strategy.

    For a reference sample on this matter please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3226

    Please let me know if I may be of further assistance.

    Comment


      #3
      can yuo please make me an example?
      i'm sorry but I'm just starting now to programm in NinjaTrader

      Comment


        #4
        Hello Radagast,

        Thank you for your response.

        You can download an example at the following link: http://www.ninjatrader.com/support/f...ead.php?t=3226

        Download the file to your desktop > then in NinjaTrader go to File > Utilities > Import NinjaScript > select the file on your desktop > Open.

        Once imported you will view the script by going to Tools > Edit NinjaScript > Strategy > SampleTimeFilter > OK.

        Please let me know if you have any questions.

        Comment


          #5
          so if i understand correctly this is the string that i must add to my strategy in order to disable it in the period between 14:00-15:00 and after 21:00

          if ((ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 140000) || (ToTime(Time[0]) >= 150000 && ToTime(Time[0]) < 210000))

          is this ok?
          this string also close all the order pending?
          if it doesn't how can i close all the order pending at a chosen time?

          Comment


            #6
            It would also depend on what you have following up this if statement.

            This if statement only checks your condition. It does not exit existing trades by itself.

            For information on managing orders: http://www.ninjatrader.com/support/h...er_methods.htm

            The filter you typed reads as this

            if ( the current bar time is between 9:30 and 14:00 OR the current bar time is between 15:00 and 21:00)
            //do something

            If you wanted to take trades here you would put your trade logic.
            If you wanted to exit trades outside of these times you would need to setup a different condition to check to see if the time was between those hours and exit open positions if not flat


            We also have education classes for learning NinjaScript: http://www.ninjatrader.com/PremiumEducation.php

            Let me know if I can further assist.
            LanceNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by janefoster, Yesterday, 11:50 PM
            0 responses
            5 views
            0 likes
            Last Post janefoster  
            Started by kaywai, 07-13-2024, 09:05 PM
            3 responses
            27 views
            0 likes
            Last Post kaywai
            by kaywai
             
            Started by stafe, Yesterday, 01:32 PM
            2 responses
            19 views
            0 likes
            Last Post stafe
            by stafe
             
            Started by Jakub, Yesterday, 11:06 AM
            2 responses
            24 views
            0 likes
            Last Post ashpang
            by ashpang
             
            Started by MatthewLesko, 05-21-2021, 09:37 PM
            4 responses
            167 views
            0 likes
            Last Post Mahmad1323  
            Working...
            X