Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ExitLong(int barsInProgressIndex) overload needed

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

    ExitLong(int barsInProgressIndex) overload needed

    While patiently waiting for higher resolution backtesting in NT8, I have some strategies on exotic bars I need to test with intrabar granularity.
    It is simple to do to Enter (eg. EnterLong(int barsInProgressIndex, int quantity, string signalName) but overly complex to exit, eg,: ExitLong(int barsInProgressIndex, int quantity, string signalName, string fromEntrySignal) is the only overload with BarsArray parameter available.

    In some more advanced strategies I store Collection<IOrder> with some other details to keep track of the entered orders and their signal names but in most cases it is an overkill for a very simple need - to have a simple overload available like: ExitLong(int barsInProgressIndex) or ExitShort(int barsInProgressIndex), the point is to not have to provide fromEntrySignal, just exit all of them on the more granular level.

    I understand you may be reluctant to make any changes right now to NT 7 so I was considering creating a method like (not tested):
    Code:
    private void ExitAllShort(int barsArray)
    {
        foreach (Order order in Orders)
        {
            if (order.Short && order.Filled > 0 && order.OrderState == OrderState.Accepted || order.OrderState == OrderState.Working)
            {
                ExitShort(barsArray, order.Quantity, "Exit " + order.Name, order.Name);
            }
        }
    }
    Only I am not sure what conditions to test for if I want to exit all of them, so your advice would be helpful, eventually if you have some other suggestions to solve it, I am all ears.

    Thanks

    #2
    Hello gregid,

    Thanks for your note.

    Calling ExitLong() without a signal name will exit your entire position.

    For example:

    if (Positions[0].MarketPosition == MarketPosition.Long)
    {
    ExitLong();
    }

    If you have multiple instruments added to your script, and multiple positions with different instruments, calling ExitLong() without a signal name will still exit all orders with all instruments.


    If you are wanting to exit specific positions, this will need to be done with the signal name.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Calling ExitLong() without a signal name will exit your entire position.
      Thank you Chelsea, but I am afraid you've missed my point, so to quote it again:

      point is to [...] just exit all of them on the more granular level.
      I want to ExitLong(int barsInProgressIndex) to simulate higher resolution backtesting, ExitLong() exits on main BarsArray which is exactly what I don't want.

      Comment


        #4
        Hello gregid,

        ExitLong (as well as any working order) will exit on whatever bars in progress uses the same instrument and has the data to exit the order.

        If there are multiple bars in progress that are using the same instrument, you will not be able to choose which bars in progress the order exits on.

        The order will fill on the first bars in progress that uses the same instrument that has a price that will exit the order.

        (With a real time order the order fills whenever the price hits it. In backtest each bars in progress using the same instrument will contribute to the hit prices that can exit the order. (introducing granularity))
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by gregid View Post
          Thank you Chelsea, but I am afraid you've missed my point, so to quote it again:



          I want to ExitLong(int barsInProgressIndex) to simulate higher resolution backtesting, ExitLong() exits on main BarsArray which is exactly what I don't want.
          All the Exit() methods have a barsInProgressIndex override method.

          Agreed, the Set() methods do not.

          Comment


            #6
            It looks like you are not entirely aware of the ways us users circumvent NinjaTrader's limitations around backtesting (for at least few years now), so bear with me while I explain the process. In cases where the bars used cannot guarantee the realistic info (eg. Renko and its derivatives with fake open, lack of wicks etc.) we add secondary (more granular) bar series eg.:
            Code:
            Add(PeriodType.Range, 1); //BarsArray[1]
            Or
            Code:
            Add(PeriodType.Tick, 1); //BarsArray[1]
            where all the order execution happen. All the strategy logic happens only on the main BarsArray so we usually place:
            Code:
            if (BarsInProgress != 0) return;
            On the beginning of the OnBarUpdate(), and while using the main bar series (ie: 0) we enter order with:
            Code:
            EnterLong(1, positionSize, "L" + CurrentBar);
            1 is the 1 range(or tick) bar; this way the order in the bactest is executed on the more granular level giving much more realistic entries.

            Now with this information in mind please reread my first post where I am explaining the problem with equivalent Exits. I usually solve the exits problem by keeping track of the IOrders. Here I am looking for something much simpler - I want to exit all of them on the more granular level and don't need/want to keep track of all orders (to get their entry signal name - required for the only available overload with barsInProgressIndex).

            So what I am in fact asking for is to see (pseudo code) logic NT uses for existing ExitLong() so I can implement my own method that will do the same with barsInProgressIndex as parameter.

            Comment


              #7
              Originally posted by koganam View Post
              All the Exit() methods have a barsInProgressIndex override method.

              Agreed, the Set() methods do not.
              The only available overload with barsInProgressIndex requires also quantity, signal name and from entry signal name which is what I don't have.

              I want a very simple ExitLong(int barsInProgressIndex) and ExitShort(int barsInProgressIndex) and since I cannot have them I want to simulate them as in the pseudo code in my first post.

              Comment


                #8
                Hello gregid,

                You will have to supply a quantity and signal name even if the signal name is a blank string.

                For example:

                ExitLong(0, 1, "");
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_ChelseaB View Post
                  Hello gregid,

                  You will have to supply a quantity and signal name even if the signal name is a blank string.

                  For example:

                  ExitLong(0, 1, "");
                  Not ideal for my particular strategy (which requires multiple entries) as I will miss on controlling the unique EntryHandling but at least with blank or simply constant signalname I will be able to execute the ExitLong overload, which may be reasonable price to pay - will see how it goes

                  Comment


                    #10
                    Originally posted by gregid View Post
                    Not ideal for my particular strategy (which requires multiple entries) as I will miss on controlling the unique EntryHandling but at least with blank or simply constant signalname I will be able to execute the ExitLong overload, which may be reasonable price to pay - will see how it goes
                    You cannot have it both ways. You say that you want to exit with a single statement that has barsInProgressIndex as the only parameter here: "Here I am looking for something much simpler - I want to exit all of them on the more granular level and don't need/want to keep track of all orders (to get their entry signal name - required for the only available overload with barsInProgressIndex)."; then next state that you do not want to "... miss on controlling the unique EntryHandling ...".

                    In any case, you can always write methods that hide parameters if you want to;

                    e.g.,
                    Code:
                    private void YourExitLong(int BarsInProgress)
                    {
                    //Any exit method with the full signature goes here.
                    return;
                    }
                    Last edited by koganam; 03-09-2015, 02:13 PM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post Javierw.ok  
                    Started by timmbbo, Today, 08:59 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post bltdavid  
                    Started by alifarahani, Today, 09:40 AM
                    6 responses
                    40 views
                    0 likes
                    Last Post alifarahani  
                    Started by Waxavi, Today, 02:10 AM
                    1 response
                    18 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by Kaledus, Today, 01:29 PM
                    5 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X