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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X