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

Calculate VolumeBid, VolumeAsk on historical data, when level 2 is available

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

    Calculate VolumeBid, VolumeAsk on historical data, when level 2 is available

    Hello,
    I am developing indicator to calculate volume on Bid and volume on Ask (on candle).
    I need work with also historical data.

    Below is script that works on realtime data. Is there a way to solve this on historical data? Especially OnMarketData part? I thought I saw somewhere about adding another DataSeries based on ask bid? Is there an example?

    Thanks a lot

    Code:

    On realtime data, this approach works for me:

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate() {

    if(Open[0] > Close[0])
    Values[2].Set(Volume[0]);
    else if(Open[0] < Close[0])
    Values[3].Set(Volume[0]);
    else
    Values[4].Set(Volume[0]);

    if (CurrentBar < activeBar)
    {
    return;
    }
    else if (CurrentBar != activeBar)
    {
    Print(Time[0] + " buys: " + buys + " sells: " + sells + " Close[0]: " + Close[0]);

    // Sells
    Values[0].Set(sells);

    // Buys
    Values[1].Set(buys);

    buys = 0;
    sells = 0;
    activeBar = CurrentBar;

    UpdateHistogram();
    }

    if (!Historical) {

    // Sells
    Values[0].Set(sells);

    // Buys
    Values[1].Set(buys);
    }

    }

    AND:

    /// <summary>
    /// Called on each incoming real time market data event
    /// </summary>
    protected override void OnMarketData(MarketDataEventArgs e)
    {
    if (e.MarketDataType == MarketDataType.Ask)
    askPrice = e.Price;
    else if (e.MarketDataType == MarketDataType.Bid)
    bidPrice = e.Price;
    else if (e.MarketDataType == MarketDataType.Last)
    {
    if (askPrice > 0 && e.Price >= askPrice)
    buys += e.Volume;
    else if (bidPrice > 0 && e.Price <= bidPrice)
    sells += e.Volume;
    }
    }

    #2
    Hello kujista,

    Thanks for your post.

    You can add bid/ask data but please note that historically it will not call the OnMarketData().

    Here is a link to the help guide on Add(): https://ninjatrader.com/support/help.../nt7/?add3.htm

    In NinjaTrader7 you may not be able to accomplish your goal. (Can be done in NT8 with tick replay).

    We will leave this open for any community response.

    We'll look into this further and update this thread when we have further information.



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello kujista,

      After further review we have these comments:

      We do not have any means to do OnMarketData() historically.

      When adding bid/ask data series, the exact sequence of a mix of bid/ask/last events will not be maintained while processing the historical data from multiple series.
      Reference: https://ninjatrader.com/support/help..._ask_serie.htm

      An approach you could take would be to create a system to record the data you need, in a format you need and create your own historical OnMarketData() to process the historical market data events. We would not have any examples of that.
      Paul H.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,404 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      95 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      8 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      159 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X