Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss and SetProfitTarget

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

    SetStopLoss and SetProfitTarget

    Hi All,

    I'm new to NJ, so please forgive me if this is not a very smart question.

    I'm trying to modify a default crossover strategy that goes with NJ. I'd like to add stop and profit targets to this strategy.

    In initialize() method I've added the following lines:
    SetStopLoss(CalculationMode.Percent, 2);
    SetProfitTarget(CalculationMode.Percent, 5);

    In my onBarUpdate() I have the following:
    bool isFlat = Position.MarketPosition == MarketPosition.Flat;

    if (isFlat && CrossAbove(SMA(Fast), SMA(Slow), 1))
    EnterLong();
    else if (isFlat && CrossBelow(SMA(Fast), SMA(Slow), 1))
    EnterShort();


    I was assuming that the effect would be that after I enter long, the stop and profit targets would be set. But this does not seem to happen.

    I'm working with EOD data from Yahoo.

    Please, let me know what I'm doing wrong here.

    Thanks.

    #2
    Welcome to the forums - correct they should be 'set' if added this way, however for 2 and 5 percent you want to enter a value of 0.02 and 0.05, so this is likely the reason you don't see them getting 'hit' during testing.

    Comment


      #3
      Thanks

      Thank you, Bertrand, this makes sense now.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by charlesugo_1, 05-26-2026, 05:03 PM
      0 responses
      61 views
      0 likes
      Last Post charlesugo_1  
      Started by DannyP96, 05-18-2026, 02:38 PM
      1 response
      148 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 05-11-2026, 05:56 AM
      0 responses
      162 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 05-10-2026, 08:12 PM
      0 responses
      98 views
      0 likes
      Last Post CarlTrading  
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      286 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Working...
      X