Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Rendering Text on Price panel, in an indicator shown on a different panel

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

    Rendering Text on Price panel, in an indicator shown on a different panel

    Hi,

    I am trying to fix the indicator VPA. I added titles to the symbols, and when using 1 minute timeframe the indicator becomes slow. I guess the reason is the large number of draw objects. So I try to switch to OnRender. The challenge is the indicator at it's base plot volume quantities on separate panel, while recolor and draw text on the price panel. Even with DrawOnPricePanel=true, the DX drawing objects, such as DrawTextLayout or DrawRectangle draw on the indicator panel.

    Any supported or unsupported way to solve this?

    QuantKey_Bruce, I notice you dealt with this.Any tip?


    #2
    Shai Samuel You would have to break out of your normal clipping rectangle to draw outside of the panel your indicator is on. You might want to take a look at this as a starting point: https://forum.ninjatrader.com/forum/...en#post1100886
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thank you Bruce @QuantKey_Bruce​ for your quick response, and help. I value that much.
      For some reason, I think this drawing tool doesn't function well now. As you can see in the image, it only draw the line on the top half of the chart.
      Also, I am not sure I fully understand the trick he use to calculate the adjustment to the desired panel.
      Can you try and be more specific?​

      Click image for larger version

Name:	Screenshot 2023-09-10 at 18.11.22.png
Views:	241
Size:	251.4 KB
ID:	1268217.

      Comment


        #4
        Hello Shai Samuel,

        Thanks for your post.

        Indicators are only able to draw on the indicator panel or the price panel when using Draw methods such as Draw.VerticalLine() or Draw.Diamond().

        Setting DrawOnPricePanel to true in State.SetDefaults will make all the drawing methods draw to the price panel rather than the indicator panel. If DrawOnPricePanel is set to false in State.SetDefaults, this will make all the drawing methods draw to the indicator panel rather than the price panel.

        You will not be able to draw to the sub-panel unless you use custom rendering with SharpDX in the OnRender method. We have an overview of using OnRender here:

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

        We are tracking interest in an existing feature request ticket for the support/ability to extend vertical line draw objects to cover all chart panels and I have added your vote to this feature request. This request is being tracked under the number SFT-654.

        As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted on the Release Notes page of the Help Guide.

        Release Notes — https://ninjatrader.com/support/help...ease_notes.htm
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          I have solved the issue:

          Code:
                
          //Draw a text at {x;y} coordinates in pixel.
          protected void DrawDXString(Gui.Chart.ChartControl chartControl, Gui.Chart.ChartScale chartScale,
              string text, int bar, double val, float xOffset, float yOffset, SimpleFont font, Brush textBrush,
              SharpDX.DirectWrite.TextAlignment textAlignment,
              float width = 0f, int opacity=100, int fontSize=14, bool drawOnPricePanel=false)
          {            
              font.Size = (fontSize==0?chartControl.BarWidth*fontFactor:(font.Size!=0?font.Size:fontSize));
              double x = (double)BarToX(bar, chartControl)+xOffset;
              double y = -font.TextFormatHeight/2+yOffset;
          
              if (!drawOnPricePanel || Panel==0)
                   y = PriceToY(val, chartScale)+y;
              else // if (drawOnPricePanel && Panel>0)
              {
                  RenderTarget.AntialiasMode    = SharpDX.Direct2D1.AntialiasMode.PerPrimitive;
                  // get current panel
                  ChartPanel    panel            = chartControl.ChartPanels[chartScale.PanelIndex];
          
                  // Switch Clip to Price chart
                  RenderTarget.PopAxisAlignedClip();
                     RenderTarget.PushAxisAlignedClip(new SharpDX.RectangleF((float)chartControl.ChartPanels[0].X,
                      (float)chartControl.ChartPanels[0].Y, (float)chartControl.ChartPanels[0].W, (float)chartControl.ChartPanels[0].H), RenderTarget.AntialiasMode);
          
                  // get y base on panel[0] - price panel
                  foreach(ChartScale cScale in chartControl.ChartPanels[0].Scales)
                      if (cScale.PanelIndex==0 && val>=cScale.MinValue && val<=cScale.MaxValue)
                           y = PriceToY(val, cScale)+y;
              }
          
              DrawDXString(text, x, y, font, textBrush, textAlignment, width, opacity);    
          
              if (drawOnPricePanel && Panel>0)
              {
                  RenderTarget.PopAxisAlignedClip();
                     RenderTarget.PushAxisAlignedClip(new SharpDX.RectangleF((float)ChartPanel.X, (float)ChartPanel.Y, (float)ChartPanel.W, (float)ChartPanel.H), RenderTarget.AntialiasMode);
              }
          }
          ​​

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          577 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