• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with SetStopLoss

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

    Issue with SetStopLoss

    Hello,
    I've an automated strategy and as a part of it if the price moves 6 ticks in the favor of trade, initial stoploss is brought to breakeven.

    But if you were to look at the chart below, for the two short trades via the strategy today, it did not bring the stoploss back to breakeven and instead exited the position at the initial stoploss of 8 ticks.

    Here is the code I am using and I have it placed under OnBarUpdate. Can someone please help to understand what could be wrong here?
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    }
    else if (Position.MarketPosition == MarketPosition.Long)
    {
    // Once the price is greater than entry price +6 ticks, set stop loss to breakeven
    if (Close[0] > Position.AvgPrice + 6 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    }
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    // Once the price is greater than entry price - 6 ticks, set stop loss to breakeven
    if (Close[0] < Position.AvgPrice - 6 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    }
    Attached Files

    #2
    Hello pandyav,

    Looking at your screenshot the reason why the stop loss was probably not moved was because the Close price was not less than 6 ticks, but it was equal 6 ticks below your entry price. The way that it is programmed now it will only move the Stop Loss if the close was more than 7 ticks or greater. So in the picture the Close would have to be 1788 or lower before your Stop Loss is triggered. If you want it to be moved if the close was 6 ticks or greater you may want to use the "<=" or ">=" signs so that if they are equal it will move it as well.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ronaldgreene828, Today, 11:20 AM
    0 responses
    1 view
    0 likes
    Last Post ronaldgreene828  
    Started by iq200, Today, 09:57 AM
    1 response
    18 views
    0 likes
    Last Post NinjaTrader_ChristopherD  
    Started by _Zero_, Today, 09:19 AM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by GLFX005, Today, 09:05 AM
    3 responses
    24 views
    0 likes
    Last Post NinjaTrader_RyanS  
    Started by meandthetrio, Today, 09:03 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Working...
    X