Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      I believe that worked. I appreciate it!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,221 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      9 views
      0 likes
      Last Post FAQtrader  
      Working...
      X