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 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 Mestor, 03-10-2023, 01:50 AM
        16 responses
        388 views
        0 likes
        Last Post z.franck  
        Started by rtwave, 04-12-2024, 09:30 AM
        4 responses
        31 views
        0 likes
        Last Post rtwave
        by rtwave
         
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        29 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        22 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        7 views
        0 likes
        Last Post funk10101  
        Working...
        X