Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Request for more accurate GetCurrentBid() & GetCurrentAsk() in Historical

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

    Request for more accurate GetCurrentBid() & GetCurrentAsk() in Historical

    As of RC2 (and possibly since NT1 for all I know) the documentation says
    When accessed during State.Historical, the Close price of the evaluated bar is substituted.
    And this means Close[0].

    Problem:
    When OnBarUpdate() is called in Realtime CurrentBar is pointing to the last closed bar. NT has received the first tick of the next bar (which I call bar-being-built). So the latest price (of the dataseries' MarketDataType) is in GetOpen(CurrentBar+1) but Close[0] might be days out of date (say if market has just opened after a weekend break).
    When in Historical the current substitution of the out-of-date Close[0] is causing all sorts of problems. These problems might only be noticed once per day after session break (since intra-day bars usually have no opening gap), so the problems are most noticeable if using a BarsPeriodType.Day datasouce.

    Suggested solution:
    a) Change the documentation to say something like
    When accessed during State.Historical, the Open price of the new bar is substituted.
    b) Change the implementation to use GetOpen(CurrentBar+1).


    Here's a quote from Ray (CEO) which backs up what I am saying
    Signals are generated on the close of a bar thus the next tick (which is the open of the next bar) is where the order is filled at. Limit and stop orders are "working" on the next bar and evaluated against this bars data to determine if it indeed has been filled and at what price.
    What Ray here calls "next bar" is what I am calling "bar-being-built".

    If this change is made it should probably be done in the same release as the suggested fix for the problematic 'historic stop order price check rule'. This is because user strategies often use GetCurrentBid() minus some ticks to assign a price for a stop order on a Long (for example), and both GetCurrentBid() and the Historical stop order rule are currently looking at the same (potentially days out-of-date price).

    Sidenote:
    Ideally GetCurrentAsk() in Historical should be using GetAsk(CurrentBar+1), and GetCurrentBid() in Historical should be using GetBid(CurrentBar+1), but since neither GetAsk() nor GetBid() currently work properly, that’s probably a step too far for now!

    #2
    DavE,

    GetCurrentAsk()/GetCurrentBid() implementations are generally the same between NinjaTrader 7 and NinjaTrader 8. What has changed is that with NinjaTrader 8 we have a slightly different 'state' system where a NinjaScript object would proceed into State.Realtime. Wanted to ask some follow up questions just to make sure your seeing behavior I would expect with NinjaTrader 8 and then I could process your request for improvement. I also wanted to make sure you were aware of 'Tick Replay' which could potentially be something of interest for you.

    1. You mention that when the NinjaScript proceeds to State.Realtime. Are you running code in OnStateChanged() { if(State == State.Realtime) } or is this the first OnBarUpdate after State.Realtime is achieved that your using GetCurrentAsk()?
    2. If it is OnBarUpdate then are you running calculate = OnEachTick or calculate =OnBarClose

    Comment


      #3
      As the thread title says
      Request for more accurate GetCurrentBid() & GetCurrentAsk() in Historical
      I am only requesting a change in the way these work in Historical.
      I am focusing on how things work using Calculate.OnBarClose.
      I only mentioned Realtime because I was contrasting how the time/price point used there (when calling GetCurrentBid etc in OnBarUpdate() ie the time/price at open of bar-being-built) is not currently replicated in Historical.
      The principle should be that Historical processing works as close as possible to Realtime.

      generally the same between NinjaTrader 7 and NinjaTrader 8.
      Its probably been like this since GetCurrentBid etc has been in NT. But my point is that in Historical, when using Calculate.OnBarClose, a better simulation of what would have happened (if we were actually running in Realtime) is to use GetOpen(CurrentBar+1) instead of the traditional Close[0].
      Last edited by DaveE; 11-01-2016, 12:06 PM.

      Comment


        #4
        The attached strategy illustrates the problem.

        Step1:
        I ran sTestGetCurrentAsk at 20:54:38 on USDJPY daily ask on IB paper trading account, days to load=5.
        Session break occurred between 21:00 and 21:15 when next OnBarUpdate() was triggered in Realtime.
        Soon afterwards disabled the strategy.
        Here is extract from the output:
        Realtime
        01/11/2016 20:59:30 CancelAllOrders: BarsInProgress=0
        Strategy 'sTestGetCurrentAsk/85748627' lost price connection but will keep running.
        BarsInProgress=0, CurrentBar=3, Time[0]=01/11/2016 21:00:00 (close of CurrentBar) actual time=01/11/2016 21:15:00
        There was an opening gap of -0.016. If Historical then GetCurrentAsk() will be giving out-of-date price
        The strategy has not printed a warning above because in Realtime GetCurrentAsk() is providing the correct value which is GetOpen(CurrentBar+1). Notice that the real time that OnBarUpdate() is being called is the end of the session break, when NT has received the open Ask for the bar-being-built.

        Step2:
        Ran at 21:28:18 the session break between 21:00 and 21:15 is now Historic.
        Using same parameters, extract from output, showing how the same session break is handled when it has become Historic.
        Historical
        ...
        BarsInProgress=0, CurrentBar=3, Time[0]=01/11/2016 21:00:00 (close of CurrentBar) actual time=01/11/2016 21:28:18
        There was an opening gap of -0.016. If Historical then GetCurrentAsk() will be giving out-of-date price
        **Warning: GetCurrentAsk() 104.156 is out of date (error=-0.016). It should be reporting GetOpen(CurrentBar+1) 104.14 instead
        Transition
        ...
        Realtime
        The problem is that GetCurrentAsk() in Historical is now incorrectly assuming that the correct price is before the session break (Close[0]), whereas in Realtime it was correcly using the price after the session break.
        Attached Files

        Comment


          #5
          DavE,

          GetCurrentAsk() and GetCurrentBid() in historical just returns the Close[0] which is just a default 'dummy' value. We don't do that to try to 'simulate' bid/ask its just a default value. Therefore I would advise not using it in historical at all and filtering that logic out with an if (State == State.Historical) then perform some other operation that is not reliant on bid/ask.

          You could switch over to using TickReplay which would give you all the ticks that build a bar and drive your logic based on that and have access to bid/ask data at the time of last. Documentation on that style of processing can be found here but its not without its implications: https://ninjatrader.com/support/help...ick_replay.htm

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by guillembm, Yesterday, 11:25 AM
          2 responses
          9 views
          0 likes
          Last Post guillembm  
          Started by junkone, 04-21-2024, 07:17 AM
          9 responses
          68 views
          0 likes
          Last Post jeronymite  
          Started by trilliantrader, 04-18-2024, 08:16 AM
          4 responses
          18 views
          0 likes
          Last Post trilliantrader  
          Started by mgco4you, Yesterday, 09:46 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by wzgy0920, Yesterday, 09:53 PM
          0 responses
          10 views
          0 likes
          Last Post wzgy0920  
          Working...
          X