Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry price with EOD data

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

    Entry price with EOD data

    Hello all!

    Recently, I started looking into NinjaTrader, and it looks promising!
    Currently, I use EOD data from Yahoo.

    However, after coding a few simple indicators and strategies, I have stumbled upon a problem. Here is what I want to achieve:
    • When my indicator gives a signal, I want the strategy to enter a long position on the close price of that same day


    ..but what I see (when I call EnterLong()) is that the strategy doesn't enter a postition until the next day.

    Searching this forum, that seems to be the default behavior (and it makes sense in some cases). But the way that I trade is I check my indicators half an hour or so before the market closes, and then I enter my actual postitions at "near-close" prices.

    So the question is: Is there some way to convince the Strategy Analyzer to enter the positions the same day it gets its signals? Could the IOrder/IExecution interfaces be of any help?

    Any help is much appreciated!

    Cheers,
    Andy

    #2
    Hello sphinxxx,

    Welcome to the NinjaTrader Forums!

    When running a backtest via Strategy Analyzer, “CalculateOnBarClose”(COBC) is always set to true. Therefore, you order will be submitted at the start of the next bar. See the following link for more information about COBC.

    http://www.ninjatrader.com/support/h...onbarclose.htm


    It is possible to add intraday granularity to the strategy. See the following post.
    http://www.ninjatrader.com/support/f...ead.php?t=6652

    Using an EOD day provider you will not be able to get any intraday data. You would have to connect or download intraday data to run your backtests with intraday data. For a list of data providers and what they support you may see the link below.
    http://www.ninjatrader.com/support/h...rical_data.htm


    Please let me know if I can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Ok, thank you!

      I'm going to stick with just EOD data for a while. Is there a way to change the entry price of a position, once entered, thus simulating an entry at the close price the day before?

      Andy

      Comment


        #4
        Hello sphinxx,

        You can use Close[1] to get the price of the close of the previous bar but depending on the market you may not get filled.

        With that said, there are a few different “Fill Types” you can select to try to get different order entry fill results. You may want to use the "Liberal" fill type. See the link below for more information on “Historical Fill Processing”
        http://www.ninjatrader.com/support/h...a_strategy.htm


        Please note that there can “Discrepancies in: Real-Time vs. Backtest”, you may read more about it at the following link.
        http://www.ninjatrader.com/support/h...ime_vs_bac.htm

        Please let me know if I can be of further assistance.
        JCNinjaTrader Customer Service

        Comment


          #5
          Excellent, thanks again!

          The section on "Historical Fill Processing" led me to this article which explains how to make your own fill algorithm:
          http://www.ninjatrader.com/support/h...fill_types.htm

          By setting FillType.FillPrice to the current day's close price I now get the behavior i want. Here is some code if anyone else has the same problem:

          [Gui.Design.DisplayName("EnterOnClose")]
          public class EnterOnCloseFillType : DefaultFillType
          {
          public override void Fill(Order order)
          {
          var type = order.OrderType;
          var action = order.OrderAction;
          bool handled = false;

          if (type == OrderType.Market)
          {
          this.FillPrice = this.Strategy.Close[0];
          handled = true;

          //Doesn't update the Strategy Analyzer chart display..
          //order.Time = order.Time.AddDays(-1);

          }
          //Because we actually entered our position one day early,
          //targets and stops need to be adjusted for gaps on the next day:
          else if ((action == OrderAction.Sell) || (action == OrderAction.BuyToCover))
          {
          var orderPrice = (type == OrderType.Stop) ? order.StopPrice : order.LimitPrice;
          var open = this.NextOpen;

          //A gap down will give a better result when reaching the target of a short position:
          bool willUseLowerOpen = ((action == OrderAction.BuyToCover) && (type == OrderType.Limit));
          //A gap up will give a better result when reaching the target of a long position:
          bool willUseHigherOpen = ((action == OrderAction.Sell) && (type == OrderType.Limit));

          if ((willUseHigherOpen && (open > orderPrice)) ||
          (willUseLowerOpen && (open < orderPrice)))
          {
          this.FillPrice = open;
          handled = true;
          }
          }

          if (!handled)
          {
          base.Fill(order);
          }
          }

          }

          NOTE: The entry dates in Strategy Analyzer don't change, indicating that the entries only take place the next day, but the entry price and profit/loss calculations are correct (even if the stock doesn't actually reach the entry price the next day).

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, Yesterday, 10:06 AM
          0 responses
          17 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          16 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          14 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          9 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          36 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X