Exemple #1
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Use this method for calculating your indicator values. Assign a value to each
            // plot below by replacing 'Close[0]' with your own formula.

            if (CurrentBar < period)
            {
                return;
            }

            double value = CCI(period)[0];

            if (value > 200)
            {
                BackColor          = Color.PaleGreen;
                BarColor           = Color.Yellow;
                CandleOutlineColor = Color.Black;
            }
            else if (value > 150)
            {
                BackColor = Color.PaleGreen;
            }
            else if (value < -200)
            {
                BackColor          = Color.Pink;
                BarColor           = Color.Yellow;
                CandleOutlineColor = Color.Black;
            }
            else if (value < -150)
            {
                BackColor = Color.Pink;
            }



            Above.Set(value);
            Neutral.Set(value);
            Below.Set(value);
        }
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (newbarsound)
            {
                if (FirstTickOfBar)
                {
                    PlaySound(newbarwavfilename);                                           // Added by TheWizard 02/06/10
                }
            }
            if (CurrentBar < 2)

            {
                PDM.Set(0);
                MDM.Set(0);
                PDI.Set(0);
                MDI.Set(0);
                Out.Set(0);
                Main.Set(0);
                Rising.Set(0);
                Falling.Set(0);
                Neutral.Set(0);
                return;
            }
            try
            {
                if (lastCalcBar != CurrentBar)
                {
                    lastCalcBar = CurrentBar;
//					setData( data, 0, 0d );
//					colorBar( 1 );
                    lastDirection = direction;
                }

                int i = 0;
                PDM.Set(0);
                MDM.Set(0);
                if (Close[i] > Close[i + 1])
                {
                    PDM.Set(Close[i] - Close[i + 1]);                  //This array is not displayed.
                }
                else
                {
                    MDM.Set(Close[i + 1] - Close[i]);                       //This array is not displayed.
                }
                PDM.Set(((WeightDM - 1) * PDM[i + 1] + PDM[i]) / WeightDM); //ema.
                MDM.Set(((WeightDM - 1) * MDM[i + 1] + MDM[i]) / WeightDM); //ema.

                double TR = PDM[i] + MDM[i];

                if (TR > 0)
                {
                    PDI.Set(PDM[i] / TR);
                    MDI.Set(MDM[i] / TR);
                }                //Avoid division by zero. Minimum step size is one unnormalized price pip.
                else
                {
                    PDI.Set(0);
                    MDI.Set(0);
                }

                PDI.Set(((WeightDI - 1) * PDI[i + 1] + PDI[i]) / WeightDI);        //ema.
                MDI.Set(((WeightDI - 1) * MDI[i + 1] + MDI[i]) / WeightDI);        //ema.

                double DI_Diff = PDI[i] - MDI[i];
                if (DI_Diff < 0)
                {
                    DI_Diff = -DI_Diff;                   //Only positive momentum signals are used.
                }
                double DI_Sum    = PDI[i] + MDI[i];
                double DI_Factor = 0;              //Zero case, DI_Diff will also be zero when DI_Sum is zero.
                if (DI_Sum > 0)
                {
                    Out.Set(DI_Diff / DI_Sum);                  //Factional, near zero when PDM==MDM (horizonal), near 1 for laddering.
                }
                else
                {
                    Out.Set(0);
                }

                Out.Set(((WeightDX - 1) * Out[i + 1] + Out[i]) / WeightDX);

                if (Out[i] > Out[i + 1])
                {
                    HHV = Out[i];
                    LLV = Out[i + 1];
                }
                else
                {
                    HHV = Out[i + 1];
                    LLV = Out[i];
                }

                for (int j = 1; j < Math.Min(ADXPeriod, CurrentBar); j++)
                {
                    if (Out[i + j + 1] > HHV)
                    {
                        HHV = Out[i + j + 1];
                    }
                    if (Out[i + j + 1] < LLV)
                    {
                        LLV = Out[i + j + 1];
                    }
                }


                double diff = HHV - LLV;    //Veriable reference scale, adapts to recent activity level, unnormalized.
                double VI   = 0;            //Zero case. This fixes the output at its historical level.
                if (diff > 0)
                {
                    VI = (Out[i] - LLV) / diff;              //Normalized, 0-1 scale.
                }
                //   if (VI_0.VIsq_1.VIsqroot_2==1)VI*=VI;
                //   if (VI_0.VIsq_1.VIsqroot_2==2)VI=MathSqrt(VI);
                //   if (VI>VImax)VI=VImax;//Used by Bemac with VImax=0.4, still used in vma1 and affects 5min trend definition.
                //All the ema weight settings, including Chande, affect 5 min trend definition.
                //   if (VI<=zeroVIbelow)VI=0;

                main.Set(((ChandeEMA - VI) * main[i + 1] + VI * Close[i]) / ChandeEMA);    //Chande VMA formula with ema built in.
                bool rising  = false;
                bool falling = false;

                if (conservativemode)
                {
                    if (main[0] > main[1])
                    {
                        Rising.Set(main[0]);
                        if (main[1] <= main[2] && Plots[0].PlotStyle == PlotStyle.Line)
                        {
                            Rising.Set(1, main[1]);
                        }
                        rising = true;
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorUp);            // added By TheWizard 02/06/10
                        }

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = Color.Transparent;
                                CandleOutlineColor = barColorUp;
                            }
                            else
                            {
                                BarColor = BarColorUp;
                            }
                        }
                    }
                    else if (main[0] < main[1])
                    {
                        Falling.Set(main[0]);
                        if (main[1] >= main[2] && Plots[1].PlotStyle == PlotStyle.Line)
                        {
                            Falling.Set(1, main[1]);
                        }
                        falling = true;

                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorDn);            // added By TheWizard 02/06/10
                        }

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = Color.Transparent;
                                CandleOutlineColor = barColorDown;
                            }
                            else
                            {
                                BarColor = BarColorDown;
                            }
                        }
                    }
                    else
                    {
                        Neutral.Set(main[0]); Neutral.Set(1, main[1]);
                        rising = false; falling = false;

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = BarColorNeutral;
                                CandleOutlineColor = BarColorOutline;
                            }
                            else
                            {
                                BarColor = BarColorNeutral;
                            }
                        }
                    }
                }

                if (!conservativemode)
                {
                    if (main[0] > main[1])
                    {
                        Rising.Set(main[0]); Rising.Set(1, main[1]);
                        rising = true;
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorUp);            // added By TheWizard 02/06/10
                        }

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = Color.Transparent;
                                CandleOutlineColor = barColorUp;
                            }
                            else
                            {
                                BarColor = BarColorUp;
                            }
                        }
                    }
                    else if (main[0] < main[1])
                    {
                        Falling.Set(main[0]); Falling.Set(1, main[1]);
                        falling = true;
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorDn);            // added By TheWizard 02/06/10
                        }

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = Color.Transparent;
                                CandleOutlineColor = barColorDown;
                            }
                            else
                            {
                                BarColor = BarColorDown;
                            }
                        }
                    }
                    else if (main[0] == main[0] && Median[0] > main[0])
                    {
                        Rising.Set(main[0]); Rising.Set(1, main[1]);
                        rising = true;
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorUp);            // added By TheWizard 02/06/10
                        }

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = Color.Transparent;
                                CandleOutlineColor = barColorUp;
                            }
                            else
                            {
                                BarColor = BarColorUp;
                            }
                        }
                    }
                    else if (main[0] == main[0] && Median[0] < main[0])
                    {
                        Falling.Set(main[0]); Falling.Set(1, main[1]);
                        falling = true;
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorDn);            // added By TheWizard 02/06/10
                        }

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = Color.Transparent;
                                CandleOutlineColor = barColorDown;
                            }
                            else
                            {
                                BarColor = BarColorDown;
                            }
                        }
                    }
                    else
                    {
                        Neutral.Set(main[0]); Neutral.Set(1, main[1]);
                        rising = false; falling = false;

                        if (ColorBars)
                        {
                            if (ChartControl.ChartStyleType == ChartStyleType.CandleStick)              // modified by TheWizard Feb 5, 2010 to allow for hollow-style candlesticks
                            {
                                BarColor           = BarColorNeutral;
                                CandleOutlineColor = BarColorOutline;
                            }
                            else
                            {
                                BarColor = BarColorNeutral;
                            }
                        }
                    }
                }


                if (rising)
                {
                    Signal.Set(1);
                    if (colorbackground)
                    {
                        BackColor = Color.FromArgb(opacity, BackColorUp);                // added By TheWizard 02/06/10
                    }
                }
                else if (falling)
                {
                    Signal.Set(-1);
                    if (colorbackground)
                    {
                        BackColor = Color.FromArgb(opacity, BackColorDn);                // added By TheWizard 02/06/10
                    }
                }
                else
                {
                    Signal.Set(0);
                }
                if (Signal[0] == 0 && Signal[1] != 0)
                {
                    if (showDiamonds && CurrentBar >= 0)
                    {
                        double val1 = Neutral[i + 1] + (TickSize * DiamondDisplacement);
                        double val2 = Neutral[i + 1] - (TickSize * DiamondDisplacement);
                        DrawDiamond("topdiamond" + CurrentBar.ToString(), false, 1, val1, DiamondColor);
                        DrawDiamond("botdiamond" + CurrentBar.ToString(), false, 1, val2, DiamondColor);
                    }

                    if (diamondsoundon && FirstTickOfBar)
                    {
                        PlaySound(diamondalertwavfilename);
                    }
//					Print("Signal: " +Signal.ToString());
                }
                if (ShowArrows && CurrentBar >= 0)       //> 2)
                {
                    //if( lastDirection < direction )
                    if (Signal[0] == 1 && Signal[1] != 1)
                    {
                        double val = Low[i + 1] - (TickSize * ArrowDisplacement);
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorUp);            // added By TheWizard 02/06/10
                        }
                        if (FirstTickOfBar)
                        {
                            DrawArrowUp(CurrentBar.ToString(), 1, val, barColorUp);
                        }
                        //data[ data.Count - 1] = val  * -1;
                        //setData( data, bar, val  * -1 );
                        if (arrowsoundon && FirstTickOfBar)
                        {
                            PlaySound(longwavfilename);
                        }
                    }
                    //else if( lastDirection > direction )
                    else if (Signal[0] == -1 && Signal[1] != -1)
                    {
                        double val = High[i + 1] + (TickSize * ArrowDisplacement);
                        if (colorbackground)
                        {
                            BackColor = Color.FromArgb(opacity, BackColorDn);            // added By TheWizard 02/06/10
                        }
                        if (FirstTickOfBar)
                        {
                            DrawArrowDown(CurrentBar.ToString(), 1, val, barColorDown);
                        }
                        if (arrowsoundon && FirstTickOfBar)
                        {
                            PlaySound(shortwavfilename);
                        }
                        //setData( data, bar, val );
                    }
                }
//--Text Box Info--//

//			double ECOminus = Math.Abs(eco[1]-eco[0]);
//			double ECOplus = Math.Abs(eco[0]-eco[1]);

                if (textOnLeft)
                {
                    if (textOnTop)
                    {
                        tPosition = TextPosition.TopLeft;
                    }
                    else
                    {
                        bPosition = TextPosition.BottomLeft;
                    }
                }
                else
                {
                    if (!textOnTop)
                    {
                        bPosition = TextPosition.BottomRight;
                    }
                    else
                    {
                        tPosition = TextPosition.TopRight;
                    }
                }

                if (showText)
                {
                    if (Signal[0] == 1)
                    {
                        DrawTextFixed("Rising", " RISING ", tPosition, Color.White, textFontMed, Color.Black, Color.Blue, 10);
                    }
                    else
                    {
                        RemoveDrawObject("Rising");
                    }

                    if (Signal[0] == -1)
                    {
                        DrawTextFixed("Falling", " FALLING ", tPosition, Color.White, textFontMed, Color.Black, Color.Red, 10);
                    }
                    else
                    {
                        RemoveDrawObject("Falling");
                    }

                    if (Signal[0] == 0)
                    {
                        DrawTextFixed("Neutral", " NEUTRAL ", tPosition, Color.Black, textFontMed, Color.Black, Color.Goldenrod, 3);
                    }
                    else
                    {
                        RemoveDrawObject("Neutral");
                    }
                }
            }
            catch (Exception ex)
            {
                Print(ex.ToString());
            }
        }
Exemple #3
0
        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            if (CurrentBar < length)
            {
                return;
            }


            LRReversal.Set(LinReg(Close, Length)[0]);
            lRR.Set(LinReg(Close, Length)[0]);
            if (LRReversal[0] >= LRReversal[1])
            {
                lRR[0] = 1;
            }
            else
            {
                lRR[0] = -1;
            }


            bool rising  = false;
            bool falling = false;

            if (lRR[0] == 1)            //> lRR[1])
            {
                Rising.Set(lRR[0]);     //Rising.Set(1, lRR[1]);
                rising = true;

//					if (ColorBars)
//					{ CandleOutlineColor = BarColorOutline; BarColor = BarColorUp; }
            }
//				else
            if (lRR[0] == -1)                    //< lRR[1])
            {
                Falling.Set(lRR[0]);             //Falling.Set(1, lRR[1]);
                falling = true;

//					if (ColorBars)
//					{ CandleOutlineColor = BarColorOutline; BarColor = BarColorDown; }
            }

            //else
            if                     //((lRR[0] > lRR[1]) || (lRR[0] < lRR[1]))
            ((lRR[1] == 1 && lRR[0] == -1) || (lRR[1] == -1 && lRR[0] == 1))
            {
                Neutral.Set(lRR[0]);
                Neutral.Set(1, lRR[1]);
                rising = false; falling = false;

//					if (ColorBars)
//					{ CandleOutlineColor = BarColorOutline; BarColor = BarColorNeutral; }
            }



///////////////////////////////////////////////////////////////////////////////////////////////
            /// draw dot at second instance of +1 or -1
            ///////////////////////////////////////////////////////////////////////////////////
            if (drawDots)
            {
                if (LRR[2] == -1 &&
                    LRR[1] == 1 &&
                    LRR[0] == 1
                    )
                {
                    DrawDot("Dot" + CurrentBar, false, 0, 0, Color.Blue);
                    signal.Set(1);
                }
                else if (LRR[2] == 1 &&
                         LRR[1] == -1 &&
                         LRR[0] == -1
                         )
                {
                    DrawDot("Dot" + CurrentBar, false, 0, 0, Color.Red);
                    signal.Set(-1);
                }
                else
                {
                    RemoveDrawObject("Dot");
                }
            }

            if (signal[1] != 1 &&
                signal[0] == 1)
            {
                if (DrawLines)
                {
                    DrawVerticalLine("tag1l" + CurrentBar, 0, Color.Blue, DashStyle.DashDot, 3);
                    //DrawDot("tag1d"+CurrentBar,false,0,Low[0] - 8*TickSize,Color.Blue);
                }
            }
            if (signal[1] != -1 &&
                signal[0] == -1)
            {
                if (DrawLines)
                {
                    DrawVerticalLine("tag2l" + CurrentBar, 0, Color.Red, DashStyle.DashDot, 3);
                    //DrawDot("tag2d"+CurrentBar,false,0,High[0] + 8*TickSize,Color.Red);
                }
            }
        }