• 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

How to create a vertical histogram ?

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

    How to create a vertical histogram ?

    Hey,

    I would like to program a kind of Volume Profile.
    So, I got an array, each values matchs with a price (so one value per tick size), and I would like to display it as a vertical histogram like a Volume Profile ?

    How could I do it ?

    Thanks !

    #2
    Hello After,

    The VolumeProfile indicator creates a horizontal (side to side) histogram.

    This indicator uses non NinjaScript methods to achieve this that are not documented in the help guide (this is done with general C#). This is done by overriding the Plot method. (The Plot method is called anytime the chart is rendered. In NinjaTrader 8, this will be the OnRender method.)

    Take a look at the code of the VolumeProfile indicator. Tools -> Edit NinjaScript... -> Indicator -> VolumeProfile -> OK.

    Instead of holding the values in a Plot object, the values are held in a SortedDictionary object.
    http://www.dotnetperls.com/sorteddictionary. This is filled with calculations made in OnMarketData when each incoming tick with volume information is received.

    The SortedDictionary keys are the price levels for each tick that is received.
    The value is a class that holds a volume amount for up, down, and neutral. (A custom class with 3 doubles.)

    Then in the Plot override, brushes are made for colors for up, down, and neutral.
    SolidBrush upBrush = barBrushUp;

    The array is looped over
    foreach (KeyValuePair<double, VolumeInfoItem> keyValue in volumeInfo)

    For each object a rectangle is made at the price.
    int yUpper = ChartControl.GetYByValue(this, priceLower + tickSize);

    The width (horizontal length) is done by a calculation of the amount of volume
    int barWidthUp = (int) ((bounds.Width / 2) * (vii.up / volumeMax));

    A rectangle is drawn each for barWidthUp, barWidthDown, and barWidthNeutral, using the brush, the x starting position (xpos), y position (yUpper), width (barWidthUp) and height.
    graphics.FillRectangle(upBrush, new Rectangle(xpos, yUpper, barWidthUp, height));
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks Chelsea !

      Well, what I wanted to program is far more less complex than a VP, because it doesn't get update at each ticks but only at each candle.

      So, I guess the easier way is to create a rectangle, and fill it with others rectangle to create the vertical histogram at each candle ?

      Comment


        #4
        Hello After,

        This depends on if you would like a vertical histogram or a horizontal histogram.

        The VOL indicator uses a vertical histogram. This is a defined plot type and using the Plot Class is available.

        Take a look at how the VOL indicator works to create a vertical histogram. No custom code is needed to render the rectangles. This is all handled by setting the plot with Value.Set().

        The VolumeProfile uses a horizontal histogram and this requires custom programming to achieve.


        So if you are wanting a vertical histogram, do not use the VolumeProfile as an example, instead use the VOL which uses a vertical histogram.

        From the VOL indicator:
        Add(new Plot(new Pen(Color.Blue, 2), PlotStyle.Bar, "Volume"));
        Value.Set(Volume[0]);

        This is all that is needed to make a vertical histogram.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by HiddenPhilosopher, Today, 07:24 PM
        0 responses
        6 views
        0 likes
        Last Post HiddenPhilosopher  
        Started by dkbyond, Today, 06:43 PM
        0 responses
        5 views
        0 likes
        Last Post dkbyond
        by dkbyond
         
        Started by i2w8am9ii2, Today, 06:05 PM
        0 responses
        2 views
        0 likes
        Last Post i2w8am9ii2  
        Started by YevhenShynkarenko, Today, 05:46 PM
        0 responses
        4 views
        0 likes
        Last Post YevhenShynkarenko  
        Started by Bionian, Today, 04:14 PM
        0 responses
        4 views
        0 likes
        Last Post Bionian
        by Bionian
         
        Working...
        X