コード例 #1
0
		protected override void OnStartUp()
		{
			BMACD=MACD(Input,fast,slow,bandPeriod);
			SDBB=StdDev(BMACD,bandPeriod);

			Plots[0].Pen.Width		= DotSize;
			Plots[0].Pen.DashStyle	= DashStyle.Dot;
			Plots[1].Pen.Width		= DotSize + 1;
			Plots[1].Pen.DashStyle	= DashStyle.Dot;
			Plots[2].Pen.Width		= plot2Width;
			Plots[2].Pen.DashStyle	= dash2Style;
			Plots[3].Pen.Width		= plot3Width;
			Plots[3].Pen.DashStyle	= dash3Style;
			Plots[4].Pen.Width		= plot3Width;
			Plots[4].Pen.DashStyle	= dash3Style;
			Plots[5].Pen.Width		= plot5Width;
			Plots[5].Pen.DashStyle	= dash5Style;
			Plots[6].Pen.Width		= CrossSize;
			Plots[7].Pen.Width		= plot7Width;

			Plots[1].Pen.Color = DotsRim;
			Plots[2].Pen.Color = BBAverage;
			Plots[3].Pen.Color = BBUpper;
			Plots[4].Pen.Color = BBLower;
			Plots[6].Pen.Color = ZeroCross;
			Plots[7].Pen.Color = Connector;
		}
コード例 #2
0
        /// <summary>
        /// Calculates the indicator value(s) at the current index.
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (!init)
            {
                BMACD   = MACD(Input, fast, slow, smooth);
                EMAMACD = EMA(BMACD, bandperiod);
                HMAMACD = HMA(BMACD, smooth);
                SDBB    = StdDev(BMACD, bandperiod);
            }
            init = true;
            double macdValue = HMAMACD[0];            //BMACD[0];

            BBMACD.Set(macdValue);
            BBMACDLine.Set(macdValue);
            BBMACDFrame.Set(macdValue);

            //double avg = EMA(BBMACD,bandperiod)[0];
            double avg = EMAMACD[0];

            Average.Set(avg);
            ZeroLine.Set(0);

            //double stdDevValue = StdDev(BBMACD,bandperiod)[0];
            double stdDevValue = SDBB[0];

            Upper.Set(avg + StdDevNumber * stdDevValue);
            Lower.Set(avg - StdDevNumber * stdDevValue);


//			if(Rising(Average))
//				if(paintbars)
//				{
//					BarColor = bbAverageUp;
//					CandleOutlineColor = candleoutlinecolorup;
//				}
//			if(Falling(Average))
//				if(paintbars)
//				{
//					BarColor = bbAverageDn;
//					CandleOutlineColor = candleoutlinecolorup;
//				}

            if (Rising(BBMACD))
            {
                if (BBMACD[0] < Upper[0])
                {
                    PlotColors[0][0] = DotsUpInside;
                    if (showhistogram)
                    {
                        Hist.Set((macdValue - avg));
                        PlotColors[10][0] = DotsUpInside;
                    }
                    updotdrawn = false;                                                 // added by TheWizard March 15, 2011
                }
                else
                {
                    PlotColors[0][0] = DotsUpOutside;
                    if (showhistogram)
                    {
                        Hist.Set((macdValue - avg));
                        PlotColors[10][0] = DotsUpOutside;
                    }
                    if (drawDotOnPricePanel)                                                                          // added by TheWizard March 15, 2011
                    {
                        if (updotdrawn == false)                                                                      // added by TheWizard March 15, 2011
                        {
                            DrawDot("UpDots" + CurrentBar, true, 0, Low[0] - dotSeparation * TickSize, BBdotUpColor); // added by TheWizard March 15, 2011
                            DrawDot("UpDots2" + CurrentBar, true, 0, Low[0] - dotSeparation * (TickSize * 2), BBdotUpColor);
                            updotdrawn   = true;                                                                      // added by TheWizard March 15, 2011
                            downdotdrawn = false;                                                                     // added by TheWizard March 15, 2011
                            if (bbviolationsound)
                            {
                                if (FirstTickOfBar)
                                {
                                    PlaySound(bbviolationupsound);
                                }
                            }
                        }
                    }
                }
                if (paintbars)
                {
                    BarColor           = barcolorup;
                    CandleOutlineColor = candleoutlinecolorup;
                }
            }
            else
            {
                if (BBMACD[0] > Lower[0])
                {
                    PlotColors[0][0] = DotsDownInside;
                    if (showhistogram)
                    {
                        Hist.Set((macdValue - avg));
                        PlotColors[10][0] = DotsDownInside;
                    }
                    downdotdrawn = false;                                       // added by TheWizard March 15, 2011
                }
                else
                {
                    PlotColors[0][0] = DotsDownOutside;
                    if (showhistogram)
                    {
                        Hist.Set((macdValue - avg));
                        PlotColors[10][0] = DotsDownOutside;
                    }
                    if (drawDotOnPricePanel)                                                                           // added by TheWizard March 15, 2011
                    {
                        if (downdotdrawn == false)                                                                     // added by TheWizard March 15, 2011
                        {
                            DrawDot("DnDots" + CurrentBar, true, 0, High[0] + dotSeparation * TickSize, BBdotDnColor); // added by TheWizard March 15, 2011
                            DrawDot("DnDots2" + CurrentBar, true, 0, High[0] + dotSeparation * (TickSize * 2), BBdotDnColor);
                            downdotdrawn = true;                                                                       // added by TheWizard March 15, 2011
                            updotdrawn   = false;                                                                      // added by TheWizard March 15, 2011
                            if (bbviolationsound)
                            {
                                if (FirstTickOfBar)
                                {
                                    PlaySound(bbviolationdnsound);
                                }
                            }
                        }
                    }
                }
                if (paintbars)
                {
                    BarColor           = barcolordn;
                    CandleOutlineColor = candleoutlinecolordn;
                }
            }
            if (BBMACD[0] > avg)
            {
                if (conservative)
                {
                    PlotColors[2][0] = BBAverageUp;
                    if (BBMACD[0] > 0)
                    {
                        PlotColors[5][0] = ZeroPositive;
                    }
                    if (BBMACD[0] < 0)
                    {
                        PlotColors[5][0] = ZeroNegative;
                    }
                }
                else
                {
                    PlotColors[2][0] = BBAverageUp;
                    PlotColors[5][0] = ZeroPositive;
                    if (colorbackground)
                    {
                        BackColor = Color.FromArgb(opacity, backgroundcolorUp);
                    }
                    if (colorALLbackgrounds)
                    {
                        BackColorAll = Color.FromArgb(opacity, backgroundcolorUp);
                    }
                }
            }

            if (BBMACD[0] < avg)
            {
                if (conservative)
                {
                    PlotColors[2][0] = BBAverageDn;
                    if (BBMACD[0] > 0)
                    {
                        PlotColors[5][0] = ZeroPositive;
                    }
                    if (BBMACD[0] < 0)
                    {
                        PlotColors[5][0] = ZeroNegative;
                    }
                }
                else
                {
                    PlotColors[2][0] = BBAverageDn;
                    PlotColors[5][0] = ZeroNegative;
                    if (colorbackground)
                    {
                        BackColor = Color.FromArgb(opacity, backgroundcolorDn);
                    }
                    if (colorALLbackgrounds)
                    {
                        BackColorAll = Color.FromArgb(opacity, backgroundcolorDn);
                    }
                }
            }

            //PlotColors[2][0] = BBAverage;
            PlotColors[3][0] = BBUpper;
            PlotColors[4][0] = BBLower;
            PlotColors[6][0] = ZeroCross;
            PlotColors[7][0] = Connector;

            if (BBMACD[0] > 0)
            {
                if (conservative)
                {
                    if (colorbackground)
                    {
                        BackColor = Color.FromArgb(opacity, backgroundcolorUp);
                    }
                    if (colorALLbackgrounds)
                    {
                        BackColorAll = Color.FromArgb(opacity, backgroundcolorUp);
                    }
                }
                if (CurrentBar != 0 && BBMACD[1] <= 0)
                {
                    MACDCross.Set(0);
                    if (zerolinecrosssound)
                    {
                        if (FirstTickOfBar)
                        {
                            PlaySound(longwavfilename);
                        }
                    }
                }

                else
                {
                    MACDCross.Reset();
                }
            }
            else
            {
                if (conservative)
                {
                    if (colorbackground)
                    {
                        BackColor = Color.FromArgb(opacity, backgroundcolorDn);
                    }
                    if (colorALLbackgrounds)
                    {
                        BackColorAll = Color.FromArgb(opacity, backgroundcolorDn);
                    }
                }
                if (CurrentBar != 0 && BBMACD[1] > 0)
                {
                    MACDCross.Set(0);
                    if (zerolinecrosssound)
                    {
                        if (FirstTickOfBar)
                        {
                            PlaySound(shortwavfilename);
                        }
                    }
                }
                else
                {
                    MACDCross.Reset();
                }
            }
        }
コード例 #3
0
ファイル: StdDev.cs プロジェクト: redrhino/NinjaTrader.Base
        /// <summary>
        /// Standard Deviation is a statistical measure of volatility. Standard Deviation is typically used as a component of other indicators, rather than as a stand-alone indicator. For example, Bollinger Bands are calculated by adding a security's Standard Deviation to a moving average.
        /// </summary>
        /// <returns></returns>
        public StdDev StdDev(Data.IDataSeries input, int period)
        {
            if (cacheStdDev != null)
                for (int idx = 0; idx < cacheStdDev.Length; idx++)
                    if (cacheStdDev[idx].Period == period && cacheStdDev[idx].EqualsInput(input))
                        return cacheStdDev[idx];

            lock (checkStdDev)
            {
                checkStdDev.Period = period;
                period = checkStdDev.Period;

                if (cacheStdDev != null)
                    for (int idx = 0; idx < cacheStdDev.Length; idx++)
                        if (cacheStdDev[idx].Period == period && cacheStdDev[idx].EqualsInput(input))
                            return cacheStdDev[idx];

                StdDev indicator = new StdDev();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
                indicator.Input = input;
                indicator.Period = period;
                Indicators.Add(indicator);
                indicator.SetUp();

                StdDev[] tmp = new StdDev[cacheStdDev == null ? 1 : cacheStdDev.Length + 1];
                if (cacheStdDev != null)
                    cacheStdDev.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheStdDev = tmp;
                return indicator;
            }
        }
コード例 #4
0
        /// <summary>
        /// Calculates the indicator value(s) at the current index.
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBars[0] < bandperiod)
            {
                return;
            }

            if (!init)
            {
                BMACD   = MACD(Input, fast, slow, smooth);
                EMAMACD = EMA(BMACD, bandperiod);
                HMAMACD = HMA(BMACD, smooth);
                SDBB    = StdDev(BMACD, bandperiod);
            }
            init = true;
            double macdValue = HMAMACD[0];            //BMACD[0];

            BBMACD.Set(macdValue);
            //BBMACDLine.Set(macdValue);
            BBMACDFrame.Set(macdValue);

            //double avg = EMA(BBMACD,bandperiod)[0];
            double avg = EMAMACD[0];

            ZeroLine.Set(0);

            //double stdDevValue = StdDev(BBMACD,bandperiod)[0];
            double stdDevValue = SDBB[0];

            Upper.Set(avg + StdDevNumber * stdDevValue);
            Lower.Set(avg - StdDevNumber * stdDevValue);

            //1. Green dots, above bands, sloping up Green dot - text UP - prefer up as easy to understand
            //2. Green dots, above bands, changing to a red dot. - Cell Colour will Change (but may still say UP)
            //3. Consecutive red dots crossing down through the bands - not sure we discussed this one!!! Cell colour will change Put --- to indicate crossing down
            //4. Red dots, below bands, sloping down.Red dot - text DOWN - prefer DOWN as easy to understand
            //5. Red dots, below bands, changing to a green dot.ell Colour will Change (but may still say DOWN)
            //6. Consecutive green dots, crossing up through the bands - not sure we discussed this one!!! Cell colour will change Put +++ to indicate crossing down

            //1 & 4 - would be trending signals - don't trade against these
            //2 & 5 - would be minor alerts for consolidation or the start of direction change
            //3 & 6 - would be major alerts with direction change confirmed by dots about to break through the opposite band



            if (Rising(BBMACD))
            {
                if (BBMACD[0] < Upper[0])
                {
                    PlotColors[0][0] = DotsUpInside;
                    macdsignal       = 1;
                }
                else if ((BBMACD[1] < Upper[1]) && (BBMACD[0] > Upper[0]))
                {
                    PlotColors[0][0] = DotsUpOutside;
                    macdsignal       = 2;
                }
                else
                {
                    PlotColors[0][0] = DotsUpOutside;
                    macdsignal       = 3;
                }
            }
            else
            {
                if (BBMACD[0] > Lower[0])
                {
                    PlotColors[0][0] = DotsDownInside;
                    macdsignal       = -1;
                }
                else if ((BBMACD[1] > Lower[1]) && (BBMACD[0] < Lower[0]))
                {
                    PlotColors[0][0] = DotsDownOutside;
                    macdsignal       = -2;
                }

                else
                {
                    PlotColors[0][0] = DotsDownOutside;
                    macdsignal       = -3;
                }
            }


            Signal.Set(macdsignal);



/*
 *
 *                              if (BBMACD[0] > BBMACD[1])
 *          {
 *              PlotColors[0][0] = DotsUpOutside;
 *              if ((BBMACD[0] > Upper[0]))  //UP
 *              {
 *                  macdsignal = 1;
 *                  PlotColors[0][0] = DotsUpOutside;
 *              }
 *              else if ((BBMACD[1] < Lower[1]) && (BBMACD[0] > Lower[0]))  //UP
 *              {
 *                  macdsignal = 6;
 *                  PlotColors[0][0] = DotsDownInside;
 *              }
 *              else if ((BBMACD[1] > BBMACD[2]) && (BBMACD[0] > Lower[0]))   //UP
 *              {
 *                  macdsignal = 7;
 *                  PlotColors[0][0] = DotsUpInside;
 *              }
 *              else if ((BBMACD[1] < Upper[1]) && (BBMACD[0] > Upper[0]))    //UP
 *              {
 *                  macdsignal = 8;
 *                  PlotColors[0][0] = DotsUpOutside;
 *              }
 *          }
 *          else //(BBMACD[0] < BBMACD[1])
 *          {
 *              PlotColors[0][0] = DotsDownOutside;
 *              if ((BBMACD[0] < Lower[0]))  //DN
 *              {
 *                  macdsignal = 5;
 *                  PlotColors[0][0] = DotsDownOutside;
 *              }
 *              else if ((BBMACD[0] < BBMACD[1]))  //DN
 *              {
 *                  macdsignal = 2;
 *                  PlotColors[0][0] = DotsDownOutside;
 *              }
 *              else if ((BBMACD[1] < BBMACD[2]) && (BBMACD[0] < Upper[0]))   //DN
 *              {
 *                  macdsignal = 3;
 *                  PlotColors[0][0] = DotsDownInside;
 *              }
 *              else if ((BBMACD[1] > Lower[1]) && (BBMACD[0] < Lower[0]))    //DN
 *              {
 *                  macdsignal = 4;
 *                  PlotColors[0][0] = DotsDownOutside;
 *              }
 *          }
 */
/*
 *          if ((BBMACD[0] > BBMACD[1]) && (BBMACD[0] > Upper[0]))  //UP
 *          {
 *              macdsignal = 1;
 *              PlotColors[0][0] = DotsUpOutside;
 *          }
 *          if ((BBMACD[1] > Upper[1]) && (BBMACD[0] < BBMACD[1]))  //DN
 *          {
 *              macdsignal = 2;
 *              PlotColors[0][0] = DotsDownOutside;
 *          }
 *          if ((BBMACD[0] < BBMACD[1]) && (BBMACD[1] < BBMACD[2]) && (BBMACD[0] < Upper[0]))   //DN
 *          {
 *              macdsignal = 3;
 *              PlotColors[0][0] = DotsDownInside;
 *          }
 *          if ((BBMACD[0] < BBMACD[1]) && (BBMACD[1] > Lower[1]) && (BBMACD[0] < Lower[0]))    //DN
 *          {
 *              macdsignal = 4;
 *              PlotColors[0][0] = DotsDownOutside;
 *          }
 *
 *          if ((BBMACD[0] < BBMACD[1]) && (BBMACD[0] < Lower[0]))  //DN
 *          {
 *              macdsignal = 5;
 *              PlotColors[0][0] = DotsDownOutside;
 *          }
 *          if ((BBMACD[1] < Lower[1]) && (BBMACD[0] > BBMACD[1]))  //UP
 *          {
 *              macdsignal = 6;
 *              PlotColors[0][0] = DotsDownInside;
 *          }
 *          if ((BBMACD[0] > BBMACD[1]) && (BBMACD[1] > BBMACD[2]) && (BBMACD[0] > Lower[0]))   //UP
 *          {
 *              macdsignal = 7;
 *              PlotColors[0][0] = DotsUpInside;
 *          }
 *          if ((BBMACD[0] > BBMACD[1]) && (BBMACD[1] < Upper[1]) && (BBMACD[0] > Upper[0]))    //UP
 *          {
 *              macdsignal = 8;
 *              PlotColors[0][0] = DotsUpOutside;
 *          }
 */


            /////PlotColors[2][0] = BBUpper;
            /////PlotColors[3][0] = BBLower;
            /////PlotColors[4][0] = SignalCol;
            /////PlotColors[5][0] = ZeroCol;
        }