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

chartControl.GetBarPaintWidth(chartControl.BarsArray[0]) doesn't seem to work

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

    chartControl.GetBarPaintWidth(chartControl.BarsArray[0]) doesn't seem to work

    I'm trying to make a dot in OnRender that is the same width as the bars, and shrinks as you zoom in on the chart.

    I have a class level variable I set in OnRender
    HTML Code:
    barWidthP        = chartControl.GetBarPaintWidth(chartControl.BarsArray[0]);

    then I use it in a method
    HTML Code:
    //==================================================================================================            
            private void RenderEntryDot(ChartControl chartControl, ChartScale chartScale,    int x, double center)
            {
                int c1;
                c1                 = chartScale.GetYByValue(center);
                lineStart         = new SharpDX.Vector2(x, c1);
    
                dot = new SharpDX.Direct2D1.Ellipse(lineStart, barWidthP, barWidthP);        
                RenderTarget.FillEllipse(dot, DxBrushWhite);
            }
    ​

    the dot shrinks when I zoom in, but it doesn't appear to be the bar width. What am I dong wrong?

    Click image for larger version

Name:	image.png
Views:	26
Size:	144.9 KB
ID:	1301196

    #2
    Hello cre8able,

    Thank you for your post.

    Is the dot the same width as the bars initially, but not shrinking with the bars? Or is it not the same width from the start?

    To confirm, barWidthP is being calculated in OnRender correct? Where is RenderEntryDot being called?

    I look forward to your response.
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Hey Gaby

      It's not the same width initially. The image shows how wide it is when I load it on the chart.

      It does shrink/grow as I zoom the chart, so it does respond to scaling.

      BarWidthP is called from OnRender

      I also call RenderEntryDot from OnRender.

      I also tried chartControl.Properties.BarDistance but that didn't work either.


      HTML Code:
              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {
                  barWidthP        = chartControl.GetBarPaintWidth(chartControl.BarsArray[0]);
      //            barWidthP        = (int)chartControl.Properties.BarDistance - chartControl.GetBarPaintWidth(chartControl.BarsArray[0]);
                  
                  stagger = 0;        //    set stagger to zero so open gap targets don't move
      //=====    SWING HIGHS            
                  for (int x = SwingHighsClosed.Count - 1; x >= 0 ; x--)
                      RenderSwingHighs(SwingHighsClosed[x].price, SwingHighsClosed[x].startTime, SwingHighsClosed[x].endTime, SwingHighsClosed[x].eqhlCount, chartControl, chartScale);
                  
                  for (int x = SwingHighs.Count - 1; x >= 0 ; x--)
                      RenderSwingHighs(SwingHighs[x].price, SwingHighs[x].startTime, SwingHighs[x].endTime, SwingHighs[x].eqhlCount, chartControl, chartScale);
      //=====    SWING LOWS
                  for (int x = SwingLowsClosed.Count - 1; x >= 0 ; x--)
                      RenderSwingLows(SwingLowsClosed[x].price, SwingLowsClosed[x].startTime, SwingLowsClosed[x].endTime, SwingLowsClosed[x].eqhlCount, chartControl, chartScale);
                  
                  for (int x = SwingLows.Count - 1; x >= 0 ; x--)
                      RenderSwingLows(SwingLows[x].price, SwingLows[x].startTime, SwingLows[x].endTime, SwingLows[x].eqhlCount, chartControl, chartScale);
                  
      //=====    CLOSED BULL GAPS
                  for (int x = BullGapsClosed.Count - 1; x >= 0 ; x--)
                  {            
                      RenderBullFVGsClosed(x, chartControl, chartScale);
                      RenderEntryDot(chartControl, chartScale,chartControl.GetXByTime(BullGapsClosed[x].endTime),  BullGapsClosed[x].entry);
                      if (ShowTargets)                
                          RenderTargets(chartControl, chartScale, chartControl.GetXByTime(BullGapsClosed[x].endTime), BullGapsClosed[x].entry, BullGapsClosed[x].tFixed, BullGapsClosed[x].sFixed, BullGapsClosed[x].be);
                  }
      //=====    CLOSED BEAR GAPS            
                  for (int x = BearGapsClosed.Count - 1; x >= 0 ; x--)
                  {            
                      RenderBearFVGsClosed(x, chartControl, chartScale);
                      RenderEntryDot(chartControl, chartScale,chartControl.GetXByTime(BearGapsClosed[x].endTime),  BearGapsClosed[x].entry);
                      if (ShowTargets)                                
                          RenderTargets(chartControl, chartScale, chartControl.GetXByTime(BearGapsClosed[x].endTime), BearGapsClosed[x].entry, BearGapsClosed[x].tFixed, BearGapsClosed[x].sFixed, BearGapsClosed[x].be);
                  }        
      ​

      Comment


        #4
        Hey Gabby

        when I draw a triangle, it does make it the same width as the bar

        HTML Code:
                private void RenderArrow(ChartControl chartControl, ChartScale chartScale, int x1, int y1, int direction)
                {
            
                    float arrowheadHeight        = (float)(barWidthP);// * 1.5);
                    float arrowheadWidth        = arrowheadHeight / 2;
                    float shaftHeight            = arrowheadHeight * 2;
                    float shaftWidth            = arrowheadHeight / 3;
                        
                    DxVector1 = new SharpDX.Vector2(x1, y1);
                    DxVector2 = new SharpDX.Vector2(x1 + arrowheadWidth * direction, y1 - arrowheadHeight * direction);
                    DxVector3 = new SharpDX.Vector2(x1 - arrowheadWidth * direction, y1 - arrowheadHeight * direction);
                    DxVector4 = new SharpDX.Vector2(x1, y1 - arrowheadHeight * direction);
                    DxVector5 = new SharpDX.Vector2(x1, y1 - shaftHeight * direction);
                                    
                    SharpDX.Direct2D1.Triangle triangle = new SharpDX.Direct2D1.Triangle();
                    triangle.Point1 = DxVector2;
                    triangle.Point2 = DxVector3;
                    triangle.Point3 = DxVector1;
                    SharpDX.Direct2D1.Mesh triangleMesh = new SharpDX.Direct2D1.Mesh(RenderTarget, new SharpDX.Direct2D1.Triangle[] {triangle});
                    
                    RenderTarget.FillMesh(triangleMesh, DxBrushYellow);
                        
                    RenderTarget.DrawLine(DxVector4, DxVector5, DxBrushYellow, shaftWidth);
        
                }
        ​
        ​

        Click image for larger version  Name:	image.png Views:	0 Size:	117.8 KB ID:	1301247
        Last edited by cre8able; 04-27-2024, 08:45 AM.

        Comment


          #5
          Hey Gaby

          Sorry, I just figured it out.

          I thought the parameter for Ellipse was diameter, but its radius so the dot was twice as big as I was expecting. Oops

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by MSerag, Yesterday, 11:52 PM
          0 responses
          5 views
          0 likes
          Last Post MSerag
          by MSerag
           
          Started by DynamicTest, Yesterday, 11:18 PM
          0 responses
          3 views
          0 likes
          Last Post DynamicTest  
          Started by dcriador, Yesterday, 01:43 AM
          3 responses
          20 views
          0 likes
          Last Post dcriador  
          Started by smartromain, Yesterday, 10:50 PM
          0 responses
          5 views
          0 likes
          Last Post smartromain  
          Started by popecapllc, 08-09-2023, 07:42 PM
          10 responses
          1,366 views
          0 likes
          Last Post BartMan
          by BartMan
           
          Working...
          X