Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Insidebar probs

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

    Insidebar probs

    I have a stop modification going one bar back when inside bars ( the grey rectangle in the pic) are in play. The stops (black line) works until a certain point when it jumps from 11446 to 11488. It should stay at 11446 until the close is higher than the inside bar range (11500), and then go up to 11496.

    I think the problem is in the structure of my code. But as it is my first strategy, I don't know where to start...

    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
    if (Position.MarketPosition == MarketPosition.Long)
    {
    // Set stop values for new higher bar
    if (Open[0] > StopBarHigh || Close[0] > StopBarHigh) // higher bar
    StopBarLowOld = StopBarLow;
    StopBarLow = Low[0];
    StopBarHighOld = StopBarHigh;
    StopBarHigh = High[0];

    // Once the low is greater than entry price set new stop loss below the low
    if (Low[0] > Position.AvgPrice)
    {
    SetStopLoss(CalculationMode.Price, StopBarLow - 2 * TickSize);
    }

    // Set values for stop bar if new bar = inside bar
    if (Open[0] > StopBarLow && Open[0] < StopBarHigh && Close[0] > StopBarLow && Close[0] < StopBarHigh) // inside bar
    {
    // Once the low is greater than entry price set new stop loss below low
    if (Low[0] > Position.AvgPrice)
    {
    SetStopLoss(CalculationMode.Price, StopBarLowOld - 2 * TickSize);
    }
    }
    }
    Attached Files

    #2
    You will want to debug your strategy step by step as per this tip: http://www.ninjatrader-support.com/v...ead.php?t=3418

    Print out values of your rectangle box to see how it moves on every bar and also print out your stop value. Then you will know why it is jumping at that point.
    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
    559 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    546 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X