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

Volume profile plot at the right

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

    Volume profile plot at the right

    Hi,

    At the moment, default volume profile of NT8 plots the rectangles at float xpos = chartControl.GetXByBarIndex(ChartBars, !Bars.IsTickReplay ? ChartBars.FromIndex : Math.Max(1, Math.Max(ChartBars.FromIndex, firstBarIdxToPaint)) - 1);
    I am trying to move the plot to the right end of the chart. please note I am using 100 margin property in my script for bars to plot at a distance from the right edge of the chart, but I want the profile to plot at the right edge.
    second, how do I limit the rectangles to remain within that 100 margin so that it does not overlap my bars on the chart?
    If anyone can help, will be helpful.

    #2
    Hello asmmbillah,

    To reverse what this is doing you may need to use the ChartBars.ToIndex here which represents the last visible bar on the chart. https://ninjatrader.com/support/help...ghtsub=toindex
    That is likely going to break some of the other rendering logic it has so this would be a situation where you will have to experiment to achieve the look you want. I see that setting the FromIndex to ToIndex does move it to the right however that also messes with the width and placement so that is something you would want to explore as you develop this modification.

    float xpos = chartControl.GetXByBarIndex(ChartBars, Math.Max(1, Math.Max(ChartBars.ToIndex, firstBarIdxToPaint)) - 1);

    This is just a simple test to move the rendering.


    To limit the rectangle will involve modifying the logic to limit where the xposition can go or the width the rectangles are being drawn.The logic as it is does not limit the rectangles to a specific size but uses math to calculate their sizes. You could include something like Math.Max and include a hard limit as well.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thanks that was helpful, but what if I want to plot the rectangles' height with a int variable ? at the moment it is simply plotting with ticksize. But when I am trying to increase the plot height, it is overlapping with other rectangles above and below. Which line/s, you think I should modify of the current volume profile. Thanks in advance.

      Comment


        #4
        Hello asmmbillah,

        The height is being calculated in the script currently which is why it allows for scaling and no overlapping. If you use just an int or same value for the height you no longer account for the scale.

        The height is calculated by using the price and the price plus 1 tick which give two dynamic Y values. Those values correspond with prices so when the scale moves in or out the prices move in the Y direction closer or further away. A static amount of height cannot account for that change which will leave gaps or have overlaps.

        If you want to increase the height and also not overlap you would either need to add logic to now plot each new level at a higher price for the next rectangle or some logic to limit the max Y to the next tick size like it is already doing. I would suggest to experiment here by making small modifications and see how that affects the plotting to get a better idea of how each variable works with the rectangle. The yUpper yLower and height variables are how the rectangle is sized so that would be what you could start modifying to see a change.


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          thanks for your reply. I have the below following your advisse above.

          public int PriceLevelInTicks { get; set; }

          if (State == State.SetDefaults)
          {
          PriceLevelInTicks = 50;
          }

          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
          {
          foreach (KeyValuePair<double, VolumeInfoItem> keyValue in sortedDicList[startIndexOf])
          {
          float yLower = chartScale.GetYByValue(priceLower);
          float yUpper = chartScale.GetYByValue(priceLower + (tickSize * PriceLevelInTicks));
          float height = Math.Max(1, Math.Abs(yUpper - yLower) - barSpacing);
          }
          }
          but still it overlaps. Can you please see where am I going wrong above?
          thanks in advance.

          Comment


            #6
            Hello asmmbillah,

            The prices you calculate will need to not overlap, that is the reason the overlap is happening. The calculation that it was using only accounts for 1 tick of spacing in price based on how the data is collected. There is no filtering happening with the dictionary so you are getting the price values from the granularity of the TickSize.

            You likely will need to modify the overall calculation here including the OnBarUpdate logic if you want to display different price levels at different amounts of ticks. The rendering is not the only part of how the level is designed in this script but also how the data is collected. The rendering is just a representation of the existing data so to actually modify it without overlapping will take some work to do that.


            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Thanks for your reply. So Do I collect the volume for Close[0]+PriceLevelInTicks * tickSize or should it collect for tick size and then sort them? but if its later one, any suggestion how that can be achieved in this script, because I just tried, it kind of does not work. or is their any example script you have in this website, I can get an idea from to resolve this problem?
              Last edited by asmmbillah; 05-21-2020, 01:58 PM.

              Comment


                #8
                Hello asmmbillah,

                If you make different price levels the indicator is not really doing what it originally did so now this really relies on what you want to do here. If you want to group the data and sort it to those levels you could do that, you could also just omit the data for levels that don't fall within your tick sizes. This will depend on what you want the final change to look like. Are you just trying to make the rectangles thicker or are you trying to include the data from the levels where you now included based on the increase tick size?

                I am not aware of a specific sample that I can link here, the change you are asking for is fairly specific to this script and how it works so this is likely something you would have to do yourself. What specifically are you having difficulty with surrounding the concepts being used here? Potentially I could provide other resources that can help with the individual concepts being used.



                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  thanks for your reply. At the moment volume profile is plotting the volume at tick size price level. I want to be able to make it a bit flexible in a way that by using a parameter variable, instead of just tick size price level plots, if I change the price level variable to 10, then volumes fall within price level of 10 tick size it will plot a rectangle of 10 ticksize and all volumes within that price levels, and if I change the parameter value to 25, then height of the rectangle will change accordingly and volumes within 25 tick size price levels will be plotted in corresponding price levels. In short, instead of fixed tick size, I want to make it flexible to plot any range of price level for each rectangle height and volume fall within that range of price level. I hope that clarifies.

                  Comment


                    #10
                    Hello asmmbillah,

                    Thank you for the reply.

                    So in that situation you would likely want to instead look at how the indicator is collecting the data first instead of how it is rendering the data. You can approach this in two ways. One would be to modify its accumulation to make it accumulate how you are asking or for those price levels. The rendering is based on the dictionary data so how you fill that will delegate how the rendering loop works. The other possible way would be to retain the same accumulation that it does now and modify the rendering loop to group the data based on the tick amount you wanted. I don't really have a specific suggestion that I can provide for either case, if you change the accumulation logic you will have to make new logic for how you want to group the data in the dictionary. If you change the rendering logic you would need to figure out how you want to split the loop on the dictionary up to the price levels you wanted.

                    What you are trying now is looping over the same price levels as the original indicator but you increase the height of each rectangle. Without also increasing the next levels price to accommodate for the increase in height that leaves the overlap you see because the next level still starts at the same price that it originally did.




                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for your reply and advise. "Without also increasing the next levels price to accommodate for the increase in height" - that is the million dollar sentence. That where I am failing. At least can you not, give a hint at which syntax this above quoted process taking place? Then I can tryin different ways.

                      Comment


                        #12
                        Hello asmmbillah,

                        The dictionary that is being used is what you would need to look at for this part of the question. Right now it uses a dictionary which has the price as the key, that is used so you can easily store values at each price level. If you wanted to make different levels the logic to store at each price level would have to change. This is happening in the OnMarketData override in the script.

                        I look forward to being of further assistance.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks for your reply. For doing that I am following Volume zones NT8 indicator as a ref.

                          I am getting current live bar as int firstBar = ChartBars.FromIndex; but I am struggling to get the first bar of the session as int lastBar;
                          I have tried int lastBar = ChartControl.GetXByBarIndex(ChartBars, !Bars.IsTickReplay ? ChartBars.FromIndex : Math.Max(ChartBars.FromIndex, firstBarIdxToPaint));
                          where
                          DateTime lastBarTimeStamp = GetLastBarSessionDate(Time[0]);

                          if (lastBarTimeStamp != currentDate)
                          {
                          cacheDictionary = new Dictionary<double, VolumeInfoItem>();
                          sortedDicList.Add(cacheDictionary);
                          }

                          currentDate = lastBarTimeStamp;

                          int firstBarIdxToPaint = -1;

                          for (int i = newSessionBarIdx.Count - 1; i > 0; i--)
                          {
                          if (newSessionBarIdx[i] <= ChartBars.ToIndex)
                          {
                          startIndexOf = i;
                          firstBarIdxToPaint = newSessionBarIdx[i];
                          break;
                          }

                          }
                          This one I have taken from the original volume profile indicator of NT8. I am printing but the first session bar index is coming wrong. Any suggestion will be appreciated.

                          Comment


                            #14
                            Is there anyone who can advise on the above post of mine?

                            Comment


                              #15
                              Hello asmmbillah,

                              From looking at the code and description I couldn't really advise much here as I don't know what specifically is wrong with your output. This is likely a situation where you would need to use more Prints to make sure all the variables being used are the correct values for what you are trying to do.

                              The The current live bar is confusing term here, do you mean the left most bar? FromIndex is the current left most bar visually, that changes as you scroll.

                              This also references Time[0] rather than the current visible time which may affect what you are trying to accomplish. If you mean to get the time from sometime within the visible range and check the session from that time you would have to change the use of Time[0] here.

                              I look forward to being of further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by agclub, 04-21-2024, 08:57 PM
                              5 responses
                              32 views
                              0 likes
                              Last Post agclub
                              by agclub
                               
                              Started by ESHunter, Today, 08:06 PM
                              2 responses
                              14 views
                              0 likes
                              Last Post ESHunter  
                              Started by ETFVoyageur, 05-07-2024, 07:05 PM
                              19 responses
                              150 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by ETFVoyageur, Yesterday, 10:13 PM
                              3 responses
                              26 views
                              0 likes
                              Last Post ETFVoyageur  
                              Started by ETFVoyageur, Yesterday, 12:52 AM
                              3 responses
                              33 views
                              0 likes
                              Last Post ETFVoyageur  
                              Working...
                              X