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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 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
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X