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

Data above or below bar using volumetric bars data order flow chart of NT8.

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

    #46
    My indicator has advanced a lot thanks to your help Brandon.

    Just three more questions. How do you round numbers up? e.g.

    myVolume = VOL()[1]/VOL()[0];

    What if I don't want decimals to display, just rounded up to 1s?

    How do you change the font size?

    And if == is the ninja way of saying equals, what is the way of writing ≠ in ninja?

    I've done a lot of work not written here in the forum, but it's almost done thanks to your help!
    Last edited by Bob-Habanai; 08-25-2022, 06:09 AM. Reason: Less wordy

    Comment


      #47
      Hello Bob-Habanai,

      Thanks for your notes.

      Rounding numbers would fall into C# education. Note that in the Support department at NinjaTrader we cannot provide C# education.

      You could do a quick Google search for something like 'how to round numbers C#' to find publicly available information about how to round numbers when using the C# programming language.


      To change the font size of text drawn using Draw.Text(), you would need to create a SimpleFont variable and use the Draw.Text() syntax that allows you to specify a SimpleFont parameter.

      The syntax could be seen in the Draw.Text() help guide page and also seen below.
      Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

      See this help guide page for more information about SimpleFont and sample code: https://ninjatrader.com/support/help...font_class.htm

      See this help guide page for more information about Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm


      To compare if one value is not equal to another value, you would use !=. To compare if one value is equal to another value, you would use ==.

      For example:

      Close[0] != Open[0]
      Close[0] == Open[0]



      Let me know if I may assist you further.
      Brandon H.NinjaTrader Customer Service

      Comment


        #48
        Hi Brandon, thanks again for all that.
        I appreciate you can't speak to writing C# itself,
        but in the Ninja script is there a specific place that's allowed to insert round() ​​​​​​?



        Comment


          #49
          Hello Bob-Habanai,

          Thanks for your note.

          If you are referring to using the C# Math.Round method, this could be used within the OnBarUpdate(), OnOrderUpdate(), or OnExecutionUpdate() methods.

          Let me know if I may assist further.
          Brandon H.NinjaTrader Customer Service

          Comment


            #50
            Hi Brandon,

            Two questions.

            Is it possible to pixel size, instead of:
            Code:
            High[0] + 5 * TickSize
            How would that code look?

            I tried the below code, and many other attempts and so far I haven't been able to get the font working.

            Thanks again

            Code:
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Enter the description for your new custom Indicator here.";
            Name = "DrawVolAboveUpBar";
            Calculate = Calculate.OnEachTick;
            IsOverlay = true;
            DisplayInDataBox = true;
            DrawOnPricePanel = true;
            DrawHorizontalGridLines = true;
            DrawVerticalGridLines = true;
            PaintPriceMarkers = true;
            ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
            //Disable this property if your indicator requires custom values that cumulate with each new market data event.
            //See Help Guide for additional information.
            IsSuspendedWhileInactive = true;
            NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 50, Bold = true };
            }
            else if (State == State.Configure)
            {
            }
            }
            
            protected override void OnBarUpdate()
            {
            //assign the VOL[0] indicator value to the double variable
            myVolume = VOL()[0];
            
            //check for up bar and use Draw.Text() to draw variable value on chart
            if (Close[0] > Open[0])
            Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, High[0] + 5 * TickSize, Brushes.Red, myFont);
            
            //check for download bar and use Draw.Text() to draw variable value on chart
            if (Open[0] > Close[0])
            Draw.Text(this, "vol up bar" + CurrentBar, myVolume.ToString(), 0, Low[0] - 5 * TickSize, Brushes.ForestGreen, myFont);

            Comment


              #51
              Hello Bob-Habanai,

              Thanks for your note.

              You would first need to create a SimpleFont variable. Then, you would define that SimpleFont variable and use the variable for the SimpleFont argument when calling the Draw.Text() method.

              See the attached sample script demonstrating the use of SimpleFont.

              If you would like to draw text to a specific pixel location, you would need to use SharpDX to custom render the text to that specifically calculated location on the chart.

              RenderTarget.DrawText() could be used to custom render text onto a chart. Note that this is considered an advanced programming concept.

              Please thoroughly review this help guide page for information about Using SharpDX to custom render objects on a chart: https://ninjatrader.com/support/help..._rendering.htm

              And, see this help guide page for information about RenderTarget.DrawText: https://ninjatrader.com/support/help...t_drawtext.htm

              We also have a SampleCustomRender indicator that comes default with NinjaTrader that you could reference also. To view the script, open a New > NinjaScript Editor window, open the Indicators folder, and double-click on the SampleCustomRender file.

              Let me know if I may assist further.
              Attached Files
              Last edited by NinjaTrader_BrandonH; 08-29-2022, 08:03 AM.
              Brandon H.NinjaTrader Customer Service

              Comment


                #52
                Hi Brandon,

                I tried following the example script you kindly provided, but this is what resulted...


                Click image for larger version

Name:	Screenshot 2022-08-30 211532.png
Views:	115
Size:	27.5 KB
ID:	1213700

                Comment


                  #53
                  Hello Bob-Habanai,

                  Thanks for your note.

                  This error indicates that you are not using the correct number of arguments when calling your Draw method.

                  How are your calling the Draw.Text() method in your script?

                  You would need to ensure that you are passing in the correct number of arguments when calling the Draw method.

                  You could compare your syntax to the syntax listed in the help guide to see where there might be an issue.

                  The Draw.Text() method that allows you to specify a SimpleFont can be seen in this help guide page and attached below: https://ninjatrader.com/support/help.../draw_text.htm

                  Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, int barsAgo, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

                  or

                  Draw.Text(NinjaScriptBase owner, string tag, bool isAutoScale, string text, DateTime time, double y, int yPixelOffset, Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush, int areaOpacity)

                  Note that each syntax option contains a total of 13 arguments. This means that you would need to ensure to pass in 13 arguments when calling your Draw.Text method.

                  Let me know if I may assist further.
                  Brandon H.NinjaTrader Customer Service

                  Comment


                    #54
                    Sorry I didn't reply earlier Brandon. I must have been reading late at night. I found a solution in the end that didn't involve SharpDX as like you said,
                    it's an advanced programming concept, but I always appreciate your help!

                    Comment


                      #55
                      Another question,

                      I appreciate all the help with rounding, but how do you round down? i.e. A string is going to divide 7 / 2,
                      and I want it to display 3?

                      Thanks again.

                      Comment


                        #56
                        Hello Bob-Habanai,

                        Thanks for your note.

                        Rounding would require the use of C# methods, not NinjaScript-specific methods, and would go beyond the level of support we provide.

                        To find information about how to round down using C# you could do a Google search for something like 'rounding down C#'. When doing a quick search for this, we can see an example from StackOverflow about how to round down in C#.

                        I have attached the publicly available link to this search result for you to view: https://stackoverflow.com/questions/...earest-integer

                        For further information you would need to do research about rounding down using C#.

                        Please let me know if you have further NinjaScript-specific questions.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #57
                          Thanks Brandon!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by dward123, 01-02-2024, 09:59 PM
                          4 responses
                          174 views
                          0 likes
                          Last Post Lancer
                          by Lancer
                           
                          Started by ETFVoyageur, Today, 04:00 PM
                          2 responses
                          19 views
                          0 likes
                          Last Post ETFVoyageur  
                          Started by AaronKTradingForum, Today, 03:44 PM
                          1 response
                          13 views
                          0 likes
                          Last Post AaronKTradingForum  
                          Started by Felix Reichert, 04-26-2024, 02:12 PM
                          11 responses
                          80 views
                          0 likes
                          Last Post Felix Reichert  
                          Started by junkone, 04-28-2024, 02:19 PM
                          7 responses
                          84 views
                          1 like
                          Last Post junkone
                          by junkone
                           
                          Working...
                          X