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 judysamnt7, 03-13-2023, 09:11 AM
      4 responses
      57 views
      0 likes
      Last Post DynamicTest  
      Started by ScottWalsh, Today, 06:52 PM
      4 responses
      36 views
      0 likes
      Last Post ScottWalsh  
      Started by olisav57, Today, 07:39 PM
      0 responses
      7 views
      0 likes
      Last Post olisav57  
      Started by trilliantrader, Today, 03:01 PM
      2 responses
      20 views
      0 likes
      Last Post helpwanted  
      Started by cre8able, Today, 07:24 PM
      0 responses
      9 views
      0 likes
      Last Post cre8able  
      Working...
      X