Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss and SetProfitTarget Assistance Needed

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

    SetStopLoss and SetProfitTarget Assistance Needed

    Hello,

    I am attempting to code a simple short term long only strategy. For Profit Target and Stop Loss exits my attempts are:

    Code:
     if (Position.MarketPosition == MarketPosition.Long)
      //(BarsSinceEntry() > 0)
    {
    SetProfitTarget(CalculationMode.Price, (Position.AvgPrice + ATR(5)[0]));
    SetStopLoss(CalculationMode.Price, (Position.AvgPrice - ATR(5)[0]));
    }
    I want to take profit at my entry price plus ATR(5) and reverse for stop loss.

    There are no compiling errors. My problem is that the exit values when backtesting are close to the nominal ATR value (rather than nominal ATR value plus/ minus the entry price). I am a beginner coder and cannot find the correct coding on any of the forums. Any direction for the proper code or helpful links would be appreciated.

    Thanks!

    #2
    Hi Scotty.Trump,

    What instrument is this on? It's possible that the value is negligible and you are seeing it as the same value of the current price.

    A few things to check...
    1. You can print the ATR value to the output using Print() statements
    Something like... Print(ATR(5)[0]);
    Print() - http://www.ninjatrader-support.com/H...ide.html?Print

    2. You can use TraceOrders to check if the orders are being submitted at a price you expect.
    TraceOrders - http://www.ninjatrader.com/support/f...ead.php?t=3627

    3. Also, ensure you are resetting the prices, as detailed in this sample - http://www.ninjatrader.com/support/f...ead.php?t=3222
    TimNinjaTrader Customer Service

    Comment


      #3
      Thank you Tim. I am testing on all instrument components in S&P. Thanks again, I will take a look.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      85 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      48 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      29 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      32 views
      0 likes
      Last Post TheRealMorford  
      Started by Mindset, 02-28-2026, 06:16 AM
      0 responses
      67 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Working...
      X