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

Standard deviation of a EMA

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

    Standard deviation of a EMA

    Hello,

    I am trying to program a standard deviation of a 21EMA to show on the upper chart. And don't know where to start with the code.

    Add StdDev(21) would be Off the price how can I change it to a EMA.

    #2
    Hello Simmi196,
    Welcome to the NinjaTrader Forums.
    You can actually use an indicator of an indicator in a chart. To do this:

    • Open up the Indicators window by left clicking on the Indicator button on the chart toolbar; it is going to be the 3rd one from the right.
    • Double left click on the indicator that you want to add, for example “StdDev”
    • It will show up in the lower left panel, make sure it is highlight by left clicking on the indicator.
    • In the right panel next to the “Input Series” left click on the “…” button.
    • This will bring up the “Input Series” window were if you scroll to the top you will see “Indicators” as an option with a “+” to the left.
    • Left clicking the “+” will display all the indicators below it where you can select another indicator, for example “EMA” and set all the parameters below after selecting it.

    To plot the “StdDev” on the same panel as the “Input Series” you can change the “Panel” parameters to “Same as input series” to have it show up on with your “Input Series” panel.

    The “Bollinger” does use a standard deviation but off of the “SMA” if you want something similar, or are you programming a custom strategy?

    Happy to be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by Simmi196 View Post
      Hello,

      I am trying to program a standard deviation of a 21EMA to show on the upper chart. And don't know where to start with the code.

      Add StdDev(21) would be Off the price how can I change it to a EMA.
      What you are describing is pretty much the Bollinger Bands, but based on the EMA instead of the SMA. Just look at the BB code and adapt it for your purposes by substituting EMA for SMA.

      Comment


        #4
        IWhat I am trying to get is a Standard Deviation Ploted off of a EMA, ploted on each side of the ema on the chart . So far I have managed to work within the indicator Bollinger Bands> Data> InputSeries >EMA (SPY (5 Min), 50) but this does not acutally give a standard deviation of an EMA. As also have this ploted on the chart. Below is my ThinkScipt that plots this can you help me convert?

        Thanks

        #Spy MA BAnds
        input type = {default "spy (5 Min) "};
        def spy = close ("spy");
        plot ema = ExpAverage(spy,21);
        ema.setdefaultcolor(color.magenta);
        def onesd = stdev(ema,21);
        def LowerBand =ema - (onesd * .75);
        def UpperBand =ema + (onesd * .75);
        plot sd1 = UpperBand;
        plot sd2 = LowerBand;
        AddCloud(upperband, lowerband,color.magenta);

        Comment


          #5
          Originally posted by Simmi196 View Post
          IWhat I am trying to get is a Standard Deviation Ploted off of a EMA, ploted on each side of the ema on the chart . So far I have managed to work within the indicator Bollinger Bands> Data> InputSeries >EMA (SPY (5 Min), 50) but this does not acutally give a standard deviation of an EMA. As also have this ploted on the chart. Below is my ThinkScipt that plots this can you help me convert?

          Thanks

          #Spy MA BAnds
          input type = {default "spy (5 Min) "};
          def spy = close ("spy");
          plot ema = ExpAverage(spy,21);
          ema.setdefaultcolor(color.magenta);
          def onesd = stdev(ema,21);
          def LowerBand =ema - (onesd * .75);
          def UpperBand =ema + (onesd * .75);
          plot sd1 = UpperBand;
          plot sd2 = LowerBand;
          AddCloud(upperband, lowerband,color.magenta);
          Code:
           
          private double numStdDev = 0.75;
          private int period = 21;
          Code:
           
          protected override void OnBarUpdate()
          {
          double emaValue = EMA(Period)[0];
          double stdDevValue = StdDev(EMA,Period)[0];
          Upper.Set(emaValue + NumStdDev * stdDevValue);
          Middle.Set(emaValue);
          Lower.Set(emaValue - NumStdDev * stdDevValue);
          }
          Which, as you can see is simply the Bollinger Bands code, with EMA instead of SMA and the StdDev applied to the EMA instead of the Close.

          Remember to create the correct properties using the backing stores, or your code will complain.
          Last edited by koganam; 06-11-2012, 07:22 PM.

          Comment


            #6
            Got it... Thanks this line of coded needed some editing for it to complie.

            double stdDevValue = StdDev(EMA(Period),Period)[0];

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by flybuzz, Today, 10:33 AM
            0 responses
            3 views
            0 likes
            Last Post flybuzz
            by flybuzz
             
            Started by algospoke, 02-19-2024, 03:25 PM
            6 responses
            42 views
            0 likes
            Last Post Abiodun
            by Abiodun
             
            Started by LillyMarv, Today, 06:47 AM
            1 response
            12 views
            0 likes
            Last Post marcus2300  
            Started by michi08, Today, 08:51 AM
            1 response
            8 views
            0 likes
            Last Post bltdavid  
            Started by awwenzovs, Today, 08:03 AM
            1 response
            9 views
            0 likes
            Last Post bltdavid  
            Working...
            X