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

how to plot Bid volume and Ask Volume

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

    how to plot Bid volume and Ask Volume

    I was using Buy sell volume to plot bid volume and ask but it is deciding bid and ask volume from Last trade

    But my data feed is providing bid and ask so want to assign directly bid to bid volume and ask to ask volume.

    How can I do that ?

    namespace NinjaTrader.NinjaScript.Indicators.Infinity
    {
    public class MyCustomIndicator : Indicator
    {

    private double buys;
    private double sells;
    private int activeBar = 0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBuySellVolume;
    Name = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNa meBuySellVolume;
    BarsRequiredToPlot = 1;
    Calculate = Calculate.OnEachTick;
    DrawOnPricePanel = false;
    IsOverlay = false;
    DisplayInDataBox = true;

    // Plots will overlap each other no matter which one of these comes first
    // in NT8, we would add the Sells first in code and then Buys, and the "Sells" was always in front of the buys.
    AddPlot(new Stroke(Brushes.DarkCyan, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeBuys);
    AddPlot(new Stroke(Brushes.Crimson, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.BuySellVolumeSells);
    }
    else if (State == State.Historical)
    {
    if (Calculate != Calculate.OnEachTick)
    {
    Draw.TextFixed(this, "NinjaScriptInfo", string.Format(NinjaTrader.Custom.Resource.NinjaScr iptOnBarCloseError, Name), TextPosition.BottomRight);
    Log(string.Format(NinjaTrader.Custom.Resource.Ninj aScriptOnBarCloseError, Name), LogLevel.Error);
    }
    }
    }

    protected override void OnMarketData(MarketDataEventArgs e)
    {

    if(e.MarketDataType == MarketDataType.Last)
    {

    buys += e.Bid;

    sells += e.Ask;

    }
    }


    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    if (CurrentBar < activeBar || CurrentBar <= BarsRequiredToPlot)
    return;

    // New Bar has been formed
    // - Assign last volume counted to the prior bar
    // - Reset volume count for new bar
    if (CurrentBar != activeBar)
    {
    Sells[1] = sells;
    Buys[1] = buys;
    //buys = 0;
    //sells = 0;
    activeBar = CurrentBar;
    }

    Sells[0] = sells;
    Buys[0] = buys;
    }

    #region Properties
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Sells
    {
    get { return Values[1]; }
    }

    [Browsable(false)]
    [XmlIgnore]
    public Series<double> Buys
    {
    get { return Values[0]; }
    }
    #endregion
    }
    }

    so i did change in Onmarkerdata and assigned Bid to buys ( buys =+ e.Bid) and ask to sell ( sells = + e.Ask) but it is not giving right result...attaching an image of how it is plotting output..
    Attached Files

    #2
    Hello svadukia,

    Thanks for your post.

    You only get the volume at bid and volume at ask when the trade occurs. It sounds more like you want order volume, level 2 data through OnMarketDepth. You can see an example of this with this level 2 order book example: https://ninjatrader.com/support/foru...ead.php?t=5965
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello svadukia,

      Thanks for your post.

      You only get the volume at bid and volume at ask when the trade occurs. It sounds more like you want order volume, level 2 data through OnMarketDepth. You can see an example of this with this level 2 order book example: https://ninjatrader.com/support/foru...ead.php?t=5965
      No I want to plot bid volume ( trade which occurred on bid ) and Ask volume ( Trade which occurred on Ask) . How I can do that... ?

      How I can decide Trade occured at Bid or Ask ??

      Comment


        #4
        Hello svadukia,

        Thanks for your reply.

        In the BuySellVolume indicator this code provides the trade volume at the bid or ask:

        Code:
        protected override void OnMarketData(MarketDataEventArgs e)
        		{			
        			if(e.MarketDataType == MarketDataType.Last)
        			{				
        				if(e.Price >= e.Ask)
        				{
        					buys += e.Volume;
        				}
        				else if (e.Price <= e.Bid)
        				{
        					sells += e.Volume;
        				}
        			}
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello svadukia,

          Thanks for your reply.

          In the BuySellVolume indicator this code provides the trade volume at the bid or ask:

          Code:
          protected override void OnMarketData(MarketDataEventArgs e)
          		{			
          			if(e.MarketDataType == MarketDataType.Last)
          			{				
          				if(e.Price >= e.Ask)
          				{
          					buys += e.Volume;
          				}
          				else if (e.Price <= e.Bid)
          				{
          					sells += e.Volume;
          				}
          			}
          I changed code that was resetting both volume after one bar ....nd plotted them continuously to check difference but both volumes were same so it is not plotting right volume....I have compared it by plotting chart which had market data type Ask and bid

          Comment


            #6
            Hello svadukia,

            I believe the helpguide provides an example of what you are looking for here: https://ninjatrader.com/support/help...marketdata.htm
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Paul View Post
              Hello svadukia,

              I believe the helpguide provides an example of what you are looking for here: https://ninjatrader.com/support/help...marketdata.htm
              Is there any way I can plot Chart with market data type ask and bid in same chart window ?? and also volume which plots ask and Bid too ?

              Comment


                #8
                Originally posted by svadukia View Post
                Is there any way I can plot Chart with market data type ask and bid in same chart window ?? and also volume which plots ask and Bid too ?
                I did it....But is there any way I can plot Volume indicator without getting reset it after one bar ?

                Comment


                  #9
                  Hello svadukia,

                  Thanks for your replies.

                  I'm not sure I am following your question. When you say Volume indicator, do you mean the NinjaTrader indicator VOL which is a volume indicator? If so, then you would need to modify the VOL indicator (modify a copy of it) and allow it to accumulate as you plot.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Paul View Post
                    Hello svadukia,

                    Thanks for your replies.

                    I'm not sure I am following your question. When you say Volume indicator, do you mean the NinjaTrader indicator VOL which is a volume indicator? If so, then you would need to modify the VOL indicator (modify a copy of it) and allow it to accumulate as you plot.
                    Yes NT VOL indicator but there is nothing in code where I can change that

                    Comment


                      #11
                      Hello svadukia,

                      Thanks for your reply and confirming we are talking about the VOL indicator (or a copy of it).

                      Correct, you would need to add code to create an accumulator variable that you declare and then add the bar volume to it and then plot the accumulator variable value.

                      I suspect you will want to reset it at some point in time and typically you would reset it at the first bar of the session. You can use Bars.IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm

                      Example:

                      Code:
                      		protected override void OnBarUpdate()
                      		{
                      		
                      			if (Bars.IsFirstBarOfSession)
                      			{
                      				accum = 0; // reset
                      			}
                      			
                      			accum += Volume[0];
                      			Value[0] = accum;
                      		}
                      Note that accum is declared as private double accum;
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Paul View Post
                        Hello svadukia,

                        Thanks for your reply and confirming we are talking about the VOL indicator (or a copy of it).

                        Correct, you would need to add code to create an accumulator variable that you declare and then add the bar volume to it and then plot the accumulator variable value.

                        I suspect you will want to reset it at some point in time and typically you would reset it at the first bar of the session. You can use Bars.IsFirstBarOfSession: https://ninjatrader.com/support/help...rofsession.htm

                        Example:

                        Code:
                        		protected override void OnBarUpdate()
                        		{
                        		
                        			if (Bars.IsFirstBarOfSession)
                        			{
                        				accum = 0; // reset
                        			}
                        			
                        			accum += Volume[0];
                        			Value[0] = accum;
                        		}
                        Note that accum is declared as private double accum;
                        I don't want to reset it at all.. then How I have to add code ??
                        Nd How to plot that
                        AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, Accum); right ?? And delete that plot which plotting VOLVolume ...

                        Comment


                          #13
                          Hello svadukia,

                          Thanks for your post.

                          In the example provided you could then not use the if statement and not use the reset code. The example is using the existing Volume bar plot to show the accumulated volume.

                          Values[0] represent the plot output.

                          If you wish to plot a line type instead of as a bar you can change the line addPlot line from:

                          AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, NinjaTrader.Custom.Resource.VOLVolume);

                          to

                          AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Line, NinjaTrader.Custom.Resource.VOLVolume);


                          If you would like someone to create this for you, we can provide references to 3rd party ninjascript coders.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            when I try to add it to chart ...gives an error that Index was outside the bounds of the Array.

                            Comment


                              #15
                              Hello svadukia,

                              Thanks for your reply.

                              Please post your code.

                              Alternatively, if you prefer, please feel free to send your code into PlatformSupport[at]NinjaTrader[dot]Com, mark the e-mail Atten:Paul and include a link to this thread. Please attach the entire source code file to the e-mail.
                              Paul H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by alifarahani, Today, 09:40 AM
                              4 responses
                              21 views
                              0 likes
                              Last Post alifarahani  
                              Started by gentlebenthebear, Today, 01:30 AM
                              3 responses
                              16 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by PhillT, Today, 02:16 PM
                              2 responses
                              7 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by Kaledus, Today, 01:29 PM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frankthearm, Yesterday, 09:08 AM
                              14 responses
                              47 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Working...
                              X