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 timmbbo, Today, 08:59 AM
    1 response
    2 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by KennyK, 05-29-2017, 02:02 AM
    2 responses
    1,281 views
    0 likes
    Last Post marcus2300  
    Started by fernandobr, Today, 09:11 AM
    0 responses
    3 views
    0 likes
    Last Post fernandobr  
    Started by itrader46, Today, 09:04 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by bmartz, 03-12-2024, 06:12 AM
    5 responses
    33 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Working...
    X