NexusFi: Find Your Edge


Home Menu

 





Help - how can I use Dataseries wich are calulate by an other Indicator?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Fat Tails with 6 posts (3 thanks)
    2. looks_two Trendseek with 5 posts (1 thanks)
    3. looks_3 Quick Summary with 1 posts (0 thanks)
    4. looks_4 gunsnmoney with 1 posts (0 thanks)
    1. trending_up 5,976 views
    2. thumb_up 4 thanks given
    3. group 3 followers
    1. forum 12 posts
    2. attach_file 5 attachments




 
Search this Thread

Help - how can I use Dataseries wich are calulate by an other Indicator?

  #1 (permalink)
 Trendseek 
Leipzig / Germany
 
Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker: Interactive Broker
Trading: Futures, Forex
Posts: 28 since Aug 2009
Thanks Given: 46
Thanks Received: 36

Hello Ninjas,
just a simple C#-Question...

I try to develope an Indicator for a Bollinger-Band, based on a "faster" Moving Average.
To calculate the Standard-Deviation for that "faster" MA (i.e. EMA or HMA), I have the Idea, to customize the normal StdDev Indicator, so, that it is able to use that "faster" MA from the calling Bollinger-Band Indicator without a recalculation - the "faster" MA must be "visible" for the new StdDev-Indicator.

Here is my Question - How can I make the "faster" MA, calculate in the new faster Bollinger-Band Indicator, visible in the customized StdDev?

Within the "FastBollinger" I call that customized StdDev as followed:

 
Code
//Calculate the fast MA
fastMA.Set(EMA(Period)[0]);

//Calling the customized StdDev with the fastMA
double StdDev = StdDevIND(fastMA, Period)[0];
Unfortunaly the Code for the customized StdDev did not work - It is not able to use the MA-Datastream

 
Code
public class StdDevIND : Indicator
    {
        #region Variables
         // this seeems to be wrong ore incomplete for using the former calulate fast MA
            IDataSeries     IndSeries;

            private int        period    = 14;
        
        #endregion

        protected override void Initialize()
        {
            Add(new Plot(Color.Green, "StdDev"));
//           Perhaps I have to build an Instanz for the MA-Datastream here?
        }

        protected override void OnBarUpdate()
        {
            if (CurrentBar < period)return;            
            else
            {
                double sum = 0;
                  for (int count = 0; count < Period ; count++)
                {
                    double diff = Math.Abs(Input[count] - IndSeries[count]);
                    sum += diff * diff;
                }   

                Value.Set(Math.Sqrt(sum / Period));
            }
        }
Hope, that someone of you can help - so that i can finished that Idea and make it usable for other users!

regards
Trendseek

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Exit Strategy
NinjaTrader
Better Renko Gaps
The Elite Circle
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
30 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


From your post it is not very clear, what you want to achieve.

1. I understand that you want to calculate a band around a moving average. You are talking about a faster moving average. So there must be a slow one as well that you are not mentioning. Can you tell me what is the purpose of the fast and the slow moving average?

2. You are mentioning different types of moving averages, EMA or HMA. Have you made up your mind, which one to use?

3. What is the mathematical formula for your band?

Reply With Quote
  #4 (permalink)
 Trendseek 
Leipzig / Germany
 
Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker: Interactive Broker
Trading: Futures, Forex
Posts: 28 since Aug 2009
Thanks Given: 46
Thanks Received: 36

Thanks for reading my Question - and sorry, if my explanation was a unclear.

The normal NT - Bollinger Indicator is based on a Simple Moving Average. The Code is very simple:
Firstly it calculates the SMA, secondly it is calling the Standard Deviation- Indicator with the same Period for calculating the Standard Deviation of that SMA. Thirdly it calculates the two BollingerBands.

Here is the Main-Code Snip for Bollinger
 
Code
            double smaValue    = SMA(Period)[0];
            double stdDevValue = StdDev(Period)[0];
            Upper.Set(smaValue + NumStdDev * stdDevValue);
            Middle.Set(smaValue);
            Lower.Set(smaValue - NumStdDev * stdDevValue);
And this one is the main Code Snip for the StdDev:
 
Code
                sumSeries.Set(Input[0] + sumSeries[1] - (CurrentBar >= Period ? Input[Period] : 0));
                double avg = sumSeries[0] / Math.Min(CurrentBar + 1, Period);
                double sum = 0;
                for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack >= 0; barsBack--)
                    sum += (Input[barsBack] - avg) * (Input[barsBack] - avg);

                Value.Set(Math.Sqrt(sum / Math.Min(CurrentBar + 1, Period)));
OK - You can see that the called StdDev also calculates a Simple Moving Average (SMA) instead of using the SMA Dataseries from the calling Bollinger Method.

My Intention is to write a modified StdDev Indicator that have access to the Moving Average which was calculated in the calling Method (for example a modified Bollinger-Indicator). This has two Advantages. Firstly it saves Ressources, if you are using complex Moving Averages instead of a simple SMA, and secondly this modified StdDev will be more flexible because you can use it with different Datastreams (mostly different Moving Averages).


Here is my Code Idea for a modified Bollinger (in this example with a "faster" EMA instead of a "slow" SMA).
 
Code
            smaSeries.Set(SMA(Period)[0]);
            double stdDevValue = modifiedStdDev(smaSeries, Period)[0];
            Upper.Set(smaValue + NumStdDev * stdDevValue);
            Middle.Set(smaValue);
            Lower.Set(smaValue - NumStdDev * stdDevValue);
Unfortunaly I have no Idea how to make the smaSeries from that modified Bolinger usable within the modified StdDev - and this is my Question.


Here is my - not working - Code-Idea for the modifiedStdDev
 
Code
public class StdDevIND : Indicator
    {
        #region Variables
           // this is for the Moving-Average DataSeries from the calling Method (for example a modified Bollinger)
            IDataSeries     IndSeries;
            private int        period    = 14;
        
        #endregion

        protected override void Initialize()
        {
            Add(new Plot(Color.Green, "StdDev"));
            // Shoud I initialize a new DataSeries for the Moving Average from the calling Method?
        }

        protected override void OnBarUpdate()
        {
            if (CurrentBar < period)return;            
            else
            {
                double sum = 0;
                  for (int count = 0; count < Period ; count++)
                {
                    double diff = Math.Abs(Input[count] - IndSeries[count]);
                    sum += diff * diff;
                }   

                Value.Set(Math.Sqrt(sum / Period));
            }
        }

        #region Properties
        // May I should do something here?
        //public IDataSeries INDSeries
        {
            get { return IndSeries; }
            set { IndSeries = value; }
        }
        
        public int Period
        {
            get { return period; }
            set { period = Math.Max(1, value); }
        }
        #endregion
OK - I hope, that this explanation will be a little bit clearer.
Thanks for reading - and I hope someone can help!

Regards
Trendseek

Started this thread Reply With Quote
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Trendseek View Post
The normal NT - Bollinger Indicator is based on a Simple Moving Average. The Code is very simple:
Firstly it calculates the SMA, secondly it is calling the Standard Deviation- Indicator with the same Period for calculating the Standard Deviation of that SMA

Edit: Text removed. Trendseek is correct. The StdDev indicator uses a simple moving average. So at least I have learned something!

You could try the following code for NT 7(not tested):

 
Code
 
# region Variables
 
private double period = 14;
private double bandperiod = 14;
private double numStdDev = 2.0;
private StdDev StdDev_IND;
private DataSeries MMA_IND;
 
protected override void Initialize()
{
  Add(new Plot(new Pen(Color.Red, 1), PlotStyle.Line, "Middle"));
  Add(new Plot(new Pen(Color.Orange, 1), PlotStyle.Line, "Upper"));
  Add(new Plot(new Pen(Color.Orange, 1), PlotStyle.Line, "Lower"));
   MMA_IND = new DataSeries(this);
     StdDev_IND = new DataSeries(this); 
}
 
protected override void OnStartUp()
{
     MMA_IND = EMA(Input, period);  // you can also replace this with a SMA, HMA or whatsoever
     StdDevInd=StdDev(MMA_IND, bandperiod));  /you can use a different bandperiod
}
 
protected override void OnBarUpdate()
{
   if (CurrentBar < period + bandperiod)}
       return;
   double average = MMA_IND[0];
   double stdDevValue = StdDev_IND[0];
     Middle.Set(average);
     Upper.Set(average + numStdDev * stdDevValue);
     Lower.Set(average - numStdDev * stdDevValue);
}
 
#region Properties
 
etc.

Reply With Quote
  #6 (permalink)
 Trendseek 
Leipzig / Germany
 
Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker: Interactive Broker
Trading: Futures, Forex
Posts: 28 since Aug 2009
Thanks Given: 46
Thanks Received: 36


Fat Tails View Post
The standard deviation in the Bollinger Band is not calculated for the SMA, but for the original data points. So it does not depend on the type of SMA you choose.

Hello Fat Tails,
thanks again for your answer - but perhaps we use different conceptions about Bollinger, or I simply missconceive you?

Bollinger in his own words: "For Bollinger Bands the measure of central tendency is a simple moving average, and the interval is delineated by a measure of volatility, a moving standard deviation." (Bollinger, John; Bollinger on Bollinger Bands; 2002; S.50). And this is, what we see in the Standard-NT Code above. Do you have some Sources for your interpretation about "centerpoints" and prices?

In my view you need something like the SMA for calculate the Standard Deviation (the Difference between Datapoints and the SMA-Values). By the way - later in his Book, Bollinger discuss the uselessness of "fast Bollinger-Bands" who based on an EMA instead of a SMA for calculate the Standarddeviation.
But back to my SIMPLE MAIN-Question - How can I use a Dataseries in an Indicator like a custumized StandardDeviation which was calculate by an other Indicator (or Method)?

Started this thread Reply With Quote
Thanked by:
  #7 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


Trendseek View Post
Hello Fat Tails,
thanks again for your answer - but perhaps we use different conceptions about Bollinger, or I simply missconceive you?

Bollinger in his own words: "For Bollinger Bands the measure of central tendency is a simple moving average, and the interval is delineated by a measure of volatility, a moving standard deviation." (Bollinger, John; Bollinger on Bollinger Bands; 2002; S.50). And this is, what we see in the Standard-NT Code above. Do you have some Sources for your interpretation about "centerpoints" and prices?

In my view you need something like the SMA for calculate the Standard Deviation (the Difference between Datapoints and the SMA-Values). By the way - later in his Book, Bollinger discuss the uselessness of "fast Bollinger-Bands" who based on an EMA instead of a SMA for calculate the Standarddeviation.
But back to my SIMPLE MAIN-Question - How can I use a Dataseries in an Indicator like a custumized StandardDeviation which was calculate by an other Indicator (or Method)?


There is no problem with your use of INDSeries. You just need to affect a value to it such as IndSeries = EMA(Input,period);

Maybe you want to use an enum. Could then select via indicator panel, which method you want to use to calculate your moving average.

 
Code
 
#region Global Enums
 
public enum movingAverageType (SMA, EMA, HMA, TEMA, WMA)  // all types of moving averages
 
#endregion
 
#region Variables
 
private movingAverageType  sdAverageType  =  movingAverageType.SMA;
private DataSeries StdDev_IND
 
#endregion
 
....
 
protected override void OnBarUpdate()
{
    ....
   if (sdaverageType == movingAverageType.SMA)
    {
         // insert formula for StdDev_IND calculated from SMA
    }
 
    else if (sdaverageType == movingAverageType.EMA)
    {
        //insert formula for StdDev_IND calculated from EMA
    }
 
.... 
}
 
#region Properties
 
...
 
[Description("Moving Average Type")]
[GridCategory("Parameters")]
[Gui.Design.DisplayNameAttribute("MA Type")]
public movingAverageType SdAverageType
{
get { return sdAverageType; }
set { sdAverageType = value; }
}
 
...

Reply With Quote
  #8 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102

Here is a sample of a universal Bollinger Band indicator. It can plot Bollinger bands using 11 different moving averages to be selected via indicator panel.

Took me some time to understand, what you wanted. Hope that this comes close.

Attached Files
Elite Membership required to download: BollingerUniversal.zip
Reply With Quote
  #9 (permalink)
 gunsnmoney 
Santa Clara, CA
 
Experience: Intermediate
Platform: NT8,
Broker: Tradier, TastyTrade
Trading: ES, Fx
Posts: 19 since Jul 2010
Thanks Given: 13
Thanks Received: 18


Fat Tails View Post
The StdDev indicator uses a simple moving average. So at least I have learned something!


Ummm, standard deviation is variation around an AVERAGE. It has to use an SMA. If you modify it using anything not an average, it becomes something other than stddev. The multi-MA tool above seems to be the best approach
to me. Play around with different moving averages with Bollinger bands added and subtracted (plus/minus stddev) and I'm sure what you have conceptualized will be in there. But keep in mind that its still the average of the fast moving average for the (period) bars that the standard deviation is being calculated from. The Dataseries is an average of the EMA (for example).

To understand this better, try adding "close" as the dataseries of the stddev to regular Bollinger bands and then you would see the volatility of each bar close (price action). It is just interesting - maybe not useful tho.

G&M

Reply With Quote
  #10 (permalink)
 Trendseek 
Leipzig / Germany
 
Experience: Intermediate
Platform: NT / TS, MC and Clones
Broker: Interactive Broker
Trading: Futures, Forex
Posts: 28 since Aug 2009
Thanks Given: 46
Thanks Received: 36



gunsnmoney View Post
Ummm, standard deviation is variation around an AVERAGE. It has to use an SMA. If you modify it using anything not an average, it becomes something other than stddev.

The StdDev simple means what it says: It is a standardised deviation (or difference) between two Datasets - nothing else. Instead of an Average you can use a Regression-Line or anything else you want - but you are right: the "original" mathematical notation contains the differences between Datapoints and tha SMA of that Datapoints over a given Period.

@ Fat Tails: Wow - a big thanks for your effort - this is a comfortable way to check out and compare different MA-Versions of Bollinger-Bands.
Unfortunaly it did not answers my Question about visibility and the access of different (MA-)Dataseries when they are a public or private.

Greetings from Leipzig
Trendseek

Started this thread Reply With Quote




Last Updated on September 3, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts