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 Stanfillirenfro, Today, 07:23 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            2 responses
            20 views
            0 likes
            Last Post cmtjoancolmenero  
            Started by olisav57, Yesterday, 07:39 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cocoescala, 10-12-2018, 11:02 PM
            7 responses
            944 views
            0 likes
            Last Post Jquiroz1975  
            Started by oviejo, Today, 12:28 AM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X