Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to add a specific parameter to Strategy

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

    How to add a specific parameter to Strategy

    Hi!
    I have a custom indicator, that doesn't seem to display certain parameters when I call it in the Strategy Builder.
    Forgive me since I'm not a C# developer, I only code HTML and CSS.

    When a Pivot Low(pivoth), or High (pivotl), is printed on the indicator, a triangle is drawn with text, I would like to be able to use that in a strategy, so that if a Pivot Low/High is printed, then do this (Go long, for example).
    I was able to get the "length" as an integer (range) to display in Strategy Builder, but not Pivot.... I'm guessing this would be a boolean? So, in Strat Builder I could use it as, if pivoth = true, then do this.

    I have highlighted the areas I think are important in bold for your convenience.
    I've been banging my head against the wall for a few days, because I'm not a C# coder.

    Hope someone can help!
    Thanks in advance!

    Code:
    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class RSIPlus: Indicator
    {
    private Series<double> max;
    private Series<double> max_rsi;
    private Series<double> min;
    private Series<double> min_rsi;
    private Series<double> src;
    private Series<double> rsiplus;
    
    private Series<bool> divbear;
    private Series<bool> divbull;
    [B]private Series<bool> pivoth;
    private Series<bool> pivotl;[/B]
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"RSIPlus";
    Name = "RSIPlus";
    Calculate = Calculate.OnBarClose;
    IsSuspendedWhileInactive = true;
    DrawOnPricePanel = false;
    IsOverlay = false;
    
    length = 14;
    [B]piv = true;[/B]
    
    [B]PivotColor = Brushes.Blue;[/B]
    BullColor = Brushes.Green;
    BearColor = Brushes.Red;
    
    // CODE REDACTED
    
    [B]pivoth[0] = false;
    pivotl[0] = false;[/B]
    divbear[0] = false;
    divbull[0] = false;
    
    // CODE REDACTED
    
    pivoth[0] = (Math.Abs(max_rsi[0] - max_rsi[2]) < 0.000001) && (Math.Abs(max_rsi[2] - max_rsi[3]) > 0.00001) && CurrentBar > barsBegin;
    pivotl[0] = (Math.Abs(min_rsi[0] - min_rsi[2]) < 0.000001) && (Math.Abs(min_rsi[2] - min_rsi[3]) > 0.00001) && CurrentBar > barsBegin;
    
    // CODE REDACTED
    
    [B]if (piv)
    {[/B]
    [B]if (pivoth[0])
    {
    Draw.Text(this, "tag" + tagCounter++, true, "Pivot", 2, max_rsi[0] + 1, offset, PivotColor, new SimpleFont("Time new roman", 10), TextAlignment.Center, nullColor, PivotColor, 0);
    //Draw.Triangle(this, "tag" + tagCounter++, true,3, max_rsi[0] - 3, 2, max_rsi[0] - 1, 1, max_rsi[0] - 3, PivotColor, PivotColor, 1000);
    Draw.TriangleDown(this, "tag" + tagCounter++, true, 2, max_rsi[0] + 1, PivotColor);
    }
    
    if (pivotl[0])
    {
    Draw.Text(this, "tag" + tagCounter++, true, "Pivot", 2, min_rsi[0] - 1, -offset, PivotColor, new SimpleFont("Time new roman", 10), TextAlignment.Center, nullColor, PivotColor, 0);
    //Draw.Triangle(this, "tag" + tagCounter++, true,3, min_rsi[0] + 3, 2, min_rsi[0] + 1, 1, min_rsi[0] + 3, PivotColor, PivotColor, 100);
    Draw.TriangleUp(this, "tag" + tagCounter++, true, 2, min_rsi[0] - 1, PivotColor);[/B]
    
    }
    
    // CODE REDACTED
    
    #region Properties
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> Default
    {
    get { return Values[0]; }
    }
    
    
    [Range(1, int.MaxValue), NinjaScriptProperty]
    [Display(ResourceType = typeof(Custom.Resource), Name = "length", GroupName = "NinjaScriptParameters", Order = 0)]
    public int length
    { get; set; }
    
    
    [B][Display(Name = "piv", GroupName = "NinjaScriptParameters", Order = 4)]
    public bool piv
    { get; set; }[/B]

    #2
    NT8 user defined parameters :
    https://ninjatrader.com/support/help...d_input_pa.htm

    Example:1

    [NinjaScriptProperty]
    [Display(Name = "Risk Multiplier", GroupName = "Entry Menu", Order = 0)]
    public double RiskMultiplier { get; set; }


    Example:2
    [NinjaScriptProperty]
    [Display(Name = "Count", GroupName = "Entry Menu", Order = 1)]
    public bool Count { get; set; }
    Last edited by Emma1; 08-16-2020, 09:08 AM.

    Comment


      #3
      Thanks for your quick reply. Maybe I'm missing something, but when I add pivoth, since a definition already exists, I'm getting the error "already contains a definition error". This is how I added it:

      Code:
      if (piv)
      {
      if (pivoth[0])
      {
      Draw.Text(this, "tag" + tagCounter++, true, "Pivot", 2, max_rsi[0] + 1, offset, PivotColor, new SimpleFont("Time new roman", 10), TextAlignment.Center, nullColor, PivotColor, 0);
      //Draw.Triangle(this, "tag" + tagCounter++, true,3, max_rsi[0] - 3, 2, max_rsi[0] - 1, 1, max_rsi[0] - 3, PivotColor, PivotColor, 1000);
      Draw.TriangleDown(this, "tag" + tagCounter++, true, 2, max_rsi[0] + 1, PivotColor);
      }
      
      if (pivotl[0])
      {
      Draw.Text(this, "tag" + tagCounter++, true, "Pivot", 2, min_rsi[0] - 1, -offset, PivotColor, new SimpleFont("Time new roman", 10), TextAlignment.Center, nullColor, PivotColor, 0);
      //Draw.Triangle(this, "tag" + tagCounter++, true,3, min_rsi[0] + 3, 2, min_rsi[0] + 1, 1, min_rsi[0] + 3, PivotColor, PivotColor, 100);
      Draw.TriangleUp(this, "tag" + tagCounter++, true, 2, min_rsi[0] - 1, PivotColor);
      }
      }
      }
      
      #region Properties
      
      [Browsable(false)]
      [XmlIgnore()]
      public Series<double> Default
      {
      get { return Values[0]; }
      }
      
      [Range(1, int.MaxValue), NinjaScriptProperty]
      [Display(ResourceType = typeof(Custom.Resource), Name = "length", GroupName = "NinjaScriptParameters", Order = 0)]
      public int length
      { get; set; }
      
      [B][NinjaScriptProperty]
      [Display(Name = "PivotHigh", GroupName = "Pivots", Order = 1)]
      public bool pivoth { get; set; }[/B]
      
      [Display(Name = "piv", GroupName = "NinjaScriptParameters", Order = 2)]
      public bool piv
      { get; set; }

      Comment


        #4
        Could someone guide me with this?

        Comment


          #5
          Are you using NT7 or NT8? which of two.
          Have you used Strategy Builder Before?https://ninjatrader.com/support/help...gy_builder.htm. Builder Screen. for a start then further modify the code later.

          Comment


            #6
            NT8. Yes, I use it Strat Builder often. The problem is that I would like the "pivoth" or "pivotl" to appear in the indicator's parameters or properties field within Strategy Builder parameters when I select the indicator. Please see attachment...

            Click image for larger version

Name:	Annotation 2020-08-16 190320.png
Views:	722
Size:	24.1 KB
ID:	1114098

            Comment


              #7
              It has to be declared in the inputs and generate the properties..Then when selecting it ,The User required name will appear instead of the fixed number. https://www.youtube.com/watch?v=HCyt90GAs9k In the about midway is the adjustmement.

              Comment


                #8
                Firstly, I appreciate you taking the time to go over this. Perhaps I'm explaining it incorrectly.... in my initial post I was referring to that the problem lays within the custom indicator, that doesn't express the parameters when I call it in the Strategy Builder. I believe this is within the coding of the indicator, not a problem with strategy.

                When a Pivot Low(pivoth), or High (pivotl), is printed on the indicator in a chart, a triangle is drawn with text, I would like to be able to use that in a strategy, so that if a Pivot Low/High is printed, then do this (Go long, for example).
                For the Pivots that print.... I'm guessing this would be a boolean?.... So, in Strat Builder I could use it as, if pivoth = true, then do this.

                Please refer to the code I pasted in the initial post.

                Thanks in advance !!

                Comment


                  #9
                  you are requesting parameter. ok for 'bool'. Do you want both Pivotlow (pivoth) and triangle printed together on chart? I am sure you know that bool is for a yes or no type of condition. OR on ,off switch.
                  Last edited by Emma1; 08-16-2020, 06:38 PM.

                  Comment


                    #10
                    They are already printing on chart. That works fine. I only want to be able to call it in a strategy, so when a triangle pivoth or pivotl prints, I can go long or short.

                    Comment


                      #11
                      when you have to call it , you only need a word or two, the actual file is zipped in same folder from where you call into the strategy.

                      Comment


                        #12
                        Introductory info
                        https://www.youtube.com/watch?v=H7aD...We0Nf&index=14Programming Concepts in Educational Resources.

                        https://ninjatrader.com/support/helpGuides/nt8/en-us/ and https://ninjatrader.com/support/help..._reference.htm , the topics on the left. But the more knowledge you have enable you create advanced topics which are not used daily..
                        Last edited by Emma1; 08-18-2020, 06:31 AM.

                        Comment


                          #13
                          Hello jpeep,

                          It looks like you need the NinjaScript Property attribute. (The Strategy Builder would add this for you if you use the Strategy Builder to generate the code and then copy this generated to the other script as demonstrated in the NinjaScript Editor 401 training video)

                          Below is a link to the help guide.


                          You will not be able to declare the same variable name twice in the same scope.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            Originally posted by jpeep View Post
                            NT8. Yes, I use it Strat Builder often. The problem is that I would like the "pivoth" or "pivotl" to appear in the indicator's parameters or properties field within Strategy Builder parameters when I select the indicator. Please see attachment...

                            Click image for larger version

Name:	Annotation 2020-08-16 190320.png
Views:	722
Size:	24.1 KB
ID:	1114098
                            I apologize for the necromancy of this old thread, but I am having the same dilemma.

                            jpeep never resolved this or at least didn't share the outcome.

                            I think jpeep just didn't explain that he wanted to expose other variables of the same indicator for use by strategy builder.

                            Let say that MACD has three variables that you could get/set in properties, but you could only access two of them when it comes time to use those plots in strategy builder.

                            It seems that it should be a simple thing to have it be selectable.

                            Anyone care to make me look as simple as I genuinely am?

                            Comment


                              #15
                              Hello notenufftime,

                              To make more inputs you would need to define the variable as public in the scripts code. Public variables show up as user inputs.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              54 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              131 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              73 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              44 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              49 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X