Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with closing additional Bars positions

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

    Problem with closing additional Bars positions

    Hi,

    I've just got a problem which cannot resolve by myself. I'm using two Bars objects and process all the events (entering/exiting positions) within the context of the primary Bars:

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0) return;
    }

    I have no problem entering Short positions for the second Bars instrument: "entryOrder = EnterShort(1, aIQ, "IQ");" But CANNOT close those short positions by executing: "exitOrder = ExitShort(1, "", "");" It simply doesnt's work. Although it perfectly closes all the primary Bars positions. What would be the reason?

    Thank you!

    #2
    Can you add the TraceOrders = true; to your Initialize.

    Are you getting any Ignored Entry signals? If so, what is the reason? Does it not find the position on the added instrument?
    MatthewNinjaTrader Product Management

    Comment


      #3
      I have added "TraceOrders = true;" and got the following:

      Ignored PlaceOrder() method: Action=BuyToCover OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MyExit' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'

      I'm not quite understand. There were definitely positions to close.

      Comment


        #4
        I have also noticed, that as soon as I place an exit order within the context of the primary Bars, "Positions.MarketPosition" returns "flat" although the same command returns "short" outside the OnBarUpdate() block. I call it twice--second time withing the OnPositionUpdate(). Looks like within the context of the primary Bars it doesn't place exit orders for the second Bars instruments.

        Comment


          #5
          You need to use the fromEntrySignal in your exit method:

          Code:
          EnterShort(1, aIQ, "IQ");
          ....
          ExitShort(1, 1, "exit", "IQ");
          This should allow the exit method to find the position from the EnterShort signal.
          MatthewNinjaTrader Product Management

          Comment


            #6
            What does the second "1" mean in "ExitShort(1, 1, "exit", "IQ");". Is this a typo?

            Comment


              #7
              Quantity:

              Code:
              ExitShort([COLOR="Blue"]int[/COLOR] barsInProgressIndex, [COLOR="blue"]int [/COLOR]quantity, [COLOR="blue"]string [/COLOR]signalName, [COLOR="blue"]string [/COLOR]fromEntrySignal)
              MatthewNinjaTrader Product Management

              Comment


                #8
                Yes, it works if I use "quantity". But does this mean that I cannot close all the "secondary Bars" positions without stating the quantity (as I do for "primary Bars") and therefore should write something like: "exitOrder = ExitShort(1, Positions[1].Quantity, "exit", "IQ");"? Because the problem here is that "Positions[1].Quantity" gives me the size of the entire position, not the size of a position from a specific entry signal.

                Is it possible to obtain a position size for a specific entry signal?
                Last edited by dmitry75; 08-22-2013, 01:49 PM.

                Comment


                  #9
                  Yes, you need to state the quantity if you're submitting to another bars array.

                  You could use OnExecution to track when a Signal name was execute, and then store that executions quantity to be used for later:

                  Code:
                  		protected override void OnExecution(IExecution execution)
                  		{
                  		  if(execution.Name == "entry");
                  			{
                  			 qty = execution.Quantity;
                  			}
                  			
                  		}
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    How would you suggest to track the quantity by individual entry signals using OnExecution?

                    Comment


                      #11
                      You can check for the name of the execution using execution.Name. You can then check to see if that is equal to the specific entry signal name you used. If that condition is satisfied, you can grab the execution quantity for just that signal name.

                      Does the code sample I posted in #9 not help?
                      MatthewNinjaTrader Product Management

                      Comment


                        #12
                        Actually, yes. This code is exactly what I need, thank you. By the way, in post #5 you said that I "need to use "fromEntrySignal" in my exit method. It turned out that it's not necessary. I can still close second Bars positions without using "fromEntrySignal" but must know the quantity.

                        You're guys providing an excellent technical support.
                        Last edited by dmitry75; 08-25-2013, 04:43 PM.

                        Comment


                          #13
                          Hello dmitry75,

                          Thanks for the kind words. We are glad everything is working.

                          Let us know if we can be of further assistance.
                          JCNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          666 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          376 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          110 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          575 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          580 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X