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 argusthome, 03-08-2026, 10:06 AM
      0 responses
      71 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      43 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      25 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      28 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      56 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X