Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Profit Target is Ignored

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

    Profit Target is Ignored

    In the attached code, you will see a dummy strategy (if EMA(5) > EMA(15), Buy, otherwise, Short). The purpose of this strategy is to illustrate the adjustment of Stop Targets. So if the price goes in the direction of the trade, I adjust the stop loss to be the entry price or a few ticks above or below the entry price depending if the order was a Long or Short. I am noticing that my Profit Target is being ignored for certain orders (see attached chart screen shot). In the chart, you can see I enter a Short, but I exit at my StopTarget. Clearly, I should have exited at my Profit Target at 4 ticks. I have attached the code and Strategy Analyzer inputs I used. Does anyone know why this behavior is occurring?
    Attached Files

    #2
    Hello lewisquake,

    Thank you for your post.

    Here's what I'm seeing in the Trace Orders for that date of a backtest:

    7/30/2020 1:00:00 AM Strategy 'BreakEvenStop/-1': Entered internal SubmitOrderManaged() method at 7/30/2020 1:00:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MyEntry' FromEntrySignal=''
    Bar: 539
    Current Position: Flat
    3221.5
    We entered at 7/30/2020 1:00:00 AM
    7/30/2020 1:00:00 AM Strategy 'BreakEvenStop/-1': Entered internal SubmitOrderManaged() method at 7/30/2020 1:00:00 AM: BarsInProgress=1 Action=BuyToCover OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3226.50 SignalName='MyStop' FromEntrySignal='MyEntry'
    7/30/2020 1:00:00 AM Strategy 'BreakEvenStop/-1': Entered internal SubmitOrderManaged() method at 7/30/2020 1:00:00 AM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=3220.50 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyEntry'
    7/30/2020 1:00:00 AM Strategy 'BreakEvenStop/-1': Ignored SubmitOrderManaged() method at 7/30/2020 1:00:00 AM: BarsInProgress=1 Action=Sell OrderType=Limit Quantity=1 LimitPrice=3220.50 StopPrice=0 SignalName='MyTarget' FromEntrySignal='MyEntry' Reason='This was an exit order but no position exists to exit'


    Basically, the order is being ignored because you're using the incorrect exit order for the position type, you're using ExitLongLimit to try to place your profit target for a short order when you should be using ExitShortLimit:

    Code:
    else if(Position.MarketPosition == MarketPosition.Short){
    stopOrder = ExitShortStopMarket(1, true, execution.Order.Filled, execution.Order.AverageFillPrice + StopLossTicks * TickSize, "MyStop", "MyEntry");
    targetOrder = [B]ExitLongLimit[/B](1, true, execution.Order.Filled, execution.Order.AverageFillPrice - ProfitTicks * TickSize, "MyTarget", "MyEntry");
    entryprice = execution.Order.AverageFillPrice;
    }
    If you correct that I suspect you'll see it behave as you expect.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      I believe that worked. I appreciate it!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, Yesterday, 09:41 PM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      31 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      30 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-25-2026, 09:53 PM
      0 responses
      34 views
      0 likes
      Last Post CaptainJack  
      Started by CaptainJack, 03-25-2026, 09:51 PM
      0 responses
      19 views
      0 likes
      Last Post CaptainJack  
      Working...
      X