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

Slope function output

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

    #91
    Hello Ben,
    Thanks for the quick response.
    I open up the output window but nothing displays in it.
    How do I get something to display in it?
    Like the slope values shown below or another indicators values?

    Thanks

    Comment


      #92
      Hello,

      You are welcome.

      Use Print(your_val_here); or Print("test");

      This link will assist you with Print():
      DenNinjaTrader Customer Service

      Comment


        #93
        Ben,
        If I wanted to have the value of a regular EMA go to the output window, what are the changes to the code below to make that happen?
        Normal EMA code is below.
        Use the : Print()
        Like:// Prints the current bar EMA value to the output window
        Print(EMA(Close, 34)[0]);

        Thanks for you help.




        ///<summary>
        /// Exponential Moving Average. The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.
        ///</summary>
        [Description("The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA.")]
        publicclass EMA : Indicator
        {
        #region Variables
        privateint period = 14;
        #endregion
        ///<summary>
        /// This method is used to configure the indicator and is called once before any bar data is loaded.
        ///</summary>
        protectedoverridevoid Initialize()
        {
        Add(
        new Plot(Color.Orange, "EMA"));
        Overlay =
        true;
        PriceTypeSupported =
        true;
        }

        ///<summary>
        /// Called on each bar update event (incoming tick)
        ///</summary>
        protectedoverridevoid OnBarUpdate()
        {
        Value.Set(CurrentBar ==
        0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
        }
        #region Properties
        ///<summary>
        ///</summary>
        [Description("Numbers of bars used for calculations")]
        [Category(
        "Parameters")]
        publicint Period
        {
        get { return period; }
        set { period = Math.Max(1, value); }
        }
        #endregion
        }
        }

        Comment


          #94
          Hello,

          You will want to place Print(EMA(Close, 34)[0]); within the OnBarUpdate() block to print the current value of the EMA.
          DenNinjaTrader Customer Service

          Comment


            #95
            Great, Thanks Ben

            Comment


              #96
              If anyone's interested, I posted a super fast calculation for regression slope in the indicator file area, called LinRegSlopeSFX. It calculates the slope of a regression line two ways, one way gives identical results to the traditional method, and another way uses exponential moving averages in lieu of sums.

              I never liked the built-in Slope() method. It basically returns momentum divided by intervals. True slope is the slope of the best-fit line, i.e. the slope of a regression line. That's what LinRegSlopeSFX returns.

              -Alex
              Last edited by anachronist; 08-20-2008, 09:01 AM.

              Comment


                #97
                Linear regression slope in degrees?

                Hi everyone

                I just noticed this post... maybe I missed something... did anyone post yet an indicator plotting the Linear Regression slope in degrees (classic range -90 / 90 or -45 / 45 degrees rather than numbers)?

                Thank you

                Comment


                  #98
                  Originally posted by stefy View Post
                  I just noticed this post... maybe I missed something... did anyone post yet an indicator plotting the Linear Regression slope in degrees (classic range -90 / 90 or -45 / 45 degrees rather than numbers)?
                  That would be meaningless, because (a) the vertical and horizontal scaling of a chart is arbitrary, and (b) the units of the x and y axes are different. The only time you can validly get degrees is if the units on both axes are the same.
                  -Alex

                  Comment


                    #99
                    Right, anachronist, but random values like 0.005 plotted on the slope chart are useless to me. Does it mean the slope is steep? How can I determine this? Someone could offer an example of how to use the slope (and its values) in a useful way?

                    Thank you everyone

                    Comment


                      Originally posted by stefy View Post
                      Right, anachronist, but random values like 0.005 plotted on the slope chart are useless to me. Does it mean the slope is steep? How can I determine this?
                      Stefy, the same argument can be said for angle, because you have no objective way of determining if an angle is "steep". Is 45° steep? How about 50°? What about 30°? Larger angles are merely steeper than smaller angles. Similarly, larger slopes are steeper than smaller slopes.

                      Because you need the same units on both axes, and the same scaling on both axes for slope to be meaningful, the only meaningful value is zero.

                      Even if you had the same units and scaling, you still wouldn't need degrees. Math.Atan(slope) gives you angle in radians, 180.0/Math.PI*radians gives you degrees. A slope of 1.0 is the same as 45° (when horizontal and vertical movement are equal).

                      But degrees mean nothing when you have time on one axis and price on another. If you got a slope of 1.0, that wouldn't be an angle, it simply means that price changes at a rate of 1 price unit per bar -- whatever a "price unit" is for your market (a dollar, a tick, a multiple of ticks, or something adaptive - see below).

                      Someone could offer an example of how to use the slope (and its values) in a useful way?
                      There are several ways in which slope can be useful:

                      1. You could define a "price unit" as an expected average displacement of price per bar in a trend. This would be different for each market. Then slope would tell you if a trend is steeper or shallower than expected for that market. One useful definition of expected slope would be a random-walk definition: take the standard deviation of (Close[0]-Close[1]) over N bars (ending with Close[N-1]-Close[N]) where N is large. The expected slope of m-bar trends would be this standard deviation multiplied by Math.Sqrt(m-1)/(m-1). Now, if you calculate slope over m bars, you can compare it with your expectation to determine if the market is trending more steeply relative to what you'd expect from a random walk.

                      2. You might use a zero crossing (when slope goes from positive to negative, or negative to positive) to indicate a change in trend direction.

                      3. Slope is also useful as an oscillator. If you plot slope as an indicator, you will see that it occupies a range of values. This range will be different for each market because the price scales are different. When the slope is near its maximum historical value, or near its minimum historical value, it's "steep".

                      4. You could use slopes of different lengths as a crossover signal, similar to MACD.

                      5. Any oscillator such as slope can be used for divergence signals.

                      6. I have used slope and intercept to get an equation for a regression line, from which I calculate price deviations over an interval, and I use those deviations as a noise measurement, from which I built adaptive indicators.

                      Hope that gives some ideas. No guarantee any of them will be profitable.
                      -Alex
                      Last edited by anachronist; 08-24-2008, 04:33 PM. Reason: corrected note about random walk

                      Comment


                        Thanks Alex, very on point.
                        RayNinjaTrader Customer Service

                        Comment


                          Easier Decimal places

                          [QUOTE=dwalls;12734]Gumphrie,


                          Put this in the initialize() section

                          Code:
                          	
                          if (TickSize.ToString().StartsWith("1E-"))
                          
                          {
                          Digits=Convert.ToInt32(TickSize.ToString().Substring(3));
                          }
                          else if (TickSize.ToString().IndexOf(".")>0)
                          {
                          Digits=TickSize.ToString().Substring(TickSize.ToString().IndexOf("."),TickSize.ToString().Length-1).Length-1;
                          }
                          And add this to your OnBarUpdate()

                          Code:
                          string dec = "N" + Digits.ToString();
                          Then you can simply code your actual string output using the following

                          string myoutputstring.ToString(dec);


                          Borrowed the initialize section from one of the samples (StatusBox) and just amended it to my own ends. I am not a programmer so I can't decipher or help with what it does ; but the output is the no of decimal points the symbol seems to require.
                          The string addition is all my own!
                          Last edited by Mindset; 11-03-2008, 12:31 PM.

                          Comment


                            Originally posted by Mindset View Post
                            Borrowed the initialize sectiont from one of the samples
                            Think I remember writing that one, don't forget to initialize/declare Digits as 0 or it'll break.

                            Comment


                              Absolutely

                              Originally posted by Gumphrie View Post
                              Think I remember writing that one, don't forget to initialize/declare Digits as 0 or it'll break.
                              Code:
                              	private	int 	Digits	= 0;
                              Apologies Gumphrie I couldn't remember who wrote StatusBox which I found a couple of weeks ago.
                              It is v useful having code that works - deciphering it is hard ( I am still waiting for my C# book to arrive) - I guess it's a little like learning to fly - I am still scrabbling to leave the gate!

                              Comment


                                Slope function confusion

                                Originally posted by NinjaTrader_Josh View Post
                                Couldn't you also just use some math to determine the angle? Slope of 1 is 45 degrees and slope of -1 is -45. Slope of 0 is 0 degrees. You don't have to worry about 90 or -90 because those won't exist on a chart.

                                Basically just use m=tan θ where m is the slope and θ is the degrees.

                                Example
                                Code:
                                (System.Math.Atan(Slope(SMA(5),CurrentBar-1,CurrentBar))*180/Math.PI).ToString()
                                This will give you the angle in degrees of an SMA.

                                So waht is ithe good way to use the slope function ( I just want the slope from last period to this period and let's assume teh current bar = 20

                                According to the user guide I should get it like that

                                Slope(IDataSeries series,1, 0) (if we want the last available slope)

                                here 1> 0

                                According to this post :

                                Slope(IDataSeries series,CurrentBar-1, CurrentBar)

                                Slope(IDataSeries series,19, 20)

                                19 < 20

                                What is the correct way ?

                                Thank You

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by jxs_xrj, 01-12-2020, 09:49 AM
                                6 responses
                                3,290 views
                                1 like
                                Last Post jgualdronc  
                                Started by Touch-Ups, Today, 10:36 AM
                                0 responses
                                7 views
                                0 likes
                                Last Post Touch-Ups  
                                Started by geddyisodin, 04-25-2024, 05:20 AM
                                8 responses
                                61 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Started by Option Whisperer, Today, 09:55 AM
                                0 responses
                                8 views
                                0 likes
                                Last Post Option Whisperer  
                                Started by halgo_boulder, 04-20-2024, 08:44 AM
                                2 responses
                                24 views
                                0 likes
                                Last Post halgo_boulder  
                                Working...
                                X