• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

total number of bars onrender and period

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

    #16
    Hello frankduc,

    It draws a line on the first bar of each new rollover period.

    It calculates which bars will have the line in OnBarUpdate(), then in OnRender() if the bar is visible on the chart renders the line over the bar. This could easily render an ellipse instead of a line.

    From the help guide:
    "7. Please limit any calculations or algorithms you may be tempted run in OnRender() simply to rendering. You should always favor precomputed values and store them for rendering later as the preferred approach to working with the OnRender() method (e.g., reusing brushes, passing values from OnBarUpdate(), etc.). See also OnRenderTargetChanged() method for more information on reusing Brushes"
    https://ninjatrader.com/support/help...s/onrender.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      It looks like this is the part i need to create my line.


      // draw a vertical line and box with the offset for that contract month where each new expiry period begins
      for (int i = 0; i < drawTheseRolls.Count; ++i)
      {
      if (drawTheseRolls[i].BarNumber >= ChartBars.FromIndex && drawTheseRolls[i].BarNumber <= ChartBars.ToIndex)
      {
      reuseLineVector1.X = ChartControl.GetXByBarIndex(ChartBars, drawTheseRolls[i].BarNumber) + (ChartControl.Properties.BarDistance / 2);
      reuseLineVector1.Y = 0;
      reuseLineVector2.X = reuseLineVector1.X;
      reuseLineVector2.Y = (float)ChartPanel.ActualHeight;

      RenderTarget.DrawLine(reuseLineVector1, reuseLineVector2, rollMarkerBrushDx, RollMarkerStroke.Width, RollMarkerStroke.StrokeStyle);

      UpdateRect(ref reuseRect, reuseLineVector1.X + 5, reuseLineVector2.Y - 27 - (RollMarkerStroke.Width * 3), 250, 100);
      RenderTarget.DrawText(drawTheseRolls[i].Label, stringFont, reuseRect, rollMarkerBrushDx);

      Comment


        #18
        Hello frankduc,

        Yes, this is the code in OnRender() that renders the line if the bar number is between the visible indexes.
        The drawTheseRolls list is populated with logic in OnBarUpdate().
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          I dont want to take more of your time so you can reply when you can.

          To draw the vertical line do i need all of this?

          // get the starting and ending bars from what is rendered on the chart
          float
          startX
          =
          chartControl.GetXByBarIndex(ChartBars,
          ChartBars.FromIndex);
          float
          endX
          =
          chartControl.GetXByBarIndex(ChartBars,
          ChartBars.ToIndex);
          // 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);
          // use the chart control text form to draw plot values along the line
          SharpDX.DirectWrite.TextFormat
          textFormat
          =
          chartControl.Properties.LabelFont.ToDirectWriteTex tFormat();
          // calculate the which will be rendered at each plot using it the plot name and its price
          string
          textToRender
          =
          Plots[seriesCount].Name
          +
          ": "
          +
          plotValue;
          // calculate the layout of the text to be drawn
          SharpDX.DirectWrite.TextLayout
          textLayout
          =
          new
          SharpDX.DirectWrite.TextLayout(Core.Globals.Direct WriteFactory,
          textToRender,
          textFormat,
          200
          ,
          textFormat.FontSize);
          // draw a line at each plot using the plots SharpDX Brush color at the calculated start point
          RenderTarget.DrawTextLayout(startPoint,
          textLayout,Plots[seriesCount].BrushDX);

          Or only this part is important:


          // 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);
          // use the chart control text form to draw plot values along the line
          SharpDX.DirectWrite.TextFormat
          textFormat
          =
          chartControl.Properties.LabelFont.ToDirectWriteTex tFormat();
          // calculate the which will be rendered at each plot using it the plot name and its price
          string
          textToRender
          =
          Plots[seriesCount].Name
          +
          ": "
          +
          plotValue;
          // calculate the layout of the text to be drawn
          SharpDX.DirectWrite.TextLayout
          textLayout
          =
          new
          SharpDX.DirectWrite.TextLayout(Core.Globals.Direct WriteFactory,
          textToRender,
          textFormat,
          200
          ,
          textFormat.FontSize);


          I am not sure which one is necessary and what is going to make my line a vertical one.

          Comment


            #20
            Hello frankduc,

            I don't know what this code is.

            If its drawing what you want it to draw then likely its the code needed to do that.

            But it looks like the relevant part is:
            RenderTarget.DrawLine(startPoint, endPoint, Plots[seriesCount].BrushDX, Plots[seriesCount].Width, Plots[seriesCount].StrokeStyle);

            So the startPoint and endPoint would be needed.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Sorry it was from that page https://ninjatrader.com/support/help...s/onrender.htm
              Using multiple SharpDX objects to override the default plot appearance

              but to get seriesCount do i need to loop
              for
              (
              int
              seriesCount
              =
              0
              ;
              seriesCount
              <
              Values.Length;
              seriesCount++)

              cause there also a loop in your indicator if (drawTheseRolls[i].BarNumber >= ChartBars.FromIndex && drawTheseRolls[i].BarNumber <= ChartBars.ToIndex)

              I try to understand why it is or not necessary

              Comment


                #22
                Hello frankduc,

                The Rollover indications script saves bar numbers that needs objects rendered on them to the drawTheseRolls list. Then for each saved bar checks to see if that bar is visible. If its visible it draws an object on that bar.

                The example in the help guide loops through all of the plots in the Values collection and draws text for each plot.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #23
                  I came up with something like this ;

                  for(int barIndex = ChartBars.GetBarIdxByX(chartControl, (int)clickPoint.X); barIndex <= ChartBars.ToIndex; barIndex--)
                  {




                  {
                  float chartScaleYValue = chartScale.GetYByValue(foundIndex);
                  float startX = chartControl.GetXByBarIndex(ChartBars, ChartBars.FromIndex);
                  float endX = chartControl.GetXByBarIndex(ChartBars, ChartBars.ToIndex);
                  SharpDX.Vector2 startPoint = new SharpDX.Vector2(startX, chartScaleYValue);
                  SharpDX.Vector2 endPoint = new SharpDX.Vector2(endX, chartScaleYValue);
                  RenderTarget.DrawLine(startPoint, endPoint, rollMarkerBrushDx, RollMarkerStroke.Width, RollMarkerStroke.StrokeStyle);

                  }

                  break;


                  }
                  }

                  i did add in proprieties:

                  [Display(Name = "Rollover marker stroke", Description = "Shows the rollover break on the chart. Set to Transparent to hide.", GroupName = "Parameters", Order = 5)]
                  [NinjaScriptProperty]
                  public Stroke RollMarkerStroke
                  { get; set; }

                  But indicator not showing up on the chart and no vertical line either. Any idea why?

                  thanks
                  Last edited by frankduc; 07-12-2019, 08:13 AM.

                  Comment


                    #24
                    Hello frankduc,

                    The very first thing to check would be if you have any errors in the log tab of your Control Center. If you are hitting a runtime error, the indicator will not be presented on the chart.

                    SharpDX custom rendering is reserved for advanced programmers and you should have a good foundation on C# before attempting to use this code. Throughout your posts, we have seen several issues involving basic programming concepts involving loops and scope. It will be imperative that you will be able to create, test, and learn from the code you are writing in order to use SharpDX properly.

                    While we want to help, our support services will not be able to provide corrections to your code, or will be able to debug the code for you. We also cannot provide programming education services. In order for us to assist, we will need to know your exact issue, with a complete and simplified example. This requires full understanding of the issue on your end.

                    I encourage you to first play around with a modified copy of the SampleCustomRender script and to experiment with some of that code in a new indicator so you can focus on some line drawing behaviors to get more comfortable using SharpDX. Copying code from SampleCustomRender into a new script can give you a point of comparison between the script where you are trying to accomplish new custom rendering and a simplified working script. This would be the best way to troubleshoot issues with your custom rendering code.

                    To move forward, I suggest either taking smaller steps to modify code from the SampleCustomRender to get more familiar with custom rendering or to take a step back and use NinjaTrader's Drawing Tools where possible. You could also consider hiring a NinjaScript Consultant to write custom rendering code for you as another option. If that interests you, please let us know.

                    Please let us know if you have any questions.
                    JimNinjaTrader Customer Service

                    Comment


                      #25
                      Let's try something basic. I have take a look at
                      SampleCustomRender
                      and did some test that end up into crashing NT. I am at 80% of the job done, i need to master graphic object the indicator will be useless otherwise. If i pay someone, assuming i get anyone honest, its gonna cost me 1000$ for an hour job.

                      In
                      SampleDisplaybarsago you can see in top left corner the tile SDBA than the contract (ES 09-19 (6 minutes), 468, True) 468 is a Period i add to my indicator and True is a boolean.

                      Is it possible to add a live variable. For exemple my CMA cumulative moving average result or the result of the variable
                      foundIndex
                      ?

                      I could add it in
                      if (State == State.SetDefaults) and in proprieties at the end like i did for Period and my boolean.

                      Ty

                      Comment


                        #26
                        Hello frankduc,

                        If you are instantiating the indicator in State.DataLoaded, you will have the ability to instantiate the indicator with a precomputed value/variable. Since State.DataLoaded occurs before OnBarUpdate starts processing data, you would not be able to use a calculation from OnBarUpdate. Chart rendering does not happen until the script starts processing realtime data in State.Realtime, so values calculated from OnRender could not be used in State.DataLoaded either.

                        If the goal is to use a variable assigned from OnRender or to use your CMA indicator, this is also possible and would just require if/else logic added to control when you want to reference your variable or the indicator value.

                        The Strategy Builder can be used to generate syntax with class level variables, so this can help to demonstrate how you can use variables in your script.

                        Please let us know if we can be of further assistance.
                        JimNinjaTrader Customer Service

                        Comment


                          #27
                          Just to be clear i want my variable barFibo to appear in SDBA at the top left corner like on the attachment just after 1668, True) By the way i work OnRender.

                          If i use an if statement it will not return 135 it will return false or true?
                          Attached Files

                          Comment


                            #28
                            Hello frankduc,

                            Properties that are listed at the top of the indicator are the indicator's parameters. These would be set by the user and should remain static. I would recommend using Draw.TextFixed to display dynamic values on your chart instead of changing a user input as this value would not update on the chart label in realtime. If you are using SharpDX in OnRender, you would use Draw.TextLayout to draw text.

                            if statements evaluate to true/false and then are used to control the logic flow. For example:

                            Code:
                            if (CONDITION)
                            {
                              // Calculate or Draw for indicator value
                            }
                            else
                            {
                              // Calculate or Draw for variable value
                            }
                            Creating User Defined Inputs - https://ninjatrader.com/support/help...d_input_pa.htm

                            Draw.TextFixed - https://ninjatrader.com/support/help..._textfixed.htm

                            TextLayout - https://ninjatrader.com/support/help...textlayout.htm

                            We look forward to assisting.
                            Last edited by NinjaTrader_Jim; 07-15-2019, 01:24 PM.
                            JimNinjaTrader Customer Service

                            Comment


                              #29
                              I can see in right upper corner sumvolfib but cant see the result number it returns. It should return a number like 135.

                              Draw.TextFixed(this, "sumvolfibo", "sumvolfibo", TextPosition.TopRight);

                              the way i see this you cannot use
                              Draw.TextFixed to input the value of my variable in
                              Draw.TextFixed because you need to fix a position to the value in the chart so you have to use
                              TextLayout to do that.

                              Is there any good exemple i can copy or modify for fast learning in another indicator other than samplecustomrender cause its hard to figure out what to use and what not to use?

                              ty
                              Last edited by frankduc; 07-16-2019, 06:53 AM.

                              Comment


                                #30
                                Hello frankduc,

                                In your example, you are supplying the string "sumvolfibo" instead of the variable sumvolfibo so that is the text you will see on the chart. The Strategy Builder can also be used to generate DrawTextFixed syntax when you supply a variable to it. Text rendering with TextFixed will allow drawing text at a certain quadrant of the chart where SharpDX would not have to be used.

                                It is important to note how resources should be disposed when working with SharpDX. You could check implementations in indicators on our User App Share for further examples, but we would recommend our documentation and the SampleCustomRender example as an educational resource.

                                https://ninjatraderecosystem.com/user-app-share/

                                The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

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

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by vivekniwas, Today, 04:56 PM
                                0 responses
                                6 views
                                0 likes
                                Last Post vivekniwas  
                                Started by dtl-saw, Today, 03:36 PM
                                1 response
                                10 views
                                0 likes
                                Last Post NinjaTrader_ChrisL  
                                Started by williamzz, Today, 02:04 PM
                                2 responses
                                11 views
                                0 likes
                                Last Post williamzz  
                                Started by jtrading82, Today, 01:55 PM
                                3 responses
                                27 views
                                0 likes
                                Last Post NinjaTrader_Tyler  
                                Started by StevenNelson, Today, 01:00 PM
                                4 responses
                                20 views
                                0 likes
                                Last Post StevenNelson  
                                Working...
                                X