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

    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 Philippe56140, Today, 02:35 PM
      0 responses
      1 view
      0 likes
      Last Post Philippe56140  
      Started by 00nevest, Today, 02:27 PM
      0 responses
      1 view
      0 likes
      Last Post 00nevest  
      Started by Jonafare, 12-06-2012, 03:48 PM
      5 responses
      3,986 views
      0 likes
      Last Post rene69851  
      Started by Fitspressorest, Today, 01:38 PM
      0 responses
      2 views
      0 likes
      Last Post Fitspressorest  
      Started by Jonker, Today, 01:19 PM
      0 responses
      2 views
      0 likes
      Last Post Jonker
      by Jonker
       
      Working...
      X