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

Using percentages in an indicator

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

    Using percentages in an indicator

    I would like to easily through the wizard create an indicator that takes a known fixed line or level and the indicator adds or subtracts a certain percentage to that value and creates another indicator.

    I know that is rambling so let me simplify that.

    Lets make it easy. Using the indicator which is already in Ninja. 'Prior Day OHLC".

    my new indicator would have inputs for "above Open and below Open. the same for HLC. But instead of using tick value I would like to use a percentage. Therefore if the input for "Above Yest Open" is .02 then I would have a line at yesterdays open plus 2%. If the input for "Below Yest Open" is 1.8% then the input would be .018 and a line would be drawn at yesterdays open minus 1.8%.

    the same would be said for 2 inputs on Yest high, Yest low and Yest close.

    What I would end up with are lines that are x% above and below Yesterdays Open, Yest High, Yest Low and Yest close. 8 lines total. 8 inputs.

    Help would be greatly appreciated. Thank you.

    #2
    Hello nostalgia93,

    Thank you for the post and welcome to the NinjaTrader support forum.

    In this case what you are explaining also includes logic which is not something the indicator wizard is capable of. You can certainly use math in NinjaScript to place drawings or do other actions but this is not something that could be done from the indicator wizard and would require manual coding.

    You could design some of this in the strategy builder such as the conditions using other indicators, but you would still need to extract the syntax from that and paste it into an indicator. In NT7 indicators are a manually programmed item so I am unsure how to provide much direction surrounding the wizard in this case. If you need further assistance with any manually programmed concepts I could try to provide help content surrounding your questions.

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

    Comment


      #3
      Thank you for your reply. Actually I had originally considered doing this in the strategy wizard which seemed like it may be easier there instead of as a stand alone indicator.

      I started that process seeing I am pretty decent with the strategy wizard but I hit a roadblock figuring out how to add a percent to, say for instance Yesterdays High off of the Prior OHLC indicator.

      Maybe you could help me with that one thing and I can learn from that and replicate it on the others?

      Thanks so much.

      Comment


        #4
        Hello nostalgia93,

        Thank you for the reply.

        Yes, this is what I mean by some of this can be created in the strategy wizard. You could create base conditions or other items the builder is capable of and then View Code to see what was generated. This would be helpful in finding the syntax for indicators or conditions if needed. That can give you a basis to start with but all of the percent modifications you want would need to be added later manually.

        Calculating a percentage would just a math concept so this will likely be one of the more simple portions of the script. If you are just looking for X percent to be added to the current value, you could get the value in by multiplying: 2000 + (2000 * 0.02).

        What portion of the logic are you stuck with post wizard? Perhaps I could provide more detail on what you are having difficulty in code as the percentages specifically will not be available in the wizard.

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

        Comment


          #5
          ok, thanks. in the strat wizzard I began by having 2 inputs. both of them a percent number which is a double. that part was easy. so to test i put .02 in each of them as a default.

          that was my inputs.

          next was the conditions.


          so i chose when the low crosses above yesterday close (this comes from the prior day ohlc indicator) enter long. The same was for the short in reverse. If the high crosses below yesterday close then go short.

          That is where I hit the roadblock. I dont know where to enter the formula to basically recognize the trigger point not as yesterdays close but yesterdays close plus the percentage or minus the percentage.

          Is this done through a user variable? or is the simple math done on the right hand side of the condition builder? I dont know how or where to enter the math.

          Thanks.

          Comment


            #6
            Hello nostalgia93,

            Thank you for the reply.

            Regarding doing math in the wizard, In NT7 there was no concept of arithmetic in the wizard so again the percentage parts would not be possible using the wizard. Math has been added to the builder in NT8 so some math concepts are now possible without manually programming.

            For NT7 this is part of the script you would need to unlock and edit manually. While creating the script, you can create conditions as placeholders which you can go back later and edit manually to do percents. The wizard in NT7 is fairly limited in what you can do so you may need to only use it to generate the structure you need or set basic properties before manually coding.

            It sounds like you have the script configured and are ready to add other math, have you at this point unlocked the script and started editing it manually? To be clear this is not going to be something you can re-edit in the builder and would need to manually program.


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

            Comment


              #7
              i have not unlocked the script no.

              Comment


                #8
                Hello nostalgia93,

                Thank you for the reply.

                Moving to manual programming would be the next step once you exceed the capabilities of the wizard.

                One example would be using the PriorDayOHLC indicator to get the prior close.

                Code:
                double value = PriorDayOHLC().PriorClose[0];
                And if you wanted to add to that value:

                Code:
                double value = PriorDayOHLC().PriorClose[0];
                value = value + (value * 0.02);


                If you are stuck on a specific portion of the logic, I would suggest sharing what you have so we can work together on what you are having difficulties with.


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

                Comment


                  #9
                  // This namespace holds all strategies and is required. Do not change it.
                  namespace NinjaTrader.Strategy
                  {
                  /// <summary>
                  /// Enter the description of your strategy here
                  /// </summary>
                  [Description("Enter the description of your strategy here")]
                  public class PERCENTABCLOSE : Strategy
                  {
                  #region Variables
                  // Wizard generated variables
                  private double pERCENTABOVE = 0; // Default setting for PERCENTABOVE
                  private double pERCENTBELOW = 0; // Default setting for PERCENTBELOW
                  private int pROFITTARGETTICKS = 25; // Default setting for PROFITTARGETTICKS
                  // User defined variables (add any user defined variables below)
                  #endregion

                  /// <summary>
                  /// This method is used to configure the strategy and is called once before any strategy method is called.
                  /// </summary>
                  protected override void Initialize()
                  {
                  Add(PriorDayOHLC());
                  Add(PriorDayOHLC());
                  SetProfitTarget("", CalculationMode.Ticks, PROFITTARGETTICKS);

                  CalculateOnBarClose = true;
                  }

                  /// <summary>
                  /// Called on each bar update event (incoming tick)
                  /// </summary>
                  protected override void OnBarUpdate()
                  {
                  // Condition set 1
                  if (CrossAbove(Low, PriorDayOHLC().PriorClose, 1))
                  {
                  EnterLong(DefaultQuantity, "LONG");
                  }

                  // Condition set 2
                  if (CrossBelow(High, PriorDayOHLC().PriorClose, 1))
                  {
                  EnterShort(DefaultQuantity, "SHORT");
                  }
                  }

                  #region Properties
                  [Description("")]
                  [GridCategory("Parameters")]
                  public double PERCENTABOVE
                  {
                  get { return pERCENTABOVE; }
                  set { pERCENTABOVE = Math.Max(0.02, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public double PERCENTBELOW
                  {
                  get { return pERCENTBELOW; }
                  set { pERCENTBELOW = Math.Max(0.02, value); }
                  }

                  [Description("")]
                  [GridCategory("Parameters")]
                  public int PROFITTARGETTICKS
                  {
                  get { return pROFITTARGETTICKS; }
                  set { pROFITTARGETTICKS = Math.Max(1, value); }
                  }
                  #endregion
                  }
                  }

                  Comment


                    #10
                    Hello nostalgia93,

                    Thank you for the reply.

                    This appears to be the base script you have started with coming out of the builder, did you have a question surrounding some part of what you have provided?

                    The next step for creating what you are asking would involve manually coding the changes you want. This would entail that you change the code to match your expectations. This may involve the use of the help guide or other available syntax samples to construct your script.

                    I would be happy to provide further details where I can but I would need some form of question surrounding what you are unclear on.


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

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by timko, Today, 06:45 AM
                    2 responses
                    12 views
                    0 likes
                    Last Post NinjaTrader_ChristopherJ  
                    Started by habeebft, Today, 07:27 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post habeebft  
                    Started by Tim-c, Today, 03:54 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by rocketman7, Today, 01:00 AM
                    1 response
                    10 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by wzgy0920, 04-23-2024, 09:53 PM
                    3 responses
                    76 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Working...
                    X