Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 GussJ, 03-04-2020, 03:11 PM
      12 responses
      3,239 views
      0 likes
      Last Post Leafcutter  
      Started by AveryFlynn, Today, 04:57 AM
      0 responses
      5 views
      0 likes
      Last Post AveryFlynn  
      Started by RubenCazorla, 08-30-2022, 06:36 AM
      3 responses
      79 views
      0 likes
      Last Post PaulMohn  
      Started by f.saeidi, Yesterday, 12:14 PM
      9 responses
      25 views
      0 likes
      Last Post f.saeidi  
      Started by Tim-c, Today, 03:54 AM
      0 responses
      5 views
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Working...
      X