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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      88 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      134 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      119 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      69 views
      0 likes
      Last Post PaulMohn  
      Working...
      X