Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to draw a line using the PlotStyle from a Plot?

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

    How to draw a line using the PlotStyle from a Plot?

    I want to extend a plot into the right margin space by drawing. how do I draw using the PlotStyle, if it is not a line. (e.g., PlotStyle.Cross)?

    #2
    Hello koganam,

    Thanks for your post. This would require custom rendering to accomplish. Below is a modified snippet from the help guide which can demonstrate drawing from the last bar to the right side margin.

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
      base.OnRender(chartControl, chartScale);
      // get the starting and ending bars from what is rendered on the chart
      float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex);
      float endX = (ChartPanel.X + ChartPanel.W);
    
      // Loop through each Plot Values on the chart
      for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
      {
        // get the value at the last bar on the chart (if it has been set)
        if (Values[seriesCount].IsValidDataPointAt(ChartBars.ToIndex))
        {
            double plotValue = Values[seriesCount].GetValueAt(ChartBars.ToIndex);
    
            // convert the plot value to the charts "Y" axis point
            float chartScaleYValue = chartScale.GetYByValue(plotValue);
    
            // calculate the x and y values for the line to start and end
            SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, chartScaleYValue);
            SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue);
    
            // draw a line between the start and end point at each plot using the plots SharpDX Brush color and style
            RenderTarget.DrawLine(startPoint, endPoint, Plots[seriesCount].BrushDX,
              Plots[seriesCount].Width, Plots[seriesCount].StrokeStyle);
        }
      }
    }
    PlotStyle.Cross cannot be used as a SharpDX StrokeStyle, so additional vertical lines would need to be drawn the spanning from ChartBars.ToIndex to ChartPanel.X + CharPanel.W. You can draw small vertical lines on top of this bar spanning the distance between ChartBars.ToIndex and ChartBars.ToIndex-1 to offset each vertical line so they are distanced in the same fashion as other bars on the chart.

    With the small vertical lines drawn on top of the horizontal line, you will have achieved the same visual effect as having the PlotStyle.Cross plot extend to the right side margin.

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello koganam,

      Thanks for your post. This would require custom rendering to accomplish. Below is a modified snippet from the help guide which can demonstrate drawing from the last bar to the right side margin.

      Code:
      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
      base.OnRender(chartControl, chartScale);
      // get the starting and ending bars from what is rendered on the chart
      float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex);
      float endX = (ChartPanel.X + ChartPanel.W);
      
      // Loop through each Plot Values on the chart
      for (int seriesCount = 0; seriesCount < Values.Length; seriesCount++)
      {
      // get the value at the last bar on the chart (if it has been set)
      if (Values[seriesCount].IsValidDataPointAt(ChartBars.ToIndex))
      {
      double plotValue = Values[seriesCount].GetValueAt(ChartBars.ToIndex);
      
      // convert the plot value to the charts "Y" axis point
      float chartScaleYValue = chartScale.GetYByValue(plotValue);
      
      // calculate the x and y values for the line to start and end
      SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, chartScaleYValue);
      SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue);
      
      // draw a line between the start and end point at each plot using the plots SharpDX Brush color and style
      RenderTarget.DrawLine(startPoint, endPoint, Plots[seriesCount].BrushDX,
      Plots[seriesCount].Width, Plots[seriesCount].StrokeStyle);
      }
      }
      }
      PlotStyle.Cross cannot be used as a SharpDX StrokeStyle, so additional vertical lines would need to be drawn the spanning from ChartBars.ToIndex to ChartPanel.X + CharPanel.W. You can draw small vertical lines on top of this bar spanning the distance between ChartBars.ToIndex and ChartBars.ToIndex-1 to offset each vertical line so they are distanced in the same fashion as other bars on the chart.

      With the small vertical lines drawn on top of the horizontal line, you will have achieved the same visual effect as having the PlotStyle.Cross plot extend to the right side margin.

      Please let me know if I can be of further assistance.
      Your response goes way further afield, and has a specificity that is way too narrow, relative to the question that I asked. I have already been able to finagle the PlotStyle.Cross pretty much in the manner that you describe. However, I used that PlotStyle pretty much as an example for my question, not as the only specific style to be used. I wanted to know how to use the Plot's PlotStyle, whatever it may be. After all, you are rendering the chart with the various plot styles, per user choice.

      I was asking how to do the same using whatever the user may have already chosen. I really did not want to have to think through and code for each specific choice in the enumeration. I am way too lazy for that.

      Comment


        #4
        Wondering if there is a way to add a desired PlotStyle to a existing or called Ray, and Referenced Ray instead of them using DashStyle to be able to call the string name or ray to hard code a PlotStyle TriangleUp/Down. Is it possible using these line types?

        Comment


          #5
          Hello LoganJKTrader,

          I may not be understanding the question fully.

          PlotSyles are specific for customizing plots. Plots also contains a Stroke which has a Brush (color) and DashStyle.

          If you want to customize plotting code, you will have to override the indicator's OnRender method.

          Drawing Objects may only have the Stroke (includes DashStyle) to customize.

          A list of available drawing commands that would not require custom rendering code in OnRender can be found below. Maybe you are looking to use Draw.ArrowUp/Draw.ArrowDown?



          If there are additional questions, could you further describe what you are trying to accomplish?
          JimNinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Jim View Post
            Hello LoganJKTrader,

            I may not be understanding the question fully.

            PlotSyles are specific for customizing plots. Plots also contains a Stroke which has a Brush (color) and DashStyle.

            If you want to customize plotting code, you will have to override the indicator's OnRender method.

            Drawing Objects may only have the Stroke (includes DashStyle) to customize.

            A list of available drawing commands that would not require custom rendering code in OnRender can be found below. Maybe you are looking to use Draw.ArrowUp/Draw.ArrowDown?

            https://ninjatrader.com/support/help...t8/drawing.htm

            If there are additional questions, could you further describe what you are trying to accomplish?
            Yes I have a set of high and low rays which also have a reference ray bool, and then there is one and two StDvtn away as a target of the high and low levels, and the HL and the targets are similar in visual style and having them changed plotstyle will help to identify what it is that is and differ the look.

            Comment


              #7
              Hello LoganJKTrader,

              Ray's do not have a PlotStyle, We would only be able to customize the DashStyle, and we would us the following overloads for that purpose:

              Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width)

              Draw.Ray(NinjaScriptBase owner, string tag, bool isAutoScale, int startBarsAgo, double startY, int endBarsAgo, double endY, Brush brush, DashStyleHelper dashStyle, int width, bool drawOnPricePanel)

              Draw.Ray(NinjaScriptBase owner, string tag, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width, bool drawOnPricePanel)


              https://ninjatrader.com/support/help...l?draw_ray.htm

              If you wanted to make a custom Ray that looks like a PlotStyle, that would require custom rendering in a drawing tool. You could make a copy of the Lines DrawingTool if you wanted to make modifications for a customized Ray.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by algospoke, 04-17-2024, 06:40 PM
              6 responses
              48 views
              0 likes
              Last Post algospoke  
              Started by arvidvanstaey, Today, 02:19 PM
              4 responses
              11 views
              0 likes
              Last Post arvidvanstaey  
              Started by samish18, 04-17-2024, 08:57 AM
              16 responses
              61 views
              0 likes
              Last Post samish18  
              Started by jordanq2, Today, 03:10 PM
              2 responses
              9 views
              0 likes
              Last Post jordanq2  
              Started by traderqz, Today, 12:06 AM
              10 responses
              19 views
              0 likes
              Last Post traderqz  
              Working...
              X