Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Modding Existing Indicator?

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

    #16
    Hi Brandon,

    This is a piece of code to show you what I'm what I'm doing wrong trying to apply the font script example.

    If you could tell me what I'm doing wrong, that would be wonderful. Thanks


    Code:
    public class MyDistance : Indicator
    {
    private NinjaTrader.Gui.Tools.SimpleFont myFont;
    
    //class level variable
    private double MyDifferenceGreen;
    private double MyDifferenceRed;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Indicator here.";
    Name = "MyDistance";
    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;
    }
    else if (State == State.Configure)
    {
    myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 30, Bold = true };
    }
    }
    
    protected override void OnBarUpdate()
    {
    
    //assign MyDifference
    int MyDifferenceGreen = (int)((Close[0] - Open[0]) / TickSize);
    int MyDifferenceRed = (int)((Open[0] - Close[0]) / TickSize);
    
    //red ticks
    if (Open[0] >= Close[0])
    Draw.Text(this, "distance" + CurrentBar, false, MyDifferenceRed.ToString(), 0, High[0] + 15 * TickSize, Brushes.Red, myFont, TextAlignment.Center, null, null, 1);
    
    //green ticks
    if (Close[0] > Open[0])
    Draw.Text(this, "distance" + CurrentBar, false, MyDifferenceGreen.ToString(), 0, Low[0] - 15 * TickSize, Brushes.ForestGreen, myFont, TextAlignment.Center, null, null, 1);
    
    } }
    
    }

    Comment


      #17
      I worked out what I was doing wrong.

      Code:
      Draw.Text(this, "distance" + CurrentBar, false, myVolume.ToString(), 0, High[0] + 1 * TickSize, [B]5, [/B]Brushes.ForestGreen, myFont, TextAlignment.Center, null, null, 1);
      I hadn't added that number in the middle. Thanks for your help!

      By the way, what does bool is autoscale mean? And are null, null for opacity and how are they set?

      Thanks again.

      Comment


        #18
        Hello Bob-Habanai,

        Glad you have it working. For setting opacity and area (text rectangle) to an empty/zero/transparent value, just use the example I provided above. That is, "Brushes.Transparent, Brushes.Transparent, 0);"

        The auto-scale determines whether the Ninja Trader chart renderer will expand the vertical scale to include your Draw item on the chart view. I recommended setting this to true in most cases.

        Hope that helps!
        Matt

        Comment


          #19
          Hello Bob-Habanai,

          Thanks for your note.

          I am happy to hear you got your code working.

          StealthM93 is correct. The 'bool isAutoScale' parameter determines if the draw object will be included in the y-axis scale.

          Some information about IsAutoScale could be found on this help guide page: https://ninjatrader.com/support/help...sautoscale.htm

          The definition of each argument could be found in the Draw.Text() help guide page linked below.

          Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm

          The outlineBrush and areaBrush arguments could be set to Brushes.Transparent if you do not want them to be visible as StealthM93 said.

          Let me know if I may assist further.
          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

          Comment


            #20
            Any advice on how to put settings into the Indicator Menu?

            I've seen some Indicators put a value below the beginning like this:

            Code:
            protected override void OnStateChange()
            {
            if (State == State.SetDefaults)
            {
            Description = @"Example";
            Name = "Example";
            Calculate = Calculate.OnBarClose;
            IsOverlay = true;
            DisplayInDataBox = true;
            DrawOnPricePanel = true;
            PaintPriceMarkers = true;
            
            IsSuspendedWhileInactive = false;
            
            
            bull_Color = Brushes.PaleGreen;
            But if I put
            Code:
            bull_Color = Brushes.PaleGreen;
            directly below
            Code:
             IsSuspendedWhileInactive = false;
            I get this error code.

            I have a number of settings I want to put into the Indicator Menu. Colours, a changable text word, Font name, etc.
            Any advice would be appreciated, thanks again.

            Click image for larger version

Name:	Screenshot 2022-08-31 112144.png
Views:	136
Size:	5.4 KB
ID:	1213822

            Comment


              #21
              Hi Bob-Habanai,

              In the Ninja Script Editor, there's a tab to the right called, NinjaScript Explorer. In there, you'll find an Indicators folder. Open up several of the default basic indicators like SMA, EMA, and perhaps others. Those will provide examples of what you're trying to do. In short, you're looking to add Properties to the source file. In the examples, they're near the bottom of the editable code.
              Here's more info: https://ninjatrader.com/support/help...attributes.htm

              Hope that helps!
              Matt

              Comment


                #22
                Hello Bob-Habanai,

                Thanks for your note.

                To get an idea of how to create user-defined input properties, you could use the Strategy Builder.

                Open a New > Strategy Builder window, navigate to the Inputs and Variables screen, create a few user-defined inputs, and click the 'View code' button to see the generated syntax.

                You could then compare the generated syntax to the syntax in your strategy to see where differences might be.

                See the help guide pages linked below for more information.

                Strategy Builder Inputs and Variables Screen: https://ninjatrader.com/support/help...ariablesScreen
                NinjaScriptProperty Attribute: https://ninjatrader.com/support/help...yattribute.htm

                Let me know if I may assist further.
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #23
                  Thank you both for your replies.

                  Inside the strategy builder in the inputs and variables it has:
                  bool, double, string, int and time.

                  At the moment, I only have a vague idea as to what those mean.
                  Bool seems to be something that meets a threshold, while double is an accurate value.

                  Within the total of 13 arguments of:

                  Code:
                  [I]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)[/I]
                  or

                  Code:
                  [I]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)[/I]
                  What are
                  Code:
                   [I]Brush textBrush, SimpleFont font, TextAlignment alignment, Brush outlineBrush, Brush areaBrush[/I]
                  considered?
                  Which one of the five (bool, double, string, int and time), do they count as? In order to make them selectable in the Indicator menu?

                  Thanks!

                  Comment


                    #24
                    Hello Bob-Habanai,

                    Thanks for your note.

                    textBrush, outlineBrush, and areaBrush are all Brush object, not a bool, double, string, int, or time object.

                    See the attached example script demonstrating how to create a user-defined Brush object.

                    SimpleFont font is referring to a SimpleFont object and not a bool, double, string, int, or time object. You would need to manually define the SimpleFont object in your script. A SimpleFont object requires you to pass in a string familyName and an int size argument. You could consider creating a user-defined string input to define the familyName of the font and you could create a user-defined int input, then use those variables when creating your SimpleFont.

                    For example, you could create a user-defined int input to use for the int size argument and pass that variable in for the int size argument when creating a SimpleFont.

                    TextAlignment alignment is an enum used to define how the text will be aligned. The available options to use for this argument are TextAlignment.Center, TextAlignment.Left, TextAlignment.Right, and TextAlignment.Justify. The options for TextAlignment could be seen in the Draw.Text() help guide page linked below.

                    See this publicly available MSDN page for more information about TextAlignment: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

                    Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm

                    Let me know if I may assist further.
                    Attached Files
                    Last edited by NinjaTrader_BrandonH; 09-01-2022, 08:12 AM.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #25
                      Thank you both for your help.

                      I have an indicator menu question.
                      I successfully put an int into my indicator menu for rounding a insanely long number.

                      In the Draw.Text(this.... at the string I wrote:
                      Code:
                      Math.Round(MyString, DecimalPlaces).ToString()
                      But when I load the indicator, Ninja gives me this error msg.
                      If I select any other number, it works, but I can't write 0.
                      Is there another way to get around this?

                      Click image for larger version

Name:	Screenshot 2022-09-06 222407.png
Views:	158
Size:	9.7 KB
ID:	1214466

                      Click image for larger version

Name:	Screenshot 2022-09-06 222459.png
Views:	120
Size:	10.1 KB
ID:	1214467

                      Again, any number above 0 is allowed, but is there another way to get 0 into an indicator menu?

                      Thanks again!

                      Comment


                        #26
                        Hello,

                        This syntax will permit a 0 (zero) for a Property.

                        [NinjaScriptProperty]
                        [Range(0, int.MaxValue)]
                        [Display(Name = "Decimal Places", Description = "Determines the number of decimal places for rounding.", Order = 1, GroupName = "My Parameters")]
                        public int DecimalPlaces { get; set; }


                        If the only reason you're rounding a number is for display purposes, then may I recommend this approach:
                        double MyDoubleVar = 3.1415926;
                        Print ("The value is " + MyDoubleVar.ToString("0.00"));


                        Just let the formatting parameter of the ToString() method do the work. If you're going to use the formatted value more than once, then you might want to do this:
                        string MyDisplayValue = MyDoubleVar.ToString("0.00");

                        Then you can use this string variable in the Draw.Text call and other places as you need.

                        Hope that helps!
                        Matt

                        Comment


                          #27
                          Hello Bob-Habanai,

                          Thanks for your note.

                          StealthM93 is correct. You would need to define the Range to have a minimum value of 0 for that NinjaScriptProperty.

                          This could be accomplished using the syntax StealthM93 shared in post #26.

                          Let us know if we may assist further

                          <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                          Comment


                            #28
                            Thank you both for your replies.

                            I'm guessing that the reason you told me to format it that way is that it'll be less CPU intensive, if it's for display purposes only?

                            Thanks again.

                            Comment


                              #29
                              Update,

                              By simply changing one digit, I got rid of that error.

                              Code:
                              #region Properties
                              [NinjaScriptProperty]
                              [Range([B]0[/B]
                              So I appreciate that, but when I tried to change the rest of the code as you said above, I missed something.
                              I'll send a sample indicator later so you can see what I'm doing wrong, but thanks for the help.
                              Last edited by Bob-Habanai; 09-06-2022, 09:37 PM.

                              Comment


                                #30
                                I have a question, regarding using if,
                                how do you say between?

                                I know < > == >= <=, but how do you say < 4, but > 1?

                                Thanks

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                648 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                370 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                109 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                573 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                576 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X