Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Script trades at an impossible price

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

    Script trades at an impossible price

    Hi Guys,

    After many hours of scratching my head, I can't figure out why I'm seeing these trades occur at the prices they do. Check out the trades at 5am on the 16th and 4am on the 20th. Both have been set to enter long at limit 1 tick above the previous day's high. As you can see, they are entering at this price even though the actual price never reached these levels. It happens in many other places too. The code is below. Any ideas?

    private int quant = 10000;
    private double insidelow = 0;
    private double trailstop = 0;
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    Add(DBollinger(2, 20));
    CalculateOnBarClose = false;
    ExitOnClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (Position.MarketPosition == MarketPosition.Flat)
    {

    if (Low[1] <= Bollinger(2, 20).Lower[1] + 1 * TickSize)
    {
    if (High[0] < High[1] && Low[0] > Low[1])
    {
    EnterLongLimit(quant, High[0] + 1 * TickSize, "GoLong");
    insidelow = Low[0];
    trailstop = 0;
    ExitLongStop(insidelow - 3 * TickSize,"InitialStop", "GoLong");
    }
    }
    }

    if (Position.MarketPosition == MarketPosition.Long)
    {
    if (Close[0] > SMA(20)[0])
    {
    if (trailstop < SMA(20)[0])
    {
    trailstop = SMA(20)[0];
    }
    ExitLongStop(trailstop - 3 * TickSize,"TrailStop", "GoLong");
    }
    ExitLongStop(insidelow - 3 * TickSize,"InitialStop", "GoLong");
    }
    }
    Attached Files

    #2
    When you are running historically, it is possible to be filled outside of the bar. If this were a live trade, you would be the one moving the bar, but since it isn't, you see it filled outside the bar. You can try messing with the different fill types in a backtest.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick reply Josh. I'm always impressed by the responsive support you guys give.

      I played around with the fill types but wasn't quite happy so I took a look at the fill scripts, with the intent of making one that does what I was expecting.

      After taking a look at these, I realised I should have been using a stop order for my entry rather than a limit order. Doh.....

      Thanks,
      Ben.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X