Announcement

Collapse
No announcement yet.

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 smk200, Today, 10:29 AM
              1 response
              15 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Started by Austiner87, Today, 09:44 AM
              2 responses
              24 views
              0 likes
              Last Post Austiner87  
              Started by TriGuy818, Today, 09:19 AM
              2 responses
              14 views
              0 likes
              Last Post TriGuy818  
              Started by 7robert, Today, 09:12 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by space_trader, Today, 09:11 AM
              3 responses
              29 views
              0 likes
              Last Post NinjaTrader_Kate  
              Working...
              X