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

Can I have Std. Dev. lines on my indicator panel?

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

    Can I have Std. Dev. lines on my indicator panel?

    I would like to see, for example, how many standard deviations an indicator is currently from the 0 line. Is there a way to draw the .5, 1, 1.5 and 2 std. deviation lines on an indicator panel? Let's say I want to do this on the Price Oscillator indicator, and thus create my own new PO with std. dev.

    I assume it would go in the Initialize tag:

    protected override void Initialize()
    {
    Add(new Line(Color.DarkGray, 0, "Zero line"));
    Add(new Plot(Color.Orange, Name));

    smoothEma = new DataSeries(this);
    Fast = 12;
    PriceTypeSupported = true;
    Slow = 26;
    Smooth = 9;
    }


    So I might add something like this?

    Add(new Line(Color.Red, stddev(somenumber), ".5"));
    Add(new Line(Color.Red, stddev(somenumber), "1"));
    Add(new Line(Color.Red, stddev(somenumber), "1.5"));
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Add(new Line(Color.Red, 0.5, ".5"));
    Add(new Line(Color.Red, 1, "1"));
    Add(new Line(Color.Red, 1.5, "1.5"));
    RayNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Ray View Post
      Add(new Line(Color.Red, 0.5, ".5"));
      Add(new Line(Color.Red, 1, "1"));
      Add(new Line(Color.Red, 1.5, "1.5"));
      Well, kind of, sort of.. not quite.

      I guess I needed to learn more about std. deviation before I went and tried to plot it. Wikipedia says: "Said more formally, the standard deviation is the root mean square (RMS) deviation of values from their arithmetic mean."

      I think what I want is to plot the standard deviation of price activity, rather than plot the oscillator graph with horizontal lines. I'll work on it and post something here if anyone is interested. Gotta love probability and statistics!

      Bryan


      [Edit: Oops, now that I look, there already is a StdDev indicator. So I can call that to calculate the std. dev. from my own oscillators... cool.]
      Last edited by cassb; 11-16-2007, 07:42 PM.
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        Have you looked at the Bollinger Bands indicator?

        It consists of a moving average of the price, with lines plotted 2 standard deviations on each side of it.

        This might be a good starting point, you could modify this indicator to plot a series of standard deviations at .5, 1.0, 1.5, etc. standard deviations above/below the average price.

        Or (easier), you could just add multiple Bollinger Bands to your chart and select different multipliers.

        Comment


          #5
          Originally posted by KBJ View Post
          Have you looked at the Bollinger Bands indicator?

          It consists of a moving average of the price, with lines plotted 2 standard deviations on each side of it.

          This might be a good starting point, you could modify this indicator to plot a series of standard deviations at .5, 1.0, 1.5, etc. standard deviations above/below the average price.

          Or (easier), you could just add multiple Bollinger Bands to your chart and select different multipliers.
          Hm... good point, I'll give it a try. I like that you can use another indicator within your code. So maybe I can just call the BB indicator code and plot it in a oscillator somehow.... Don't you love programming? :-)

          Thanks!
          Bryan
          cassb
          NinjaTrader Ecosystem Vendor - Logical Forex

          Comment


            #6
            Hey guys, wondered if anyone ever have any success with this? I've been looking at this but it's beyond my knowledge at the moment, would appreciate any pointers. Have had a look at the Bollinger indicator and the MACDBB indicator to no avail ... can't figure it out.
            Thanks

            Comment


              #7
              Here's an idea, but I have not done it.

              Calculate the std. dev. in the OnBarUpdate() tag for each tick -- or only when the bar closes. Then plot a "-" character at the positive and negative std. dev. values either on the chart or in the indicator panel. It will eventually form a std. dev. line as it goes.

              Bryan
              cassb
              NinjaTrader Ecosystem Vendor - Logical Forex

              Comment


                #8
                Adding Std dev bands to an oscillator

                Go through the wizard to create a new indicator
                Add Input parameters: Fast, Slow, BBPeriod, BBwidth.
                the first two are the standard PPO values (e.g., 12,26) the other two will allow you to adjust period of the moving average used by the Bollinger Bands (typically 20) and the number of standard deviations to plot (typically 2.0)
                Make BBWidth of type double.

                Add 4 plots - one for the PPO, 1 for the top band, one for the bottom band and one for the middle moving average.

                I named mine, PPOPlot, UpperBB, LowerBB, and Middle

                I made PPOPlot Black, Upper and Lower Blue, and Middle a lighter blue.

                I also added 1 horizontal black line I called "Zero" with value 0.
                The wizard will create the Add(new Plot(..... lines in the Initialize method for you.

                It will also create a stub for the OnBarUpdate method.

                Modify the OnBarUpdate Method to:
                double val = 100 * ((EMA(Fast)[0] - EMA(Slow)[0]) / EMA(Slow)[0]);
                PPOPlot.Set(val);
                UpperBB.Set(Bollinger(PPOPlot,BBwidth, BBPeriod).Upper[0]);
                Middle.Set(Bollinger(PPOPlot,BBwidth,BBPeriod).Mid dle[0]);
                LowerBB.Set(Bollinger(PPOPlot,BBwidth, BBPeriod).Lower[0]);


                That should do it.

                Notice that the wizard only allows 4 plots to be added. You can have more but you have to add them manually.
                For each additional plot you'll need to add a Add( new Plot ... line in the Initialize() method. You'll also need to add a new public DataSeries for it in the Properties region.

                -Jim

                Comment


                  #9
                  Thanks a lot, seems so simple once you know the answer!
                  Al

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Mestor, 03-10-2023, 01:50 AM
                  16 responses
                  387 views
                  0 likes
                  Last Post z.franck  
                  Started by rtwave, 04-12-2024, 09:30 AM
                  4 responses
                  31 views
                  0 likes
                  Last Post rtwave
                  by rtwave
                   
                  Started by yertle, Yesterday, 08:38 AM
                  7 responses
                  29 views
                  0 likes
                  Last Post yertle
                  by yertle
                   
                  Started by bmartz, 03-12-2024, 06:12 AM
                  2 responses
                  22 views
                  0 likes
                  Last Post bmartz
                  by bmartz
                   
                  Started by funk10101, Today, 12:02 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post funk10101  
                  Working...
                  X