• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetBid() and GetAsk() not working correctly RC2

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

    GetBid() and GetAsk() not working correctly RC2

    I assume that GetBid(CurrentBar) should get the Open Bid price for CurrentBar regardless of whether the dataseries has MarketDataType Last, Bid or Ask.
    But in RC2 all it does is give the same value as Open[0].
    Basically currently GetBid(index) may as well be calling GetOpen(index).

    Here's an example of a problem this causes:
    User is running strategy with MarketDataType.Ask, user assumes following documentation that GetBid(CurrentBar) will get the Bid price at open of the bar just closed. But in fact the user is getting the Ask price at open of the bar just closed (which will be higher than what they are expecting).
    In fact the documentation would make more sense if it used
    Code:
    EnterShortStopMarket(Bars.GetBid(CurrentBar+1));
    instead of current
    Code:
    EnterShortStopMarket(Bars.GetBid(CurrentBar));
    since that should be retrieving the latest open Bid price available at current OnBarUpdate() but currently just gets what I call OpenNew (which in this scenario is the latest Ask price, which will be higher than the user wants).

    I assume that GetAsk(CurrentBar) should get the Open Ask price for CurrentBar regardless of whether the dataseries has MarketDataType Last, Bid or Ask.
    But in RC2 all it does is give the same value as Open[0]+2*TickSize.
    Basically currently GetBid(index) may as well be calling GetOpen(index) + 2*TickSize.

    The use of an arbitrary number of 2 ticks to simulate a spread makes it look like the current implementation of GetAsk and GetBid is just some temporary code that a developer was supposed to go back to and finish, but forgot.

    This crude attempt to simulate a spread makes the current GetAsk() even worse than GetBid. For example:
    User is running strategy with MarketDataType.Ask, user wants to EnterLongLimit at the latest Ask price. User might expect that GetAsk(CurrentBar+1) should get this value (regardless of selected MarketDataType), but in fact here it gets the latest Ask + 2 ticks!
    If instead user was running strategy on MarketDataType.Bid then GetAsk(CurrentBar+1) would get the latest Bid price plus two ticks. Whereas the real latest relevant Ask price might have been any number of ticks above the latest Bid price.

    Test strategy is attached. The problem can easily be seen by running this strategy on a MarketDataType.Ask dataseries.
    Here is some sample output:
    DataLoaded: sTestGetAsk1() BarsArray.Count=1, Dataseries:
    BarsInProgress index=0. Instrument=USDJPY, MarketDataType=Ask, BarsPeriodType=Minute, Value=1, Timeframe: From=25/10/2016 00:00:00, To=26/10/2016 00:00:00, TradingHours=Forex, BreakAtEOD=True, Count=2175
    Setup: Account=****, Calculate=OnBarClose, MaximumBarsLookBack=TwoHundredFiftySix, BarsRequiredToTrade=0, StartBehavior=WaitUntilFlat (IsAdoptAccountPositionAware=False)
    Historical Fill Processing: Resolution=Standard, IsFillLimitOnTouch=False, Slippage=0
    Order Handling: (managed) EntriesPerDirection=1, EntryHandling=AllEntries, IsExitOnSessionCloseStrategy=False, StopTargetHandling=PerEntryExecution
    Order Properties: SetOrderQuantity=Strategy, TimeInForce=Gtc (TraceOrders=False)
    Historical
    * BarsInProgress=0, CurrentBar=0, Time=24/10/2016 22:01:00 (close of CurrentBar), bar-being-built will close at: 24/10/2016 22:16:00
    Close[0]=104.186, Open[0]=104.184, openNew=104.229, Bid(CurrentBar)=104.184, Bid(CurrentBar+1)=104.229, Ask(CurrentBar)=104.186, Ask(CurrentBar+1)=104.231
    Warning Open[0] differs from GetAsk(CurrentBar) even though using MarketDataType.Ask !
    Warning GetOpen(CurrentBar+1) differs from GetAsk(CurrentBar+1) even though using MarketDataType.Ask !

    * BarsInProgress=0, CurrentBar=1, Time=24/10/2016 22:16:00 (close of CurrentBar), bar-being-built will close at: 24/10/2016 22:17:00
    Close[0]=104.234, Open[0]=104.229, openNew=104.234, Bid(CurrentBar)=104.229, Bid(CurrentBar+1)=104.234, Ask(CurrentBar)=104.231, Ask(CurrentBar+1)=104.236
    Warning Open[0] differs from GetAsk(CurrentBar) even though using MarketDataType.Ask !
    Warning GetOpen(CurrentBar+1) differs from GetAsk(CurrentBar+1) even though using MarketDataType.Ask !
    Attached Files
    Last edited by DaveE; 10-26-2016, 06:30 AM.

    #2
    Hello DaveE,

    Thank you for your post.

    NinjaTrader does not add a Historical Bid or Ask series to the Last bar series. When you view Historical Data you need to understand there is no Bid or Ask on the Last bar series and if you need those Historical bars then you need to explicitly add and call those in your code.

    For example:
    In OnStateChange...
    Code:
    			else if (State == State.Configure)
    			{
    				AddDataSeries("EURUSD", BarsPeriodType.Minute, 15, MarketDataType.Ask);
    				AddDataSeries("EURUSD", BarsPeriodType.Minute, 15, MarketDataType.Bid);
    			}
    Please refer to the AddDataSeries page in the Help Guide: http://ninjatrader.com/support/helpG...dataseries.htm
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Just makes it more tough

      I wrote the same thing a few days ago about the issue, writing more code in what will be a final product is cumbersome hopefully you will make BID and ASK available in future releases as a simple thing like the last price, so we do not have to modify our codes and then un-modify our code every time we want to know what happens in a limit order.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by aslane, Today, 02:31 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by stoner, 10-16-2019, 01:38 PM
      5 responses
      51 views
      0 likes
      Last Post sledge
      by sledge
       
      Started by music_p13, Today, 12:04 PM
      1 response
      24 views
      0 likes
      Last Post NinjaTrader_Kate  
      Started by zaro33, Today, 10:55 AM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Heath  
      Started by itrader46, Today, 10:16 AM
      5 responses
      11 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X