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

indicator proprieties

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

    indicator proprieties

    In my indicator i use a <, if i change it for > it will modified the result of the calculation.
    Is it possible to add a check box in the indicator proprieties of my indicator so i dont have to get into the ninjascript editor to change the sign to compile?

    TY

    #2
    Hello frankduc,

    Thanks for your post.

    Yes, you can create a public bool (or other variable) that you can use to change behavior within the script.
    The bool would choose between the two sets of calculations (one with < and the other with >).

    if (myBool)
    {
    // this path/calculation if myBool is true
    }
    else
    // this path/calculation if myBool is false
    }

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      If i do this there's nothing in the proprieties indicator like mybool

      bool myBool = true;

      if (myBool)
      {
      if(closePrice > cma);
      }
      else
      {
      if(closePrice < cma);
      }

      Comment


        #4
        Hello frankduc,

        Thanks for your reply.

        You would need to create a Public bool for the input. You can name the bool as you wish.

        If I may suggest, an easier path here is to use the Ninjascript wizard process and use the indicator wizard (accessed by the "+" in the Ninjascript editor to create an indicator (for keep example source code) and through that process you can create inputs of types bool, int, double, string and brush (and I suggest one of each) and then create through that process one plot and one line and when you click finish the wizard will create all of the structures for the inputs, plot and line and then you can copy/use these as needed in your code. Here is a reference to help: https://ninjatrader.com/support/help...?ns_wizard.htm

        Here is an example of a public bool input as found in #region Properties:

        [NinjaScriptProperty]
        [Display(Name="MyBoolInput", Order=1, GroupName="Parameters")]
        public bool MyBoolInput
        { get; set; }


        In State.SetDefaults, you would need to set the default state like: MyBoolInput = true;
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I did what you said. Gave the bool the name Reverse. It created
          bool Reverse = true; in the new indicator in
          if (State == State.SetDefaults)
          Created also 3 type of properties one for the indicator
          : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
          , one for
          MarketAnalyzerColumn : MarketAnalyzerColumnBase
          and the last for Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase,.

          Do i need the last 2. I mean i only need it for the indicator so i dropped the last 2.

          When compile it says Reverse do not exist in the context in my copy/paste indicator. Does it have to do with the 2 last properties i dropped? Unless Reverse need to be define. Like bool Reverse = ??? but is that part going above Reverse = true or below?

          Comment


            #6
            Hello frankduc,

            Thanks for your reply.

            Based on your reply I suspect that you went into the section that says, "#region NinjaScript generated code. Neither change nor remove." and would advise to never do anything in this area.

            I recommend that you delete that script and start over as I have no idea what the consequences are of the deleting action.

            All you need is the example I provided for your bool, the other information was an attempt to provide you with source code you could use but I did not think you would do anything in the region that advises neither change nor remove as this is not advised.

            In State.SetDefaults, you would need to set the default state like: MyBoolInput = true;

            The following code would be outside of OnBarUpdate but would be within the public class

            .[NinjaScriptProperty]
            [Display(Name="MyBoolInput", Order=1, GroupName="Parameters")]
            public bool MyBoolInput
            { get; set; }




            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Simply put:

              Reverse = true;

              if (Reverse)
              {
              if(closePrice > cma);
              }
              else
              {
              if(closePrice < cma);
              }


              #region Properties
              [NinjaScriptProperty]
              [Display(Name="Reverse", Order=1, GroupName="Parameters")]
              public bool Reverse
              { get; set; }
              #endregion


              It looks like its returning the same result in one case or the other. Can you confirm that is what you told me.
              Last edited by frankduc; 06-17-2019, 09:33 AM.

              Comment


                #8
                Hello frankduc,

                Thanks for your reply.

                You have terminated both if statements with a ";" so I don't see how they perform any action.

                The use of the bool is correct assuming you are saying that Reverse = true; is done in state.SetDefault and not directly ahead of the if statements.
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  The problem comes from the fact that it was already an if statement before making it a bool. If i remove the ";" ill get an error.

                  Before:

                  if(closePrice > cma)
                  {

                  counter++;

                  sumOfVolumesx += Bars.GetVolume(barIndex);
                  }


                  After:

                  if (Reverse)
                  {
                  if(closePrice > cma);
                  }
                  else
                  {
                  if(closePrice < cma);
                  }

                  {

                  counter++;

                  sumOfVolumesx += Bars.GetVolume(barIndex);
                  }



                  now i modified for :

                  if (Reverse)
                  {
                  if(closePrice > cma)
                  {

                  counter++;

                  sumOfVolumesx += Bars.GetVolume(barIndex);
                  }

                  }
                  else
                  {
                  if(closePrice < cma)

                  {

                  counter++;

                  sumOfVolumesx += Bars.GetVolume(barIndex);
                  }

                  }


                  looks better now
                  Last edited by frankduc; 06-17-2019, 10:05 AM.

                  Comment


                    #10
                    Hello Frankduc,

                    Thanks for your reply.

                    If I understand correctly, based on your comment of "looks better now", the issue is resolved.
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      I am having an error for a second bool.

                      it says something like bool dont have a definition for Getvalueat?
                      what does it mean?

                      ty

                      Last edited by frankduc; 06-19-2019, 07:09 AM.

                      Comment


                        #12
                        Hello frankduc,

                        Thanks for your reply.

                        In the code you have posted, you are defining fibo as a "local" variable used within the High { } context so if you are using fibo elsewhere then it would advise it does not exist.

                        In general, it is a better idea to define your variables at the class level so that you don't have to define them locally unless you intend to use them within that { } local context.

                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          sorry i solve that problem and got another one but the message was delete before you answer.
                          I am having an error for a second bool.
                          it says something like bool dont have a definition for Getvalueat?

                          is also link to "local" variable?




                          the problem is a got 2 fibo

                          double lowestclose = Low.GetValueAt(ChartBars.GetBarIdxByX(chartControl , cursorPointX));
                          double highestclose = High.GetValueAt(ChartBars.GetBarIdxByX(chartContro l, cursorPointX));


                          double fibo = ((Close.GetValueAt(CurrentBar) - lowestclose)) / (cmaave - lowestclose);

                          if(High)
                          {
                          fibo = ((Close.GetValueAt(CurrentBar) - lowestclose)) / (cmaave - lowestclose);
                          }
                          else
                          {
                          fibo = ((Close.GetValueAt(CurrentBar) - highestclose)) / (cmaave - highestclose);
                          }

                          Seems i cant switch to highestclose without creating a new fibo1 and it will affect where i used fibo elsewhere.
                          the only solution seems to create another indicator with highestclose instead.

                          ty
                          Last edited by frankduc; 06-19-2019, 08:23 AM.

                          Comment


                            #14
                            Hello frankduc,

                            Thanks for your reply.

                            C# syntax is capitalization sensitive, GetValueAt and Getvalueat are two different things.



                            Paul H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Radano, 06-10-2021, 01:40 AM
                            19 responses
                            606 views
                            0 likes
                            Last Post Radano
                            by Radano
                             
                            Started by KenneGaray, Today, 03:48 AM
                            0 responses
                            4 views
                            0 likes
                            Last Post KenneGaray  
                            Started by thanajo, 05-04-2021, 02:11 AM
                            4 responses
                            470 views
                            0 likes
                            Last Post tradingnasdaqprueba  
                            Started by aa731, Today, 02:54 AM
                            0 responses
                            5 views
                            0 likes
                            Last Post aa731
                            by aa731
                             
                            Started by Christopher_R, Today, 12:29 AM
                            0 responses
                            11 views
                            0 likes
                            Last Post Christopher_R  
                            Working...
                            X