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

Problem with ExitOnClose

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

    Problem with ExitOnClose

    I am working with 30 minutes time frame on instrument 0, and 1 minute on instrument 1.

    I want to close positions everyday, so I set a IF condition like this:
    if (ToTimes(Times[1][0]) =154000)
    {
    //close anyopen position.
    }
    The problem is, as I set calculatedOnBar=true; the system waits the last bar to act and at 16.00 the marketclosesand positions arenot closed.
    How can I handle it to close at 155200, in case I want to.

    #2
    Hello dafonseca,

    Thank you for your inquiry.

    You would want to exit your positions on a different time frame rather than the primary time frame you are running on (which is 30 minutes).

    What you can do is submit your exit order against the one minute time frame to exit at a one minute interval time rather than a 30 minute interval.

    Assuming your one minute interval is the secondary DataSeries....

    Code:
    if (BarsInProgress == 1)
    {
         if (ToTimes(Times[1][0]) >= 155200)
              ExitLong();
    }
    For more information about working with multiple time frames and instruments, please take a look at the NinjaTrader help guide at this link: http://ninjatrader.com/support/helpG...nstruments.htm
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      It is weird.
      I am using this.
      if (BarsInProgress == 1)
      {
      Print ("time 0 : " + ToTime(Times[0][0]) + " time 1 : " + ToTime(Times[1][0]));

      if(ToTime(Times[1][0]) == ToTime(15,35,00))// &&
      {
      if (Position.MarketPosition == MarketPosition.Long)
      {

      ExitLong();
      }
      if (Position.MarketPosition == MarketPosition.Short)
      {
      ExitShort();
      }

      }
      }
      outLook windows shows that the Print works fine, But my system is still generating exit on close at 16.00. A question would be. does intrument 0 accepts a exit order at a different timeframe(each 30 minutes)? It seems that only orders at each 30 minutes (timeframe)has been accepted,

      Comment


        #4
        Hello dafonseca,

        If you wish to prevent your strategy from exiting upon the close of a session, ensure that you are using the ExitOnClose property and setting it to false in Initialize(). More about ExitOnClose can be found here: http://ninjatrader.com/support/helpG...xitonclose.htm

        I would suggest taking a look at this particular reference sample on our support forum detailing entering on one time frame and exiting on another: http://ninjatrader.com/support/forum...ead.php?t=5787

        For your 1 minute time frame, are you using the same instrument as the primary? If not, you will need to create another 1 minute time frame, without specifying an instrument, so a 1 minute Bars object will be added that utilizes the same instrument as your primary instrument so you can exit a position on that particular instrument.

        Example:
        Code:
        Add(PeriodType.Minute, 1);
        You will then want to use BarsInProgress == 2, rather than 1, as this object would be in BarsArray[2].
        Zachary G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, Today, 01:16 PM
        2 responses
        8 views
        0 likes
        Last Post cre8able  
        Started by chbruno, 04-24-2024, 04:10 PM
        3 responses
        48 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by WHICKED, Today, 12:56 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by WHICKED, Today, 12:45 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X