Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

stop loss

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

    stop loss

    hi

    i dont know if im crazy or just not able to think logic.

    my strategy is perfectly handling my long stops but not my short stops and i have no idea why. if someone could help me pls

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Resets the stop loss to the original value when all positions are closed
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    }

    // If a long position is open, allow for stop loss modification to breakeven
    else if (Position.MarketPosition == MarketPosition.Long)
    {
    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (High[0] > Position.AvgPrice + breakeventicks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 3);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (High[0] > Position.AvgPrice + plusstop1ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + 2);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (High[0] > Position.AvgPrice + plusstop2ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + 5);
    }

    }

    // If a short position is open, allow for stop loss modification to breakeven
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (Low[0] < Position.AvgPrice - breakeventicks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice + 3);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (Low[0] < Position.AvgPrice - plusstop1ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 2);
    }

    // Once the price is greater than entry price+10 ticks, set stop loss to breakeven
    if (Low[0] < Position.AvgPrice - plusstop2ticks * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice - 5);
    }

    }

    #2
    Raggamuffin,

    Please be more specific as to what you want it to do and what it actual does. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      in the variables i have this:

      private int breakeventicks =7;
      private int plusstop1ticks =12;
      .
      .
      .

      lets say i run this strategy 3 times

      1 has a profit target of 20 ticks
      1 has a profit target of 30 ticks and the third target is 50 ticks

      and it does that:




      you see the stop loss in the first pic is perfect and in pic 2 the stop loss is negative but it should be like in pic 1 in positive terrain and i dont understand why.

      Comment


        #4
        You should add Print() along each step where you think you are amending your stops. Then you will know if an amend every was submitted. If no amend was submitted you then need to debug out your if-statements by printing those values so you can evaluate by hand.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        57 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        143 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        161 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        97 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        276 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X