Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

where to define new variable

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

    where to define new variable

    hello everyone,


    i am still learning nt programming basics.


    i would like to use a transformation of williamsr indicator in an automated strategy. i don't want the number of periods that the williamsr indicator will be calculated on to be hard coded into the strategy, but would like to keep it among the inputs that can be set externally and / or optimized.

    i would like to define some kind of function (?) or variable (?) that performed the following transformation of the williamsr and it is this transformation i would like to use for the automated strategy algorithms.

    we would call the number of periods for the williamsr - wrp -, and then the transformation would be the following:


    revwillr = ( williamsr(wrp) * (-1) )


    i understand i need to define wrp among the variables like this:


    private int wrp = 9;


    but how could i then define the revwillr function / variable (how can i use or call an existing indicator like williamsr?) and where in the strategy should i place it?


    thanks.
    Last edited by rtwave; 03-25-2016, 01:48 AM.

    #2
    Hello rtwave,

    Thank you for your post.

    Is revwillr intended to be a variable of the WilliamsR indicator itself? Or is it simply a variable to hold the value of the WilliamsR * -1?

    To set a variable as user defined you can refer to the following link: http://ninjatrader.com/support/forum...ead.php?t=5782

    Comment


      #3
      PatrickH, thanks.

      i want to use the williamsr multiple times in a strategy, but prefer that it takes positive values. that's why i think a new variable would work best.

      Comment


        #4
        Hello rtwave,

        So revwillr does represent an instantiated WilliamsR indicator then, correct?

        When you multiply by -1 this is to keep the value where you would like, correct?

        And finally you want to be able to dynamically have the period change while the indicator or strategy is running, is that accurate?

        I want to provide an example but need to verify I understand what you are looking for. Please confirm the items above or advise what is truly needed.

        Comment


          #5
          PatrickH, thanks.



          in a more general sense i would like to learn how to be able to apply basic arithmetic transformations (additions, multiplications and so on) to indicators and variables (functions?) in a way such that nt can then apply logical operators such as <=, >=, cross above and others to these outputs within an automated strategy.


          i am not familiar with the concept of instantiated. in this case my idea is to have an equation / function / variable called revwillr that would calculate a williamsr, apply a transformation to the williamsr's value and then use this output. and yes, multiplying by (-1) is a means to have a williamsr with only positive values.

          finally, i would like to have an input to be able to adjust the periods over which the revwillr is calculated, just like the periods for a normal williamsr or sma can be adjusted via a numeric input. it would not be necessary for this value to be dynamically modified once the strategy is running.

          Comment


            #6
            Hello rtwave,

            Here is a basic example:
            Code:
            		private int period = 20;
            		private double revwillr = 0;
            		
                    protected override void Initialize()
                    {
                        CalculateOnBarClose = true;
                    }
            		
                    protected override void OnBarUpdate()
                    {
            			if (CurrentBar <= period)
            				return;
            			
            			revwillr = WilliamsR(period)[0] * -1;
            			
            			if (revwillr >= 20)
            				Print("Hello");
                    }
            
                    [Description("")]
                    [GridCategory("Parameters")]
                    public int Period
                    {
                        get { return period; }
                        set { period = Math.Max(1, value); }
                    }
            I recommend you review our educational resources to begin learning NinjaScript at the following link: http://ninjatrader.com/support/helpG..._resources.htm

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Jonafare, 12-06-2012, 03:48 PM
            5 responses
            3,984 views
            0 likes
            Last Post rene69851  
            Started by Fitspressorest, Today, 01:38 PM
            0 responses
            2 views
            0 likes
            Last Post Fitspressorest  
            Started by Jonker, Today, 01:19 PM
            0 responses
            2 views
            0 likes
            Last Post Jonker
            by Jonker
             
            Started by futtrader, Today, 01:16 PM
            0 responses
            6 views
            0 likes
            Last Post futtrader  
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,791 views
            0 likes
            Last Post aligator  
            Working...
            X