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

Backtests and Optimization on Tick by Tick

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

    Backtests and Optimization on Tick by Tick

    Hi,


    I try to do tick by tick backtests over a long period. For this, I created a symbol, imported ticks (Ask, Bid, Last), I also imported minute bars.

    when i launch a backtest on a 1 minute chart, i see that only Open,Close, High, Low values are used. It's ok with tick replay, but not with backtests on a long period.

    I also added dataseries on ticks in the strategy as secondary data, same result.

    The only way to perform is to use Tick primary data series, so tick charts.

    Is there another way ? I'd like tu use 1mn chart, like in automated live trading. Difficult to verify my strategy on tick chart.

    Thanks for your anwers.

    #2
    Welcome to the forums fredericlebre!

    In my opinion, the quickest way to create a strategy that backtests with each tick is to design a strategy that operates on a single tick data series. You can add additional data series to the script and reference those added data series, and you can have that additional data drive indicators as well. This can all be done with the Strategy Builder, but limits you to enabling the strategy on a single tick data series.

    You could also consider adding a single tick data series as the secondary series and to use that to drive your logic, and to make sure that orders are submitted to the single tick data series so the orders are filled with intrabar granularity. If you want to consider an approach that does not require Calculate.OnEachTick, or Calculate.OnPriceChange, I recommend this approach.

    Multi time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

    Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

    Tick Replay allows for historical OnEachTick and OnPriceChange updates with OnBarUpdate and also for historical OnMarketData events for Last ticks, but does not affect how orders fill. You can add your single tick data series to the script and have the orders submitted to the single tick data series to have them filled with intrabar granularity, however. I would recommend this approach if you do want to use Calculate.OnEachTick or OnPriceChange.

    Using Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

    Developing for Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Welcome to the forums fredericlebre!

      In my opinion, the quickest way to create a strategy that backtests with each tick is to design a strategy that operates on a single tick data series. You can add additional data series to the script and reference those added data series, and you can have that additional data drive indicators as well. This can all be done with the Strategy Builder, but limits you to enabling the strategy on a single tick data series.

      You could also consider adding a single tick data series as the secondary series and to use that to drive your logic, and to make sure that orders are submitted to the single tick data series so the orders are filled with intrabar granularity. If you want to consider an approach that does not require Calculate.OnEachTick, or Calculate.OnPriceChange, I recommend this approach.

      Multi time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

      Backtesting with intrabar granularity - https://ninjatrader.com/support/help...ipt_strate.htm

      Tick Replay allows for historical OnEachTick and OnPriceChange updates with OnBarUpdate and also for historical OnMarketData events for Last ticks, but does not affect how orders fill. You can add your single tick data series to the script and have the orders submitted to the single tick data series to have them filled with intrabar granularity, however. I would recommend this approach if you do want to use Calculate.OnEachTick or OnPriceChange.

      Using Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

      Developing for Tick Replay - https://ninjatrader.com/support/help...ick_replay.htm

      We look forward to assisting.


      thanks for your answer.

      So, you confirm that if i realy want real tick by tick backtest i'll have to put the strategy on a Tick chart ?
      i tried to add tick data series as secondary serie, using 1mn primary dataserie on a 1mn chart and it does not work.

      Comment


        #4
        very sorry for my poor english

        Comment


          #5
          Hello fredericlebre,

          Thanks for your reply.

          So, you confirm that if i realy want real tick by tick backtest i'll have to put the strategy on a Tick chart ?
          i tried to add tick data series as secondary serie, using 1mn primary dataserie on a 1mn chart and it does not work.
          No, I am providing three different avenues where you can process on each tick. Please see my demonstration below for adding a single tick data series and observing the prints from the single tick data series. The Multi Time Frame and Instruments documentation is an important read for working with multi time frame scripts, so please be sure to follow that guide for a complete understanding on this topic.

          Demo - https://drive.google.com/file/d/1IFy...w?usp=drivesdk

          Code used:

          Code:
          protected override void OnStateChange()
          {
              if (State == State.SetDefaults)
              {
                  Description                                    = @"Enter the description for your new custom Strategy here.";
                  Name                                        = "MyCustomStrategy3";
                  Calculate                                    = Calculate.OnBarClose;
              }
              else if (State == State.Configure)
              {
                  AddDataSeries(Data.BarsPeriodType.Tick, 1); // BarsInProgress 1
              }
          }
          
          protected override void OnBarUpdate()
          {
              if (BarsInProgress == 1)
              {
                  Print(String.Format("Bar index for single tick data series: {0} Time[0]: {1} Close[0]: {2}", CurrentBar, Time[0], Close[0]));
              }
          }
          We look forward to assisting.
          JimNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by GussJ, 03-04-2020, 03:11 PM
          11 responses
          3,228 views
          0 likes
          Last Post xiinteractive  
          Started by andrewtrades, Today, 04:57 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by chbruno, Today, 04:10 PM
          0 responses
          7 views
          0 likes
          Last Post chbruno
          by chbruno
           
          Started by josh18955, 03-25-2023, 11:16 AM
          6 responses
          440 views
          0 likes
          Last Post Delerium  
          Started by FAQtrader, Today, 03:35 PM
          0 responses
          12 views
          0 likes
          Last Post FAQtrader  
          Working...
          X