Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder Indicator Stop Loss Help

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

    Strategy Builder Indicator Stop Loss Help

    Hello, I've been testing several strategies using the Strategy Builder, and I'm having an issue attaching a stop loss to an indicator.

    I'm trying to do the following:

    If all condition are met, go long.
    Set stop loss at the 50sma.

    Here the command from strategy builder:
    SetStopLoss("", CalculationMode.Price, SMA(Close, 50)[0], false);

    When I run a strategy analyzer or try to enable this strategy on a chart no results pop up, it's as if the strategy has never run.

    If I remove this line the strategy runs fine, it just bounces back and forth between the Long and Short conditions.

    Any Hints? Or can you not attach an indicator using Strategy Builder?
    Thanks.
    Mark.

    #2
    Hello Mark@NightOwlTrading,

    Thanks for your post and welcome to the NinjaTrader forums.

    In the strategy builder, you can only use static profit and stop targets, for example CalculationMode.Ticks, 20. The set methods, in the strategy builder, are placed in the State.Configure section of OnStateChange() which would limit changes to what could be set at run time. For example as a user input you can set the number of ticks to use (for stop or for profit or both) and when the strategy is run it would use that value from the UI and would apply those values to all trades made.

    Alternatively, you could add condition sets that check to see if you are long or short and then place an appropriate exit limit order at the dynamically changing SMA, however in doing so you would not be able to use the set methods as well as this would cause conflicts with the internal order handling rules here: http://ninjatrader.com/support/helpG...d_approach.htm

    Alternatively, to dynamically use the set methods (which are OCO linked) if you wish to unlock the code, then you can move the SetStopLoss() method into the OnBarUpdate where it can be dynamically assigned per your example. However once unlocked you would not be able to access the strategy through the strategy builder and could only work through the Ninjascript editor.

    References:

    Comment


      #3
      Thanks for the info. I did exactly what you directed, and my strategy is working great.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Today, 05:17 AM
      0 responses
      52 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      130 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      70 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      43 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      48 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X