• 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 dltharpe, Today, 09:17 AM
    0 responses
    6 views
    0 likes
    Last Post dltharpe  
    Started by HiddenPhilosopher, Today, 06:45 AM
    0 responses
    6 views
    0 likes
    Last Post HiddenPhilosopher  
    Started by PG7940, Today, 04:26 AM
    0 responses
    10 views
    0 likes
    Last Post PG7940
    by PG7940
     
    Started by marcus2300, Today, 02:25 AM
    0 responses
    2 views
    0 likes
    Last Post marcus2300  
    Started by drpapp, 01-24-2019, 06:57 AM
    5 responses
    69 views
    0 likes
    Last Post pjsmith
    by pjsmith
     
    Working...
    X