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

Bid/Ask During Backtest

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

  • reach4thelasers
    replied
    Made some changes to my Bid/Ask Historical Market Data Proxy.

    Note: The the OnMarketData events in ninjatrader don't fire at all during historical.

    therefore if you just need one Bid/Ask price per bar during historical. For OnBarClose Strategies, then call EnsureHistoricalBidAsk from OnBarUpdate.

    If you want Historical Bid/Ask for each tick. call EnsureHistoricalBidAsk(marketDataUpdate). This passes in the LAST price TickReplay event and will push out corresponding Bid/Ask prices during Historical.
    Attached Files
    Last edited by reach4thelasers; 06-19-2017, 11:52 AM.

    Leave a comment:


  • reach4thelasers
    replied
    Patrick,

    Appreciate the detailed response.

    I've attached a MarketDataProxy that I threw together in an hour that produces Historical Bid and Ask Updates. Just tell it the spread, and it takes the LAST price update generated via TickReplay and produces a corresponding Bid and Ask update.

    Why can't ninjatrader do this? Why do you all think that it is a better solution to provide nothing, and to completely break strategies that depend on BID & ASK data. Even if Ninjatrader just pushed out the Last price three times on the BID, ASK and LAST events it would be better than only triggering LAST. Things would keep working and we would be able to do backtests. I cannot understand why you are happy with the Status quo. The reason I wanted to discuss this with a PM is to let them know that the exact prices don't matter as long as the event triggers things would keep working, and its easy to simulate Bid and Ask prices. We are talking about a tiny price difference. But if you're placing Stop or Limit orders it is important that strategies consider the Bid and Ask.

    The decision of Ninjatrader's product development team to provide NOTHING for Bid and Ask events during back-tests is the wrong decision. It results in a totally unrealistic market simulation.

    But it seems like your playing gatekeeper today and I am not able to covey this.

    Anyway. Proof. historical Bid and Ask:


    Code:
    MarketDataProxy| State:Historical, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Historical, MarketDataType:Ask Price:140.317
    MarketDataProxy| State:Historical, MarketDataType:Bid Price:140.287
    MarketDataProxy| State:Historical, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Historical, MarketDataType:Ask Price:140.317
    MarketDataProxy| State:Historical, MarketDataType:Bid Price:140.287
    MarketDataProxy| State:Historical, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Historical, MarketDataType:Ask Price:140.317
    MarketDataProxy| State:Historical, MarketDataType:Bid Price:140.287
    MarketDataProxy| State:Historical, MarketDataType:Last Price:140.287
    Enabling NinjaScript strategy 'HistoricalMarketDataTestStrategy/108359003' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
    MarketDataProxy| State:Realtime, MarketDataType:Ask Price:140.299
    MarketDataProxy| State:Realtime, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Realtime, MarketDataType:Ask Price:140.3
    MarketDataProxy| State:Realtime, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Realtime, MarketDataType:Ask Price:140.299
    MarketDataProxy| State:Realtime, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Realtime, MarketDataType:Ask Price:140.3
    MarketDataProxy| State:Realtime, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Realtime, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Realtime, MarketDataType:Ask Price:140.299
    MarketDataProxy| State:Realtime, MarketDataType:Last Price:140.287
    MarketDataProxy| State:Realtime, MarketDataType:Ask Price:140.287
    Attached Files
    Last edited by reach4thelasers; 06-19-2017, 02:55 AM.

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    Hello reach4thelasers,

    Thank you for your response.

    I discussed your case with Product Management and they have advised me to respond as follows.

    There are 3 concepts to understand:
    • OnBarUpdate, which occurs based on 'bar' data. Bar data being considered 'historical data'.
    • OnMarketData, which occurs as a realtime L1 market data update comes into the platform. With NinjaTrader 7 this only would be called as realtime data comes in and would be called for all ask/bid and last updated.

    Now we introduce Tick Replay with NinjaTrader 8:
    • Indicators in NinjaTrader 7 that were coded to work in OnMarketData would not work in historical and only could work in live due to the nature of OnMarketData. At the time when we developed NinjaTrader 7 providers typically would not support bid/ask historical data either.
    • At the time of this writing very few historical data vendors still do not store bid/ask historical data or store it in severely limited fashion. However what is now stored on some providers (Kinetick, IQFeed, Continuum, Rithmic) is a bid/ask 'stamp' on a last event for 1 tick historical data. This is not true bid/ask recording of data but instead simply a stamp of the current bid and current ask at the time of a trade.
    • We wanted to expose that data, to do that we needed to simulate the strategy like it was running live (Tick Replay) and call OnMarketData and expose on the 'last' event the 'bid' and 'ask' stamp stored on that last event on the server.

    This is what we now support with tick replay. Tick replay has a lot of 'gotchas' and things that need to be understood, not all indicators/strategies that are written for OnMarketData will work in TickReplay only certain types will. Hence this is why we require separate logic for accessing bid/ask in OnMarketData as part of TickReplay. Since you need to code specifically for it.

    To drive the point home even further:
    1. An indicator which counts the number of bid events vs number of ask events in OnMarketData. This indicator would work live since you get 3 streams of independent data in OnMarketData. Ask/Bid and Last. This indicator WOULD NOT work in Tick Replay, since Tick Replay only throws last events with the recorded bid/ask at the time of last.
    2. Indicator which counts the last events but counts last events at the bid as sell and last events at the ask as sells. This would work in Tick Replay since we have last historical 1 tick data which has the bid/ask stamped data at the time last occurred.

    Now that we have the understanding out of the way. I would advise you caution with Tick Replay strategies. There are a number of gotchas we detail in our help guide in the Tick Replay section I believe you have been linked earlier. Tick Replay wasn't designed for better strategy simulation, simply was designed to expose additional bid/ask data stamped 1 tick data to indicators which would do the type of analysis above.

    Please let me know if you have any questions.

    Leave a comment:


  • reach4thelasers
    replied
    Sorry are you a project manager?

    Leave a comment:


  • NinjaTrader_PatrickH
    replied
    Hello reach4thelasers,

    Thank you for your response.

    The information provided previously is correct. If you wish to use Bid and Ask historically you would either add the additional Bid and Ask bar series or your would use Tick Replay. If you want to backtest without changing implementation of your strategy consider running the Playback Connection to playback the market as if it was realtime data.

    For information on Playback please visit the following link: http://ninjatrader.com/support/helpG...connection.htm

    Please let me know if you have any questions.

    Leave a comment:


  • reach4thelasers
    replied
    I can do a Playback while disconnected, using historical data and get Bid and Ask prices via Market Data. I can do a simulator connection and even get fake bid and ask prices via Market Data. Why is Strategy Analyser not consistent with the rest of the platform? I am on the verge of dumping Ninjatrader for good now. I believe that Ninjatrader is only good for the most simplistic one-file retailer strategies e.g. "If moving average cross above go long if cross below enter short" anything more complex that depends on multiple classes is useless.

    And any Technology Company where the recommended advice is "Have one implementation for LIVE and a completely different implementation for Testing" immediately causes Alarm bells for me.

    Kindly adhere to my earlier request and ask one of your Project Managers to intervene on this thread. I simply cannot believe the answers you are giving me; that the official Ninjatrader advice is to totally change the implementation in order to support the strategy analyzer; an implementation that works in every other part of Ninjatrader. It will take weeks; and I will need to maintain 2 versions which is high risk. Not to mention the fact that I won't actually be testing the same version of the strategy that is used in LIVE. It cannot be the official advice.

    I wasted weeks being your chief regression tester - someone's got to do it, huh? You guys clearly don't. And now I'm faced with a total rework of my system or I'm not able to backtests. Nah mate. I am done with this.
    Last edited by reach4thelasers; 06-16-2017, 06:33 AM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello reach4thelasers,

    The Strategy Analyzer uses a different data source than a real-time connection.

    This is why you can backtest even if you are disconnected because this is read from historical data file only.

    Historical data and real-time data are fundamentally different. The behavior is fundamentally different.

    If you need your script to process historically, then add the tick series and don't use OnMarketData. Start the script this way because its necessary if this is what you want.

    Its your choice how you code the script. However, if you want historical bid and ask prices, this is how its able to pull that information from historical data files.

    Leave a comment:


  • reach4thelasers
    replied
    I understand your recommendation about using bar updates on a secondary series to obtain bid and Ask data. Message received and understood. However this requires me to change my entire implementation and maintain two versions of a very complex strategy. It is not an acceptable solution. Bid and Ask data are supposed to be supplied by the MarketData event.

    And let's not get hung up on semantics. The internal working of a strategy Analyser session is basically a high speed historical Playback Connection. For all intents and purposes it's the same and should not have different behaviour. How on earth does a Simulator session provide fake bid and ask Data but a Market Analyser session provides nothing? It's a simple solution... Just make Bid Price equal to Last Price and add on a Tick for the Ask price and push it out on the MarketDataUpdate event. Better than providing nothing at all which is not realistic and breaks strategies and indicators that depend on these data.

    I would like one of your P.Ms to take over this thread please and explain the rational behind this.
    Last edited by reach4thelasers; 06-15-2017, 03:44 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello reach4thelasers,

    I'm trying to convey that you would no longer use OnMarketData() as by adding the 1 tick ask and bid series this would put that same information in OnBarUpdate() so that this can be used by the Strategy Analyzer historically.

    Lets say you want to know the current ask price halfway through the building of the primary bar. You would simply check the Close[0] when BarsInProgress is 1 any time while that bar is building and this will give you the current ask price.

    You will not be able to get the ask and bid historically from OnMarketData. You must add a 1 tick ask series and 1 tick bid series and get the updates for these from OnBarUpdate.

    The Strategy Analyzer is not a connection type.

    Leave a comment:


  • reach4thelasers
    replied
    Ok this is going nowhere. You've clearly not read my posts properly or understood my issue.

    I have a very complex strategy that utilises MarketData updates. I need the current market bid and ask in many many many different places in lots of interdependent classes. I don't need bar data I just occasionally need to know the current price. It's a trading platform and yet I can't get prices out of the damn thing.

    To summarise the state of the various connection types in this regard:
    • Live connection - provides Bid, Ask and Last Prices via market data updates
    • Historical Data Playback Connection - provides Bid, Ask and Last Prices via market data updates
    • MarketReplay Playback Connection - provides Bid, Ask and Last Prices via market data updates
    • Simulated Data Feed - provides Bid, Ask and Last Prices via market data updates
    • Strategy Analyser - DOES NOT provide Bid or Ask data via market data updates


    Why?? Why is this different from EVERY other connection type. And what can I do about it without changing my entire implementation just so I can do back tests?
    Last edited by reach4thelasers; 06-15-2017, 02:23 PM.

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello reach4thelasers,

    From your previous post, it sounds as if you are expecting OnMarketData to trigger. This will trigger. Instead OnBarUpdate() will trigger for each tick.

    May I confirm that you have added a print to OnBarUpdate to print the BarsInProgress and time and you are not getting prints for the ask tick data or bid tick data?

    Leave a comment:


  • reach4thelasers
    replied
    Did I not add 1 Tick Bid and ask series in that spike. I'm on my phone now so cant check

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello reach4thelasers,

    Adding a 1 tick ask series and 1 tick bid series will cause OnBarUpdate to trigger for the historical ask ticks and bid ticks.

    I highly recommend you review the thread where I have detailed intra-bar granularity that I linked in post #4.

    Leave a comment:


  • reach4thelasers
    replied
    Chelsea,

    I've made a spike which tries to get Bid/Ask data during a backtest (Strategy Analyzer).

    The attached strategy subscribes to MarketData updates the only two ways I know how...

    - MarketDataUpdate Event on the Instrument class
    - Update Event on the MarketData class

    Neither of these events Fire at all - There is no printed output from all three methods, and breakpoints are not triggered.

    I've downloaded 3 months work of HistoricalData with Bid, Ask, Last and Tick checked.
    Attached Files

    Leave a comment:


  • reach4thelasers
    replied
    Thanks Chelsea, I will try that over the weekend

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by wzgy0920, 04-20-2024, 06:09 PM
2 responses
26 views
0 likes
Last Post wzgy0920  
Started by wzgy0920, 02-22-2024, 01:11 AM
5 responses
32 views
0 likes
Last Post wzgy0920  
Started by wzgy0920, Yesterday, 09:53 PM
2 responses
49 views
0 likes
Last Post wzgy0920  
Started by Kensonprib, 04-28-2021, 10:11 AM
5 responses
192 views
0 likes
Last Post Hasadafa  
Started by GussJ, 03-04-2020, 03:11 PM
11 responses
3,234 views
0 likes
Last Post xiinteractive  
Working...
X