Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Not Exiting at Initial Profit Target

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

    Not Exiting at Initial Profit Target

    I am testing the conditions of my strategy now and all of the entry criteria works perfectly. So that is really great. Thank you to everyone who has helped me so far.

    Now comes the laborious task of testing all of the exit criteria and there is one glaring issue. The initial profit target is not being honored. It is not closing out of that part of the trade.

    The basic idea is that a series of conditions creates a Signal Candle and from that signal candle the entry, stop, & target prices come - all done with percentages of the signal candle.

    I have attached a picture of one of the trades. As you can see, 2 entries were done at 135.83 and exited at a nice profit at 142.06.

    The problem is that the blue line is where LongEntryA should have exited. (FYI, this is not actually where is should exit in real trading - it is just the settings that I have in the code for now).

    Below is code that I have that I think is pertinent to help someone find where my error is.

    Code:
    Variables:
    		// Variables dealing with Actual Entries & Exits
    		private IOrder LongEntryA; // This is the name of the Long Entry A Order
    		private IOrder LongEntryB; // This is the name of the Long Entry B Order
    		private IOrder LongStopA; // This is the name of the Long Entry A Stop Order
    		private IOrder LongStopB; // This is the name of the Long Entry B Stop Order
    		private IOrder LongLimit;
    
            protected override void OnBarUpdate()
            {
    			/* Conditions for Long Entry */
                if (Close[0] > Open[0]
                    && Close[0] > MAEnvelopes(MAEPerc, 3, 25).Upper[0]
                    && Aroon(14).Up[0] == 100
                    && Close[0] > ParabolicSAR(0.02, 0.2, 0.02)[0]
                    && Close[0] > Ichimoku(9, 26, 52).KijunSen[0]
                    && Close[0] > SMA(SMAPeriod)[0]
    				&& !barResetUp)
    			{
    				signalHigh = High[0];
    				signalLow = Low[0];
    				
    				//Order Entries A & B
                    LongEntryA = EnterLongStop(DefaultQuantity, TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongEntry[0], "LongEntryA");
                    LongEntryB = EnterLongStop(DefaultQuantity, TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongEntry[0], "LongEntryB");
    				
    				// Initial Stop Losses & Profit Target
    				LongLimit = ExitLongLimit(TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongTarget[0],"LongLimit","LongEntryA");
    				LongStopA = ExitLongStop(TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongStop[0],"LongStopA","LongEntryA");
    				LongStopB = ExitLongStop(TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongStop[0],"LongStopB","LongEntryB");
    				barResetUp = true;
                }
    Would somebody have an idea of why the trade is not closing out at the initial target?
    Attached Files

    #2
    jg123, great work so far - I would expect though the first target not hitting as you don't have an entry scale in order for it via your code. You have 3 exits uniquely linked to an entry, so you would want to have three entries as well and not only 2. Here's a further sample that would go over scaling out for a strategy - http://www.ninjatrader.com/support/f...ead.php?t=3751

    Comment


      #3
      Thanks Bertrand

      Okay, now I am really confused. haha

      It looks to me like I have 2 entry orders.

      The first one ("LongEntryA") has a profit target ("LongLimit") and a stop loss ("LongStopA") of which both are associated with "LongEntryA" and the second entry order ("LongEntryB") has only a stop loss order ("LongStopB") which is associated with "LongEntryB".

      I looked at the sample code that you sent me (thank you!) and it doesn't appear that IOrder variables are being used. I heard that it is much more difficult & quite possibly inaccurate to try and use scaling orders without using IOrder variables. For example, as soon as LongEntryA hits its profit target, LongStopB is supposed to move closer to the price (a little less than breakeven - and the calculation is based on the price at which LongEntryA exited).

      Am I still on the right track by using IOrder?

      Can you show me how I have 3 exit orders linked to the entry order? I am only supposed to have 2 entries...1 of those entries are supposed to have a profit target and a stop and the other only a stop.

      Comment


        #4
        Hi jg123, apologies - I see what you're saying now. The orders get likely ignored as not position would exist yet at the point you're trying to submit them at - why the exact ignore would have happend, please run with TraceOrders enabled in your script's Initialize().



        For the order submission with the IOrders, it would be best to submit them in from the OnExecution() method when you are receiving the fill events for your entries, that would be the earliest possible point the orders could be sent.

        Here's a sample that would introduce the needed skeleton - http://www.ninjatrader.com/support/f...ead.php?t=7499

        Comment


          #5
          Great! thank you!

          Here is what happened when I traced the orders:
          11/19/2013 11:00:00 PM Entered internal PlaceOrder() method at 11/19/2013 11:00:00 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=135.83 SignalName='LongEntryA' FromEntrySignal=''
          11/19/2013 11:00:00 PM Entered internal PlaceOrder() method at 11/19/2013 11:00:00 PM: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=135.83 SignalName='LongEntryB' FromEntrySignal=''
          11/19/2013 11:00:00 PM Entered internal PlaceOrder() method at 11/19/2013 11:00:00 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=0 LimitPrice=136.84 StopPrice=0 SignalName='LongLimit' FromEntrySignal='LongEntryA'
          11/19/2013 11:00:00 PM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=0 LimitPrice=136.84 StopPrice=0 SignalName='LongLimit' FromEntrySignal='LongEntryA' Reason='This was an exit order but no position exists to exit'
          11/19/2013 11:00:00 PM Entered internal PlaceOrder() method at 11/19/2013 11:00:00 PM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=133.92 SignalName='LongStopA' FromEntrySignal='LongEntryA'
          11/19/2013 11:00:00 PM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=133.92 SignalName='LongStopA' FromEntrySignal='LongEntryA' Reason='This was an exit order but no position exists to exit'
          11/19/2013 11:00:00 PM Entered internal PlaceOrder() method at 11/19/2013 11:00:00 PM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=133.92 SignalName='LongStopB' FromEntrySignal='LongEntryB'
          11/19/2013 11:00:00 PM Ignored PlaceOrder() method: Action=Sell OrderType=Stop Quantity=0 LimitPrice=0 StopPrice=133.92 SignalName='LongStopB' FromEntrySignal='LongEntryB' Reason='This was an exit order but no position exists to exit'
          so it is quite clear now that the order was not placed because there was no position to close out of.

          It also appears that it has ignored the stop orders. This is good to see, as I have not yet started debugging the stop orders and now can maybe kill two birds with one stone.

          So this information should then be moved to the OnExecution() ?

          Comment


            #6
            Yes, you are correct in understanding. You also notice on your first screenshot it didn't exit by the stop but probably by your market order time exit, so yes a good chance to iron that out now.

            Comment


              #7
              That fixed the profit target issue. Thanks!

              That is now leading to some other issues that I am working on trying to fix.

              Seems like a never ending road of problem solving....haha

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              571 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              548 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              549 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X