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 sjsj2732, Yesterday, 04:31 AM
    0 responses
    39 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    289 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    289 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    135 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    96 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X