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

OnRender Help

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

    #16
    Originally posted by NinjaTrader_Jesse View Post
    Hello omololu,

    If you want to fully customize the bars you can create a BarsType to generate custom bars or a ChartStyle to render the bar data in a custom way. OnRender from an Indicator could be used to draw over the bars but they would still exist as they were built/rendered by the selected bars type and chart style. You could make the chart style use transparent colors for the bars and then use OnRender to draw what you like as well.


    Please let me know if I may be of further assistance.
    Jesse,

    Thanks for your reply ... and surely your further assistance is needed by me.

    Although, my initial interest is an indicator such as the RSIGradient shown in the attached screenshot, I shall appreciate it if you will give some OnRender code snippets or example(s) on both a ChartStyle, BarsType; and also on an indicator (such as the RSIGradient).

    Omololu

    Click image for larger version

Name:	RSIGradient.png
Views:	205
Size:	11.5 KB
ID:	1151546
    Attached Files

    Comment


      #17
      Hello omololu,

      You can refer to the built in bars types and chart styles for working examples of those types of scripts. In the NinjaScript editor you can view their code.

      To learn more about OnRender or creating different types of brushes you can see the SampleCustomRender indicator, that displays a lot of different OnRender concepts. OnRender is the same no matter what type you are using so using any script that uses OnRender will help with learning. A lot of tools use OnRender, for example the drawing tools, ChartStyles, and some indicators.

      If you are using the RSI Color Gradient from the user app share you can also learn from that as the code is available. That specifically uses BarBrush which makes a new color for each bar. The same concept could be used to generate gradient bruhses for OnRender. A Brush will have the ToDXBrush method which converts to a OnRender brush.

      BarBrush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rgbRed,(byte)rgbGreen,(byte)rgbBlue));

      There are some examples of converting a brush to a DXBrush here: https://ninjatrader.com/support/help...ghtsub=dxbrush


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

      Comment


        #18
        Originally posted by NinjaTrader_Jesse View Post
        Hello omololu,

        You can refer to the built in bars types and chart styles for working examples of those types of scripts. In the NinjaScript editor you can view their code.

        To learn more about OnRender or creating different types of brushes you can see the SampleCustomRender indicator, that displays a lot of different OnRender concepts. OnRender is the same no matter what type you are using so using any script that uses OnRender will help with learning. A lot of tools use OnRender, for example the drawing tools, ChartStyles, and some indicators.

        If you are using the RSI Color Gradient from the user app share you can also learn from that as the code is available. That specifically uses BarBrush which makes a new color for each bar. The same concept could be used to generate gradient bruhses for OnRender. A Brush will have the ToDXBrush method which converts to a OnRender brush.

        BarBrush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rgbRed,(byte)rgbGreen,(byte)rgbBlue));

        There are some examples of converting a brush to a DXBrush here: https://ninjatrader.com/support/help...ghtsub=dxbrush


        I look forward to being of further assistance.
        Hi Jesse,

        I have the SampleCustomRender. It shows OnRender applied to Rectangle, Ellipse, Text and Lines but none for Chart Bars. You may wish to direct me to the portions of the codes that I can tweak for Chart Bars. I've also had the RSIColorGradient for some time now, and I understand the codes in it.

        I'll explore the "[B]BarBrush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rgbRed,(byte)rgbGreen,(byte)rgbBlue));" and the examples on DXBrush.

        Thanks and Best Regards.

        Omololu

        Comment


          #19
          Hello omololu,

          The SampleCustomRender is used to learn how to use rendering. You can see the following link which shows how to observe the currently visible bars and reference data from a series: https://ninjatrader.com/support/help...tsub=fromindex

          To convert bar data to x or y values you can use the following methods:




          Please let me know if I may be of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #20
            Originally posted by NinjaTrader_Jesse View Post
            Hello omololu,

            The SampleCustomRender is used to learn how to use rendering. You can see the following link which shows how to observe the currently visible bars and reference data from a series: https://ninjatrader.com/support/help...tsub=fromindex

            To convert bar data to x or y values you can use the following methods:




            Please let me know if I may be of further assistance.
            Jesse,

            Thanks for all the guides ... I'll go through them.

            Omololu

            Comment


              #21
              Originally posted by NinjaTrader_Jesse View Post
              Hello omololu,

              The SampleCustomRender is used to learn how to use rendering. You can see the following link which shows how to observe the currently visible bars and reference data from a series: https://ninjatrader.com/support/help...tsub=fromindex

              To convert bar data to x or y values you can use the following methods:




              Please let me know if I may be of further assistance.
              Hi Jesse,

              I don't seem to be having a breakthrough. I'm trying to learn from the RSIColorGradient indicator with the example code ---> BarBrush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rgbRed,(byte)rgbGreen,(byte)rgbBlue)). The examples at the links you provided don't give explicit and clear examples. Could you please provide code snippets that convert BarBrush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rgbRed,(byte)rgbGreen,(byte)rgbBlue)) to OnRender brush; and also the codes to subsequently use to apply the OnRender command to produce the gradient effects on the chart candles bars

              Regards.

              Omololu

              Comment


                #22
                Hello omololu,

                The examples I had provided are showing specific concepts which relate to what you are asking. If you want to make custom brushes the code you copied would be one way to do that by using RGB values. The SampleCustomRender shows how to create Gradient brushes for sharpDX.

                To make a brush for OnRender you need to call ToDxBrush on the brush variable. Using the concepts from the SampleCustomRender you can see brushes are converted, for example: areaBrushDx = areaBrush.ToDxBrush(RenderTarget);

                To make candles you would need to draw a single rectangle per bar at the X and Y coordinates and then make its width the same size as the candle, If you don't want to draw your own candles you could look at using a ChartStyle instead to just provide one of the existing styles new brushes but retain the logic for creating the candles.

                You could also use the existing indicator that was linked to use BarBrush with the custom color, that also colors the bar in a gradient way. That does not use gradients but creates a gradient by changing the color for each bar toward a gradient goal.


                Please let me know if I may be of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello omololu,

                  The examples I had provided are showing specific concepts which relate to what you are asking. If you want to make custom brushes the code you copied would be one way to do that by using RGB values. The SampleCustomRender shows how to create Gradient brushes for sharpDX.

                  To make a brush for OnRender you need to call ToDxBrush on the brush variable. Using the concepts from the SampleCustomRender you can see brushes are converted, for example: areaBrushDx = areaBrush.ToDxBrush(RenderTarget);

                  To make candles you would need to draw a single rectangle per bar at the X and Y coordinates and then make its width the same size as the candle, If you don't want to draw your own candles you could look at using a ChartStyle instead to just provide one of the existing styles new brushes but retain the logic for creating the candles.

                  You could also use the existing indicator that was linked to use BarBrush with the custom color, that also colors the bar in a gradient way. That does not use gradients but creates a gradient by changing the color for each bar toward a gradient goal.


                  Please let me know if I may be of further assistance.
                  Hi Jesse,

                  Thanks for your reply.

                  1. So, to make a brush for OnRender for the RSIColorGradient BarBrush example I can do the following;

                  BarBrush = new SolidColorBrush(Color.FromArgb((byte)255, (byte)rgbRed,(byte)rgbGreen,(byte)rgbBlue));
                  BarBrushDX = BarBrush.ToDxBrush(RenderTarget);

                  ... I can thereafter use BarBrushDX to render gradients on the candles ... Right ? ... if Right, what are the subsequent example codes that I need to use to render gradients on the candles ?

                  2. Alternatively, if I want to use existing ChartStyle, or make my own candles by drawing a single rectangle per bar at the X and Y coordinates, etc, could you please provide me with example codes for each of these two approaches.

                  Best Regards.

                  Omololu

                  Comment


                    #24
                    Hello omololu,


                    1). yes that would be similar to what the sample shows, brushes have a ToDxBrush method which converts the brush to a sharpdx brush.

                    The BarBrushDX could be used as a brush for any of the rendering items like a rectangle. You can find more information about sharpdx brushes and gradients in the following links.




                    2). you can see any of the existing ChartStyles by using the NinjaScript editor, that would be the best sample to work with as those are already working styles and show the necessary code.

                    Please let me know if I may be of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by NinjaTrader_Jesse View Post
                      Hello omololu,

                      The examples I had provided are showing specific concepts which relate to what you are asking. If you want to make custom brushes the code you copied would be one way to do that by using RGB values. The SampleCustomRender shows how to create Gradient brushes for sharpDX.

                      To make a brush for OnRender you need to call ToDxBrush on the brush variable. Using the concepts from the SampleCustomRender you can see brushes are converted, for example: areaBrushDx = areaBrush.ToDxBrush(RenderTarget);

                      To make candles you would need to draw a single rectangle per bar at the X and Y coordinates and then make its width the same size as the candle, If you don't want to draw your own candles you could look at using a ChartStyle instead to just provide one of the existing styles new brushes but retain the logic for creating the candles.

                      You could also use the existing indicator that was linked to use BarBrush with the custom color, that also colors the bar in a gradient way. That does not use gradients but creates a gradient by changing the color for each bar toward a gradient goal.


                      Please let me know if I may be of further assistance.
                      Hello Jesse,

                      Is possible to use the placement of the rectangle and instead of placing just above on a rectangle use the entire Vertical space at the width of the current bar, and set only it a certain brush color based on a state of a value that was last set in OnBarUpdate.
                      So to do that on each new bar in OnRender, as I do that in an indicator using OnBarUpdate and a value setting BackBrushAll, though there is a max limit of how many bars call the accurate visual value and is plotted then it will choose one of the colors and stop dynamically displaying visual changes.

                      So can simulate in OnRender be done in the same method a new rectangles can be drawn in OnRender to use a variable set earlier in OnBarUpdate, called on a secondary DataSeries, then expand the size vertically of the rectangle to seem like it is say, value -400 to current value and +400 and appear as the entire backbrush is dynamically painted. I assume that works as well. Can you help me to understand if this works to continually update a simulated backbrush color longer than allowed in OnBarUpdate using the BackBrushAll ... method.
                      Last edited by LoganJKTrader; 07-11-2022, 08:10 PM.

                      Comment


                        #26
                        Hello LoganJKTrader,

                        Its a little hard to understand your question, are you asking if OnRender has a brush limit like BackBrush?
                        JesseNinjaTrader Customer Service

                        Comment


                          #27
                          Originally posted by NinjaTrader_Jesse View Post
                          Hello LoganJKTrader,

                          Its a little hard to understand your question, are you asking if OnRender has a brush limit like BackBrush?
                          Is it possible to create an endless number of objects using OnRender or is there limitations as there is a max number of calls to BackBrushAll in OnBarUpdate.
                          If a limit is in place is there a work around to the limitations ie. creating a box stopping at the upper limits /visable area on a chart screen both high and low to limit the amount of memory in use creating areas/regions to up and to low on screen starting at the Open or close of each bar. Again, if there is ability to do that in a way to allow Higher number of bars that are visually updated using these methods, than using BackBrushAll, can you tell me how to calcualte an axis point of a chart high and low visable area. (horizontal axis)

                          Sorry these a lot of questions. Short answer is yes, as there is a limit using BackBrush All I can manually work around and not have to refresh screen but an automated method to update continually or your help is appreciated.
                          Last edited by LoganJKTrader; 07-14-2022, 03:23 PM.

                          Comment


                            #28
                            Hello LoganJKTrader,

                            You would control what logic goes in OnRender but you wouldn't draw endless objects from there. On Render is intended to loop over the visible bars for efficiency so you would just render the underlying data for that period of visible time. You can read about OnRender here: https://ninjatrader.com/support/help...htsub=onrender

                            If you have further questions on this topic please open a new thread so we can close this thread out as this does not relate to the original post question.

                            JesseNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by mgco4you, Today, 09:46 PM
                            1 response
                            3 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by wzgy0920, Today, 09:53 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post wzgy0920  
                            Started by Rapine Heihei, Today, 08:19 PM
                            1 response
                            8 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by Rapine Heihei, Today, 08:25 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post Rapine Heihei  
                            Started by f.saeidi, Today, 08:01 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Working...
                            X