コード例 #1
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();
                }
            }
        }
コード例 #2
0
ファイル: anaMACDBBLines.cs プロジェクト: hmgl/TradingStudies
        protected override void OnBarUpdate()
        {
            double macdValue = BMACD[0];

            BBMACD.Set(macdValue);
            BBMACDLine.Set(macdValue);
            BBMACDFrame.Set(macdValue);
            double avg = BMACD.Avg[0];

            Average.Set(avg);
            ZeroLine.Set(0);
            double stdDevValue = SDBB[0];

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

            if (Rising(BBMACD))
            {
                if (macdValue > avg + StdDevNumber * stdDevValue)
                {
                    PlotColors[0][0] = DotsUpOutside;
                }
                else
                {
                    PlotColors[0][0] = DotsUpInside;
                }
            }
            else
            {
                if (macdValue < avg - StdDevNumber * stdDevValue)
                {
                    PlotColors[0][0] = DotsDownOutside;
                }
                else
                {
                    PlotColors[0][0] = DotsDownInside;
                }
            }
            if (BBMACD[0] > 0)
            {
                PlotColors[5][0] = ZeroPositive;
                if (CurrentBar != 0 && BBMACD[1] <= 0)
                {
                    MACDCross.Set(0);
                }
                else
                {
                    MACDCross.Reset();
                }
            }
            else
            {
                PlotColors[5][0] = ZeroNegative;
                if (CurrentBar != 0 && BBMACD[1] > 0)
                {
                    MACDCross.Set(0);
                }
                else
                {
                    MACDCross.Reset();
                }
            }
        }