Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stoploss to breakeven problem

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

    Stoploss to breakeven problem

    Hi everyone.

    I have inserted in my strategy the following code, to set the stoploss to breakeven for a long and a short position:

    // Condition set 3
    if (Position.MarketPosition == MarketPosition.Long
    && GetCurrentBid() >= Position.AvgPrice + Breakeven_Long * TickSize)
    {
    SetStopLoss("", CalculationMode.Price, Position.AvgPrice + 2* TickSize, true);
    }

    // Condition set 4
    if (Position.MarketPosition == MarketPosition.Short
    && GetCurrentBid() <= Position.AvgPrice + Breakeven_Short * TickSize)
    {
    SetStopLoss("", CalculationMode.Price, Position.AvgPrice - 2* TickSize, true);
    }

    // Condition set 5
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, Stop_Loss);
    }
    Breakeven_Short and Breakeven_Long are user defined inputs.

    Breakeven_Short is a negative number, so I expect it to be subtracted to the position.avgprice.

    Now, when I run the strategy on historical data, nothing happens.
    What could be missing?

    thank you,

    John.

    #2
    Hello John,
    Thanks for writing in and I am happy to assist you.
    GetCurrentBid is a realtime property only. You cannot access it while backtesting/historical data.

    Also you have set the fromEntrySignal property in the SetStopLoss() to “”. Please make sure the entry name is aslo set to “”.

    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you, it's ok now!

      Comment


        #4
        Hello John,
        Glad you could resolve the issue.
        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        650 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        577 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X