Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Basic coding needed to draw a sideways histogram on price chart(like volume profile)?

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

    Basic coding needed to draw a sideways histogram on price chart(like volume profile)?

    Hello.

    I am looking into creating a sideways volume profile on a chart(like a volume profile), and wondering if there is a SIMPLE code example somewhere. I have seen several, and tbh, many of them are just over my head.

    A NOTE, I have drawn a histogram before in NT7. I did it in two ways, taking values from an array I updated on each bar, for the daily session....
    1) I used simple lines, I.e., Draw.Line() from the calculated start and end I needed, drawing many lines that would build a developing profile.
    2) I used boxes, Draw.rectanle()... in a similar way as above, but with a height of 1, which allowed me to have control over the opacity

    Both of the above ways are probably not the most efficient way to accomplish this. So I'm wondering if there is a code sample that offers the SIMPLEST amount of code, so that I can understand how this works. I.e., scouring through some code examples is a bit confusing for a newb like myself.

    I have attached an image of my simple, but likely inefficient way of doing it, along with one I am using now created by someone else(3 images in 1). First image shows the lines I drew, the second shows using rectangles, and third shows someone else's code done right. See image 'distinction.png'

    Another question I have... you can imagine how the profile is built bar by bar... is it possible to code it in such a way that the profile would update based on the number of bars visible on the chart? I.e., imagine you had a day built completely... if you scroll the chart to the left(removing bars in view from the right edge), that it would update the profile based on the scrolling. This feature is not essential, but I'm just wondering if this is a big code change?

    Lastly... I have seen profiles that are colored(like a heat-map) based on various conditions. This is also something I am wondering about, if anyone knows any samples with the base amount of code to do this. This also is not essential, but something I am thinking about. See image called 'colors.png'

    So... I know this is not necessarily a supported feature, and that I have a lot of questions... worst case I'll eventually figure it out by sifting through the examples I have, but I'm hoping someone may be able to point me along the right path to find simple examples to get me started.

    Just to recap, questions are:
    1. Is there a code example that contains the very most basic amount of code to create a simple histogram ON THE PRICE chart, like a volume profile?
    2. Is it possible to build it in such a way, that the profile displayed will be based on how many bars are VISIBLE on the chart, and not necessarily how many bars are available? Again, this feature is not essential, but a good-to-know.
    3. Is there a sample somewhere that explains how to shade the profile based on some condition? Mostly I'm just looking for what one would do to make a profile heat-map fashion as shown in the 'colors.png' image.
    Attached Files
    Last edited by forrestang; 12-15-2020, 05:35 PM.

    #2
    Hello forrestang, thanks for your post.

    We have reached the end of our office hours for today. I will follow up tomorrow with a full reply.

    Thanks in advance for your patience.

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post
      Hello forrestang, thanks for your post.

      We have reached the end of our office hours for today. I will follow up tomorrow with a full reply.

      Thanks in advance for your patience.
      Many thanks... no rush, whenever you have time!

      Comment


        #4
        Hello forrestang, thanks for waiting.

        The best example of rendering a histogram efficiently is the Volume Profile indicator. The Volume Profile source code can be studied through the NinjaScript Editor.

        The ChartBars property has a fromIndex and toIndex that will allow you to loop through every visible bar on the chart, the OnRender method can render data based on just these bars:

        https://ninjatrader.com/support/help..._fromindex.htm

        Unfortunately, I do not have an example of changing brush color based on a condition. The custom script would need to pre-define every possible brush that will be used, then use each of those brushes when drawing based on price/indicator value conditions.

        Please let me know if I can assist any further.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        576 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        334 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X