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 f.saeidi, Yesterday, 12:14 PM
    9 responses
    23 views
    0 likes
    Last Post f.saeidi  
    Started by Tim-c, Today, 03:54 AM
    0 responses
    3 views
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Started by FrancisMorro, Today, 03:24 AM
    0 responses
    3 views
    0 likes
    Last Post FrancisMorro  
    Started by Segwin, 05-07-2018, 02:15 PM
    10 responses
    1,772 views
    0 likes
    Last Post Leafcutter  
    Started by Rapine Heihei, 04-23-2024, 07:51 PM
    2 responses
    31 views
    0 likes
    Last Post Max238
    by Max238
     
    Working...
    X