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

VOL Indicator and Volumes dataseries have different data for Bid and Ask

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

    VOL Indicator and Volumes dataseries have different data for Bid and Ask

    I am in my wits end in trying to figure out why my indicator is not showing accurate Bid Ask Volumes.

    I am comparing the data from the indicator coming out from the VOL indicator and my indicator and it seems that my indicator will occasionally come out with false bid/ask volume. If we hit F5, we will get back the accurate volume according to the VOL indicator.

    My initialize code:


    Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value,MarketDataType.Bid);
    Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value,MarketDataType.Ask);

    These are the codes I have tried:
    Values[1].Set(Volumes[1][0]);
    Values[0].Set(Volumes[2][0]);
    Values[1].Set(VOL(BarsArray[1])[0]);
    Values[0].Set(VOL(BarsArray[2])[0]);
    PlotBid.Set(GetCurrentBidVolume());
    PlotAsk.Set(GetCurrentAskVolume());


    GetCurrentAskVolume and GetCurrentBidVolume seems to throw some bogus value that does not fit the VOL data plotted on the Ask Prices. Would this be a Time and Sales data instead?
    As you can see from the screenshot, both VOL and Volumes throw the same figure and do not correspond to the VOL indicator, however, the non-refreshed data are all correct. I'm using Zenfire btw.
    Attached Files

    #2
    Hello,

    Can you please clarify where you are using the Plot code?

    Are you checking for the correct BarsInProgress event for the added data series? If you're not familiar with that, please review the information on the following link:



    If this does not help, can you please provide me with more of the code you are using in OnBarUpdate?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Heres my code. I'm using OnBarUpdate to set values for all the plots. The rest of the stuff is just drawing triangles etc which does not affect the main dataseries code...

      #region Variables
      private int maperiod = 3;
      private bool filterabovema = true;
      private int whichbar = 0;
      #endregion

      protected override void Initialize()
      {
      Add(new Plot(Color.FromKnownColor(KnownColor.PaleGreen), PlotStyle.Dot, "PlotAsk"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Pink), PlotStyle.Dot, "PlotBid"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "MAAsk"));
      Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "MABid"));
      Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value,MarketDataType.Bid);
      Add(Instrument.FullName, BarsPeriod.Id, BarsPeriod.Value,MarketDataType.Ask);

      CalculateOnBarClose = false;
      //Overlay = true;
      PriceTypeSupported = false;

      protected override void OnBarUpdate()
      {

      Values[1].Set(Volumes[1][0]);
      Values[0].Set(Volumes[2][0]);
      //PlotBid.Set(GetCurrentBidVolume());
      //PlotAsk.Set(GetCurrentAskVolume());
      Values[3].Set(EMA(Volumes[1],maperiod)[0]);
      Values[2].Set(EMA(Volumes[2],maperiod)[0]);


      if(CurrentBar < maperiod )
      {
      return;
      }
      // draw stuff
      }

      Your help is much appreciated.
      I have attached a pic with less intensive indicators... BTW I've discovered that the values is correct as each tick comes in but when the bar is closing the bar created becomes the wrong value. I do not have any additional calculations. I have tried to use the Values[0].Set(1,value). For some reason it always returns an empty plot.

      My latest code with BarsInProgress is not helping


      if(BarsInProgress == 1)
      {
      Values[1].Set(Volumes[1][0]);
      }
      if(BarsInProgress == 2)
      {
      Values[0].Set(Volumes[2][0]);
      }

      PSPS: I've tested the indicator with CalculateOnBarClose, When the CalculateOnBarClose is true, it will produce the correct value, CalculateOnBarClose false will give the wrong value. CORRECTION: It is quite random. Sometimes the true setting matches the VOL indicator and sometimes it doesn't. "true" could match and "false" could not match and sometimes "false" will match and "true" will not match.
      Attached Files
      Last edited by wwteo; 05-17-2012, 01:11 PM.

      Comment


        #4
        I'm happy to help and welcome to our forums by the way.

        What you're likely seeing here is the difference in timing between OnBarUpdate and the actual market data at that time. OnBarUpdate will only be called when a tick has been received, and may not be updating fast enough to see the accurate bid/ask volume at that time.

        I would suggest working in OnMarketData() which is called every time there is a change to the level I data you are looking for.

        Please see our Help Guide article on OnMarketData() for more information:

        MatthewNinjaTrader Product Management

        Comment


          #5
          I have already tried OnMarketData. It doesn't work as well... Same problem with erroneous data after closing. My Time and Sales based volume counting orders seems to do better but does not have history.
          It seems to mostly affect the Ask volume. My guess is the Volume data seems to reset more quickly than the painting of the plot. Would it be better to delay painting the plot or create another dataseries? How do I set values into a plot that are 1 bar ago?
          PS: The volume bar seems to be correct WHILE the bar is forming. The bogus data only comes AFTER the bar is formed. It first forms the correct bid/ask volume data then reforms it into bogus data.
          Last edited by wwteo; 05-17-2012, 09:51 PM.

          Comment


            #6
            Ah looks like I've solved it with a ((FirstTickOfBar) && (BarsInProgress == 0)) code to reset the bars and stopping the bars from overzealously updating the volumes.

            Can I ask is the FirstTickOfBar only apply to the main bar or can I use FirstTickOfBar on other dataseries besides the main one? Is there a FirstTickOfBar for BarsArray[1]?

            Comment


              #7
              wwteo, while there's FirstTickOfBar array accessible, you can check it in context to each BarsInProgress.
              BertrandNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by stafe, 04-15-2024, 08:34 PM
              7 responses
              31 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by adeelshahzad, Today, 03:54 AM
              4 responses
              30 views
              0 likes
              Last Post adeelshahzad  
              Started by merzo, 06-25-2023, 02:19 AM
              10 responses
              823 views
              1 like
              Last Post NinjaTrader_ChristopherJ  
              Started by frankthearm, Today, 09:08 AM
              5 responses
              17 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              43 views
              0 likes
              Last Post jeronymite  
              Working...
              X