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

testing strategy

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

    testing strategy

    Hello, I have a managed strategy that is currently not using the Advanced part and so is cancelled on bar close as per help section :

    By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted

    .....

    i currently set the strategy to run oneachtick
    .... corrected this section ...

    When a strategy is loaded all the history bars are marked with text and lines - however even if the strategy is running on each tick / on each price change
    all the history bars will be processed on bar close ?

    Within the strategy i have code to update the stop to break even after X ticks. This will not show on the history bars? ie i will not see the actual tick by tick history to know
    if the stop level was effective.

    If i run this through strategy analyser - having read the documentation it is not clear how the ticks for history bars in the range are processed.

    Can a strategy be run as if is live and each tick is processed in strategy analyser? I do not see any reference to this ?

    Does this need to be done in Replay ?

    Any clarification to the above would help

    thanks
    Last edited by explorer101; 11-12-2019, 11:16 AM.

    #2
    Hello explorer101,

    Thanks for your question.

    Yes, historical data processing will be calculated on bar closes and will not calculate using OnPriceChange or OnEachTick.

    If you would like to have the script process historical data with OnEachTick or OnPriceChange, the script can be enabled against a Tick Replay Data Series. Tick Replay can be enabled in the Tools > Options > Market Data menu of the Control Center, and then it can be enabled in the Strategy Analyzer or on a Chart within the Chart's Data Series window.

    Please note that Tick Replay allows for intrabar processing, but does not allow for intrabar order fill simulations. High Order Fill Resolution is not compatible with Tick Replay, so if you want to have orders filled intrabar when using a Tick Replay strategy, you will have to add a single tick data series and submit the orders to that data series. Our Intrabar granularity example can be used to demonstrate.

    Sample Intrabar Backtest - https://ninjatrader.com/support/help...ipt_strate.htm

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

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      thanks i just wanted to confirm ; ill take a look at the intrabar backtest sample

      Also running in replay mode would also have the effect of processing each tick ?

      when you say tick replay does NOT allow for intrabar order fill simulations - but allows for intrabar processing - do you mean any strategy logic will apply but it will not be able to handle
      an order being submitted intrabar and the logic i have to move the stop to break even which processes on each tick : this will not process either in tick replay mode? even in strategy analyzer?

      update to this .... in looking at the intrabarbacktest :

      // When the OnBarUpdate() is called from the secondary bar series, do nothing.
      else
      {
      return;
      }

      the section of code in there as above for processing the secondary 1 tick series.

      IF i run the strategy on each tick - can i

      submit the order based on the secondary series as in the example ie EnterLongLimit( )
      but it seems if i use EnterLongLimit to specify a limit price (which will be based on the Primary Bar Series)
      this takes me into advanced handling. As the overload for this to access barsinprogress also has the liveuntilcancelled parameter

      I am trying to set up a sample for someone without necessarily using the managed advanced which means handling the CancelOrder().
      If i need to in order to do this then fine :

      Update whilst awaiting reply

      So i added the 1 tick series - in the section barsinprogress == 0 (the primary bar) i am testing the condition for entry and sending to the 1 tick series with liveuntilcancelled set as false in EnterLongLimit

      in barsinprogress ==1 (the added 1 tick series) i am making updates and checks to the stop for the position for the strategy.

      Would you expect this to work and have the intrabar granularity in strategy analyser and in loading the chart since the strategy now has a 1 tick series to process the stops - all ticks for the 1 tick series are processed during the load of strategy on chart
      the setting is onbarclose - so waiting for close of primary to check and send order - and onbarclose of 1 tick series is every tick

      thanks
      Last edited by explorer101; 11-13-2019, 06:34 AM.

      Comment


        #4
        Hello explorer101,

        Running the strategy in Market Replay will mimic realtime data, so any point after you hit the Play button will follow realtime processing. Realtime order fill simulations are filled with Bid/Ask and scripts can calculate OnEachTick or OnPriceChange. Any data that exists prior to clicking the Play button will be processed as historical data. Historical order fill simulations will be filled using the OHLC points of the data series that the orders are submitted to.

        Tick Replay allows scripts to process historical data OnEachTick or OnPriceChange. The orders will still fill with prices estimated from the OHLC points of the data series you submit the orders to.

        Since the orders will fill depending on the added data series, you could come across a scenario where a limit order gets filled at price you do not expect, before the processing ticks reach this price.

        You could have the strategy call EnterLongLimit() with the the following overload, and you can set the IsLiveUntilCancelled parameter to false to have the order automatically cancel on the next bar that the method is not called.

        EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

        EX:

        EnterLongLimit(1, false, 5, 1000, "Long Limit Entry")

        Your strategy does not need to do any processing for the added data series, it is only needed for order submissions for the intrabar order fills. For example, you could add if (BarsInProgress != 0) return; to the top of your OnBarUpdate method and OnBarUpdate will then only process for BarsInProgress 0 (the primary data series.)

        However, your understanding is correct. You could consider creating a Multi Time Frame strategy which adds a single tick data series, and use that added data series for your logic instead of using Calculate.OnEachTick or OnPriceChange.

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

        Please let me know if there is anything else I can do to help.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hello JIm, thanks for the reply.

          In testing this prior to your reply i am seeing the flexibility here but also the nuances of adding the 1 tick series.

          What i have now is the strategy set to OnBarClose with the primary series and the 1 tick series

          I use EnterLongLimit(xxPrice); in the barsinprogress section - when the current bar closes and the condition for the order is true.

          then when / if filled the 1 tick series processes the stops etc and updates on each tick which is what i wanted.

          However if i use the overload with liveuntilcancelled = false and send to the barsinprogress = 1 ie the 1 tick series - what seems to be happening is the limit order is cancelled on the next tick as the order is associated with the 1 tick series ? that would be expected and thus not feasible in this scenario and so i likely would need to use liveuntilcancelled = true and handle the CancelOrder() - Is my understanding of this correct in this scenario

          i wanted to clarify also the added data series scenario for intrabar order fills - if i have say a 5 minute primary bar series for which i want to determine the signals. And then have the 1 tick series - is this used/needed for strategy analyzer to process the historical bars? So even if the strategy waits until the close to submit the order - if i use a limit price this does not matter so much in terms of the order being filled ? is it only market orders that need the 1 tick series - or is it a case that strategy analyser needs the 1 ticks series for market and limit in order to process the order on the close of the 5 minute bar - even if strategy is set to oneachtick for all bars including the 5minute primary - for backtesting and strategy analyzer it still needs the granularity of the 1 tick series ?

          Just trying to fully understand this - as in my example i test sending order to the 1 tick series EnterLongLimit(1,false, etc) seems to cancel the order on the next 1 tick series bar - perhaps this shouldnt happen and should be on the next primary series bar? I just did a test now before submitting this reply and it did just that.

          So my questions are geared at useable instances of this feature.

          My objective for having the stop and price update in the 1 tick series works which is great - which is more related to the multi time frame aspect you mention.

          So im trying to understand the intrabar order fills - this to me would make sense if the strategy was run oneachtick for the primary bar - and you needed the tick level information for strategy analyzer to be meaningful ? is this the case?

          thanks

          Comment


            #6
            Hello explorer101,

            However if i use the overload with liveuntilcancelled = false and send to the barsinprogress = 1 ie the 1 tick series - what seems to be happening is the limit order is cancelled on the next tick as the order is associated with the 1 tick series ? that would be expected and thus not feasible in this scenario and so i likely would need to use liveuntilcancelled = true and handle the CancelOrder() - Is my understanding of this correct in this scenario
            Yes, your understanding is correct. If an order method is called on the single tick data series (without specifying a different BarsInProgress index,) it will then be associated with that data series. If the order method (using IsLiveUntilCancelled = false) is not called again on the next tick, the order will be cancelled.

            i wanted to clarify also the added data series scenario for intrabar order fills - if i have say a 5 minute primary bar series for which i want to determine the signals. And then have the 1 tick series - is this used/needed for strategy analyzer to process the historical bars? So even if the strategy waits until the close to submit the order - if i use a limit price this does not matter so much in terms of the order being filled ? is it only market orders that need the 1 tick series - or is it a case that strategy analyser needs the 1 ticks series for market and limit in order to process the order on the close of the 5 minute bar - even if strategy is set to oneachtick for all bars including the 5minute primary - for backtesting and strategy analyzer it still needs the granularity of the 1 tick series ?
            Submitting the order to the single tick data series allows it to be filled intrabar. Consider the case of a limit order that gets submitted to the 5 minute data series. If the next bar covers price action to fill the order, it will use the OHLC points of that bar to create virtual bars to estimate a price where the order filled. If the limit order is submitted to a single tick data series, we will see the tick data fill the order as the tick data passes through it. Market orders will fill using the open of the next bar, so you will see bigger differences in fill prices of Stop and Limit orders than with Market orders.

            Just trying to fully understand this - as in my example i test sending order to the 1 tick series EnterLongLimit(1,false, etc) seems to cancel the order on the next 1 tick series bar - perhaps this shouldnt happen and should be on the next primary series bar? I just did a test now before submitting this reply and it did just that.
            Yes, similar to calling the order method on a different data series (without specifying a BarsInProgress index,) if you submit the order to a specific BarsInProgress index, the order will be associated with that data series. If we get another bar on that data series and the order is not called again, it will cancel.

            So im trying to understand the intrabar order fills - this to me would make sense if the strategy was run oneachtick for the primary bar - and you needed the tick level information for strategy analyzer to be meaningful ? is this the case?
            If the strategy is run OnEachTick/OnPriceChange historically using Tick Replay, orders can be submitted intrabar. To have them filled with intrabar data, they would need to be submitted to a single tick data series.

            To summarize, if you are updating your stop loss intrabar and submitting the order to a single tick data series, you will then need to use IsLiveUntilCancelled = true or ensure that the order method is called on subsequent ticks so the order does not cancel. You could use Calculate.OnEachTick/OnPriceChange without submitting to the single tick data series, but intrabar order submissions may not have a fill price that you would expect.

            Further information on historical fill processing is included below.

            Understanding Historical Fill Processing - https://ninjatrader.com/support/help...ical_fill_.htm

            Please let us know if there is anything else we can do to help.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by sidlercom80, 10-28-2023, 08:49 AM
            168 responses
            2,262 views
            0 likes
            Last Post sidlercom80  
            Started by Barry Milan, Yesterday, 10:35 PM
            3 responses
            10 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by WeyldFalcon, 12-10-2020, 06:48 PM
            14 responses
            1,429 views
            0 likes
            Last Post Handclap0241  
            Started by DJ888, 04-16-2024, 06:09 PM
            2 responses
            9 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            41 views
            0 likes
            Last Post jeronymite  
            Working...
            X