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

Entries at open of bar

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

    Entries at open of bar

    My strategy works as expected on intrabar entries and exits, but only when i have a single entry. As soon as i add more, entries occur on the open of the bar that triggered the entry, but should have been later in that bar.

    Code for broken entries:
    Code:
        private void ExecuteLongEntry(BarType previousBarType, BarType currentBarType)
        {
            if (longLastEntryBar != CurrentBar) {
                        // Enter a position with a size of 4
                SetProfitTarget("my1stentry", CalculationMode.Ticks, 80);
                SetProfitTarget("my2ndentry", CalculationMode.Ticks, 100);
                SetProfitTarget("my3rdentry", CalculationMode.Ticks, 120);
                SetProfitTarget("my4thentry", CalculationMode.Ticks, 140);
                EnterLong( 1, "my1stentry");
                EnterLong( 1, "my2ndentry");
                EnterLong( 1, "my3rdentry");
                EnterLong( 1, "my4thentry");
    
                longEntryCount++;
                longLastEntryBar = CurrentBar;
                longEntryBarHigh = High[1];
                longEntryBarLow = Low[1];
                formingBarLow = High[0];
            }
        }​
    Example of unwanted entries in backtest: Click image for larger version  Name:	image.png Views:	0 Size:	108.7 KB ID:	1291789
    Code that works with single entry:
    Code:
        private void ExecuteShortEntry(BarType previousBarType, BarType currentBarType)
        {
            if (shortLastEntryBar != CurrentBar) {
                EnterShort(1, Convert.ToInt32(4), "Short");
                SetProfitTarget(CalculationMode.Ticks, 75);
                shortEntryCount++;
                shortLastEntryBar = CurrentBar;
                shortEntryBarHigh = High[1];
                shortEntryBarLow = Low[1];
                formingBarHigh = High[0];
            }
        }​
    Output in strategy analyzer:
    Click image for larger version  Name:	image.png Views:	0 Size:	54.7 KB ID:	1291790

    I'm using tick replay, and the only difference is the number of orders
    Last edited by spencerduran; 02-16-2024, 04:40 PM.

    #2
    Hello spencerduran,

    Thank you for your post.

    Please clarify what you mean by "As soon as i add more, entries occur on the open of the bar that triggered the entry, but should have been later in that bar."
    Do you mean that entries are being shown at the Open price of the bar rather than an intrabar price? This would be expected in a backtest because of the historical fill algorithm. Fill prices are determined based on the OHLC prices of the bar. Tick replay would allow for intrabar actions to occur, but it does not introduce more granular, intrabar prices for the order fill algorithm. What are the results if you disable tick replay and instead use the High Order Fill Resolution with a 1 tick data series? This would intoduce more granular data, with 1-tick being the most granular option available. Then the order fill prices should represent the intrabar price values where the orders were filled at. For more information on discrepancies between real-time and backtest, the historical order fill algorithm, and intrabar granularity, please see the following links:




    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      Ah, what i meant by that was "As soon as i edit the strategy to include additional separate orders and re-run the strategy analyzer"
      The goal is to be able to set different profit targets for each of the four entries

      if you notice in the second screenshot in the original post, those are the correct entry points.

      If i disable tick replay and use high resolution with 1 tick additional data, all entries are shown at the open of the bar following what should have been the entry bar. (pictured)
      Click image for larger version  Name:	image.png Views:	0 Size:	64.6 KB ID:	1291793
      Last edited by spencerduran; 02-16-2024, 05:19 PM.

      Comment


        #4
        Incorrect entry point (open of trigger bar):
        Click image for larger version

Name:	image.png
Views:	36
Size:	17.7 KB
ID:	1291795
        Correct entry point:
        Click image for larger version

Name:	image.png
Views:	29
Size:	7.5 KB
ID:	1291796

        High resolution with additional 1 tick data series:
        Click image for larger version

Name:	image.png
Views:	27
Size:	16.3 KB
ID:	1291797​​

        Comment


          #5
          Hello spencerduran,

          Thank you for your reply.

          With Tick Replay disabled, it is expected that the strategy will run its logic "On Bar Close" rather than On Price Change or On Each Tick. That is why, with Tick Replay disabled, you see the entries on the bar after the entry condition is triggered. What you will need to do to get your entry logic to process intrabar as well as have more granular price data for the profit targets to be filled at their separate prices is enable Tick Replay and also program your strategy to add a 1-tick data series and submit orders to that added series. We have a reference sample of backtesting with intrabar granularity (which is essentially what the High Order Fill Resolution is doing) here:


          The reason this is necessary is that Tick Replay can not be used with High Order Fill Resolution at the same time, so you must program the more granular data resolution into your strategy's logic itself.

          Please let us know if we may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by geddyisodin, 04-25-2024, 05:20 AM
          8 responses
          60 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by jxs_xrj, 01-12-2020, 09:49 AM
          4 responses
          3,287 views
          1 like
          Last Post jgualdronc  
          Started by Option Whisperer, Today, 09:55 AM
          0 responses
          5 views
          0 likes
          Last Post Option Whisperer  
          Started by halgo_boulder, 04-20-2024, 08:44 AM
          2 responses
          22 views
          0 likes
          Last Post halgo_boulder  
          Started by mishhh, 05-25-2010, 08:54 AM
          19 responses
          6,189 views
          0 likes
          Last Post rene69851  
          Working...
          X