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

Close strategy at particular time

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

    Close strategy at particular time

    Hello guys!

    Is posible to close a strategy at particular time (for example at 20 p.m) with "calcule on bar close=true"?.
    If i use "if to time()[0]>200000", the position is closed when the bar close at time> 20 pm (not exactly 20 pm, the real close time is diferent every day) With the "calcule on bar close=true", how can i do it??.

    And, for varius strategies?
    Only with flatten?

    Thanks!!!

    #2
    Hello Aagogueta

    Thank you for your post.

    You would want to use ToTime(Time[0]) and compare against a 6 figure number as such -
    Code:
    int myInt = 200000;
    
    if(ToTime(Time[0]) > myInt)
    {
         if(Position.MarketPosition == MarketPosition.Long)
              ExitLong();
         else if(Position.MarketPosition == MarketPosition.Short)
              ExitShort();
    }
    http://www.ninjatrader.com/support/h...tml?totime.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Aagogueta View Post
      Hello guys!

      Is posible to close a strategy at particular time (for example at 20 p.m) with "calcule on bar close=true"?.
      If i use "if to time()[0]>200000", the position is closed when the bar close at time> 20 pm (not exactly 20 pm, the real close time is diferent every day) With the "calcule on bar close=true", how can i do it??.

      And, for varius strategies?
      Only with flatten?

      Thanks!!!
      Thanks.
      But:
      - Working with tick data
      - Calcule on bar close=true. This is necesary for my strategy.

      Example:
      Bar[1] close at 19:45
      Bar[0] close at 20:26
      The position is closed at 20:26.

      I want to close my position exactly at 20:00.
      How can i do it?.
      Thanks again.

      Comment


        #4
        Originally posted by Aagogueta View Post
        Thanks.
        But:
        - Working with tick data
        - Calcule on bar close=true. This is necesary for my strategy.

        Example:
        Bar[1] close at 19:45
        Bar[0] close at 20:26
        The position is closed at 20:26.

        I want to close my position exactly at 20:00.
        How can i do it?.
        Thanks again.
        You will need to use an event that happens on every tick. You can create a timer, or you can use another handler like OnMarketData().

        Comment


          #5
          Originally posted by koganam View Post
          You will need to use an event that happens on every tick. You can create a timer, or you can use another handler like OnMarketData().
          Thanks koganam!

          Could you give me one example?

          Comment


            #6
            Originally posted by Aagogueta View Post
            Thanks koganam!

            Could you give me one example?
            Code:
            protected override void OnMarketData(MarketDataEventArgs e)
            {
                if (ToTime(e.Time) >= 140000){ExitLong(); ExitShort();}
            }

            Comment


              #7
              Originally posted by koganam View Post
              Code:
              protected override void OnMarketData(MarketDataEventArgs e)
              {
                  if (ToTime(e.Time) >= 140000){ExitLong(); ExitShort();}
              }
              Thanks again!!!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Waxavi, Today, 02:10 AM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by Kaledus, Today, 01:29 PM
              5 responses
              13 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by Waxavi, Today, 02:00 AM
              1 response
              12 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by alifarahani, Today, 09:40 AM
              5 responses
              23 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by gentlebenthebear, Today, 01:30 AM
              3 responses
              17 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X