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 sjsj2732, Yesterday, 04:31 AM
      0 responses
      39 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      289 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      289 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      135 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      96 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X