Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue on stop loss based on keltner channel lower band

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

    Issue on stop loss based on keltner channel lower band

    Hello,
    I would like to set my stop loss on the lower band of a keltner channel if the position is long.
    So the keltner channel lower band becomes my stop loss or stop profit as is the case. The idea is that the stop loss should follow the trend as it develops.
    I wrote this code,

    double longTrailStop = KeltnerChannel(1.5 , 10).Lower[1] ;

    SetStopLoss( "LongTrade", CalculationMode.Price, longTrailStop, false);

    but it is not working, and I do not understand why?
    When I activate the strategy on a chart, Ninjatrader automatically deactivate it!
    Please help!
    Thank you.
    Attached Files
    Last edited by CLDGLR; 11-14-2016, 05:30 AM.

    #2
    Hello CLDGLR,

    Thank you for your note.

    The reason your strategy is deactivating is due to the error “Object reference not set to an instance of an object”.

    The issue is you are setting the value of longTrailStop from within Initialize, at which point it will not have a value. You’d want to set the value of the variable longTrailStop within OnBarUpdate().

    To resolve the issue you could put within the buy condition,
    double longTrailStop = KeltnerChannel(1.5 , 10).Lower[1] ;
    SetStopLoss(‘LongTrade’, CalculationMode.Price, longTrailStop, false);

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    69 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    42 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    24 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    27 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    54 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X