Esempio n. 1
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 2)
            {
                _uSigma[0] = Input[0];
                _lSigma[0] = Input[0];
                return;
            }

            setWeights();

            double input = Input[0];//(CurrentBar > 0) ? Value[1] : Input[0];//SMA(Input, 1)[0];

            double uDelta = input - _uSigma[1];
            double lDelta = input - _lSigma[1];
            double uAbs   = Math.Abs(uDelta);
            double lAbs   = Math.Abs(lDelta);

            if (uAbs > lAbs)
            {
                _vx[0] = uAbs;
            }
            if (uAbs < lAbs)
            {
                _vx[0] = lAbs;
            }
            if (uAbs == lAbs)
            {
                _vx[0] = 0;
            }


            _vxAvg[0] = _vxAvg[1] + 0.1 * (_vx[0] - _vx[Math.Min(CurrentBar, 10)]);

            _vxTrend[0] = SMA(_vxAvg, Math.Min(CurrentBar, 65))[0];
            if (CurrentBar <= 64)
            {
                _vxTrend[0] = _vxTrend[1] + 2 * (_vxAvg[0] - _vxTrend[1]) / (65);
            }

            double vxCoeff = 0d;

            if (_vxTrend[0] > 0)
            {
                vxCoeff = _vx[0] / _vxTrend[0];
            }
            vxCoeff = Math.Min(Math.Pow(_lengthParam, 1 / _expFactor), vxCoeff);
            if (vxCoeff < 1)
            {
                vxCoeff = 1.0;
            }

            double vExp = Math.Pow(vxCoeff, _expFactor);
            double kV   = Math.Pow(_beta, Math.Sqrt(vExp));

            double gamma = _windowLength / (_windowLength + 2);
            double alpha = Math.Pow(gamma, vExp);

            _uSigma[0] = (uDelta > 0) ? input : input - kV * uDelta;
            _lSigma[0] = (lDelta < 0) ? input : input - kV * lDelta;


            int bar = CurrentBar;

            double[] bank = new double[5];
            fbank[bar] = bank;
            if (bar == 2)
            {
                bank[0] = input;
                bank[2] = input;
                bank[4] = input;
            }
            else
            {
                bank[0] = (1 - alpha) * input + alpha * fbank[bar - 1][0];                                                   //level component
                bank[1] = (input - bank[0]) * (1 - gamma) + gamma * fbank[bar - 1][1];                                       //trend component
                bank[2] = bank[0] + _permissivity * bank[1];                                                                 //apriori prediction
                bank[3] = (bank[2] - fbank[bar - 1][4]) * Math.Pow((1 - alpha), 2) + Math.Pow(alpha, 2) * fbank[bar - 1][3]; //error (innovation)
                bank[4] = fbank[bar - 1][4] + bank[3];                                                                       //posteriori mean
            }

            RawTrend.Set(bank[1]);
            Prediction.Set(bank[3]);

            DrawDots();

            if (_drawZLR)
            {
                CatchZLR();
            }
            if (drawVerticalLineOnPricePanel)
            {
                if (CrossAbove(Prediction, 0, 1))
                {
                    DrawVerticalLine("MyVerticalLine", 0, vlineUpColor, DashStyle.Dash, vlineWidth);                   // added by TheWizard December 23, 2009
                }
                else if (CrossBelow(Prediction, 0, 1))
                {
                    DrawVerticalLine("MyVerticalLine", 0, vlineDnColor, DashStyle.Dash, vlineWidth);                   // added by TheWizard December 23, 2009
                }
//				if(CrossAbove(RawTrend,Prediction,1))
//				{
//					DrawVerticalLine("MyVerticalLine", 0,vlineWarningColor,DashStyle.Dash,vlineWidth); // added by TheWizard December 28, 2009
//				}
//				else if (CrossBelow(RawTrend,Prediction,1))
//				{
//					DrawVerticalLine("MyVerticalLine", 0,vlineWarningColor,DashStyle.Dash,vlineWidth); // added by TheWizard December 28, 2009
//				}
            }
            if (soundOn)
            {
// ORIGINAL CODE
//				if(CrossAbove(Prediction, 0, 1))
//				{
//					PlaySound(longWavefilename);
//					BarAtLastCross=CurrentBar;
//					Alert("Ready",NinjaTrader.Cbi.Priority.High,"Ready","long.wav",4,Color.Black,Color.Yellow);
//				}
//				else if (CrossBelow(Prediction, 0, 1))
//				{
//					PlaySound(shortWavefilename);
//					BarAtLastCross=CurrentBar;
//					Alert("Ready",NinjaTrader.Cbi.Priority.High,"Ready","short.wav",4,Color.Black,Color.Yellow);
//				}
//  DAVIDHP's MODIFIED CODE:
                if (CrossAbove(Prediction, 0, 1))
                {
                    if (FirstTickOfBar) // added by TheWizard December 23, 2009
                    {
                        Alert("Ready", NinjaTrader.Cbi.Priority.High, "Ready", "long.wav", 4, Color.Black, Color.Yellow);
                    }
//copied the line below from ADXVMA_Alerts_Rjay & modified, slightly
                    if (_drawInfo)
                    {
                        DrawArrowUp(CurrentBar.ToString(), 0, Low[1] - TickSize, Color.FromKnownColor(KnownColor.Blue));
                    }
                }
                else if (CrossBelow(Prediction, 0, 1))
                {
                    if (FirstTickOfBar) // added by TheWizard December 23, 2009
                    {
                        Alert("Ready", NinjaTrader.Cbi.Priority.High, "Ready", "short.wav", 4, Color.Black, Color.Yellow);
                    }
//copied the line below from ADXVMA_Alerts_Rjay & modified, slightly
                    if (_drawInfo)
                    {
                        DrawArrowDown(CurrentBar.ToString(), 0, High[1] + TickSize, Color.FromKnownColor(KnownColor.Red));
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void OnBarUpdate()
        {
            if (CurrentBar < 2)
            {
                _uSigma[0] = Input[0];
                _lSigma[0] = Input[0];
                return;
            }

            setWeights();

            double input = Input[0];//(CurrentBar > 0) ? Value[1] : Input[0];//SMA(Input, 1)[0];

            double uDelta = input - _uSigma[1];
            double lDelta = input - _lSigma[1];
            double uAbs   = Math.Abs(uDelta);
            double lAbs   = Math.Abs(lDelta);

            if (uAbs > lAbs)
            {
                _vx[0] = uAbs;
            }
            if (uAbs < lAbs)
            {
                _vx[0] = lAbs;
            }
            if (uAbs == lAbs)
            {
                _vx[0] = 0;
            }


            _vxAvg[0] = _vxAvg[1] + 0.1 * (_vx[0] - _vx[Math.Min(CurrentBar, 10)]);

            _vxTrend[0] = SMA(_vxAvg, Math.Min(CurrentBar, 65))[0];
            if (CurrentBar <= 64)
            {
                _vxTrend[0] = _vxTrend[1] + 2 * (_vxAvg[0] - _vxTrend[1]) / (65);
            }

            double vxCoeff = 0d;

            if (_vxTrend[0] > 0)
            {
                vxCoeff = _vx[0] / _vxTrend[0];
            }
            vxCoeff = Math.Min(Math.Pow(_lengthParam, 1 / _expFactor), vxCoeff);
            if (vxCoeff < 1)
            {
                vxCoeff = 1.0;
            }

            double vExp = Math.Pow(vxCoeff, _expFactor);
            double kV   = Math.Pow(_beta, Math.Sqrt(vExp));

            double gamma = _windowLength / (_windowLength + 2);
            double alpha = Math.Pow(gamma, vExp);

            _uSigma[0] = (uDelta > 0) ? input : input - kV * uDelta;
            _lSigma[0] = (lDelta < 0) ? input : input - kV * lDelta;


            int bar = CurrentBar;

            double[] bank = new double[5];
            fbank[bar] = bank;
            if (bar == 2)
            {
                bank[0] = input;
                bank[2] = input;
                bank[4] = input;
            }
            else
            {
                bank[0] = (1 - alpha) * input + alpha * fbank[bar - 1][0];                                                   //level component
                bank[1] = (input - bank[0]) * (1 - gamma) + gamma * fbank[bar - 1][1];                                       //trend component
                bank[2] = bank[0] + _permissivity * bank[1];                                                                 //apriori prediction
                bank[3] = (bank[2] - fbank[bar - 1][4]) * Math.Pow((1 - alpha), 2) + Math.Pow(alpha, 2) * fbank[bar - 1][3]; //error (innovation)
                bank[4] = fbank[bar - 1][4] + bank[3];                                                                       //posteriori mean
            }

            RawTrend.Set(bank[1]);
            Prediction.Set(bank[3]);


            DrawDots();
            if (_drawZLR)
            {
                CatchZLR();
            }
            if (alertonrawtrend)                // Added by TheWizard October 25, 2009
            {
                if (CrossAbove(RawTrend, 0, 1)) // Added by TheWizard October 25, 2009
                {
                    uptrend = true; downtrend = false;
//					BackColor = Color.FromArgb(50,Color.DodgerBlue);  // Added by TheWizard December 10, 2009
                    if (soundOn)
                    {
                        if (FirstTickOfBar)
                        {
                            Alert("Ready", NinjaTrader.Cbi.Priority.High, "Ready", longWavefilename, 4, Color.Black, Color.Yellow);                            // Added by Wizard October 25, 2009
                        }
                    }
                    if (showArrows)
                    {
                        DrawArrowUp(CurrentBar.ToString(), true, 0, Low[0] - (TickSize * ArrowDisplacement), Color.DarkGreen);                                // Added by Wizard October 25, 2009
                    }
                }
                else if (CrossBelow(RawTrend, 0, 1))                  // Added by TheWizard October 25, 2009
                {
                    downtrend = true; uptrend = false;
//					BackColor = Color.FromArgb(50,Color.DeepPink);  // Added by TheWizard December 10, 2009
                    if (soundOn)
                    {
                        if (FirstTickOfBar)
                        {
                            Alert("Ready", NinjaTrader.Cbi.Priority.High, "Ready", shortWavefilename, 4, Color.Black, Color.Yellow);                            // Added by Wizard October 25, 2009
                        }
                    }
                    if (showArrows)
                    {
                        DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + (TickSize * ArrowDisplacement), Color.DarkRed);                                // Added by Wizard October 25, 2009
                    }
                }
            }
            else
            {
                if (CrossAbove(Prediction, 0, 1))                 // Added by TheWizard October 25, 2009
                {
                    uptrend = true; downtrend = false;
                    if (soundOn)
                    {
                        if (FirstTickOfBar)
                        {
                            Alert("Ready", NinjaTrader.Cbi.Priority.High, "Ready", longWavefilename, 4, Color.Black, Color.Yellow);                            // Added by Wizard October 25, 200
                        }
                    }
                    if (showArrows)
                    {
                        DrawArrowUp(CurrentBar.ToString(), true, 0, Low[0] - (TickSize * ArrowDisplacement), Color.DarkGreen);                                // Added by Wizard October 25, 2009
                    }
                }
                else if (CrossBelow(Prediction, 0, 1))                  // Added by TheWizard October 25, 2009
                {
                    downtrend = true; uptrend = false;
                    if (soundOn)
                    {
                        if (FirstTickOfBar)
                        {
                            Alert("Ready", NinjaTrader.Cbi.Priority.High, "Ready", shortWavefilename, 4, Color.Black, Color.Yellow);                            // Added by Wizard October 25, 2009
                        }
                    }
                    if (showArrows)
                    {
                        DrawArrowDown(CurrentBar.ToString(), true, 0, High[0] + (TickSize * ArrowDisplacement), Color.DarkRed);                                // Added by Wizard October 25, 2009
                    }
                }
            }
            if (uptrend)
            {
                BackColor = Color.FromArgb(opacity, BackGroundUpColor);
            }
            if (downtrend)
            {
                BackColor = Color.FromArgb(opacity, BackGroundDnColor);
            }
        }
Esempio n. 3
0
 protected override void OnBarUpdate()
 {
     if (CurrentBar < 2)
     {
         uSigma[0] = Input[0];
         lSigma[0] = Input[0];
     }
     else
     {
         SetWeights();
         double num  = Input[0];
         double num2 = num - uSigma[1];
         double num3 = num - lSigma[1];
         double num4 = Math.Abs(num2);
         double num5 = Math.Abs(num3);
         if (num4 > num5)
         {
             vx[0] = num4;
         }
         if (num4 < num5)
         {
             vx[0] = num5;
         }
         if (Math.Abs(num4 - num5) < double.Epsilon)
         {
             vx[0] = 0.0;
         }
         vxAvg[0]   = vxAvg[1] + (0.1 * (vx[0] - vx[Math.Min(CurrentBar, 10)]));
         vxTrend[0] = SMA(vxAvg, Math.Min(CurrentBar, 65))[0];
         if (CurrentBar <= 64)
         {
             vxTrend[0] = vxTrend[1] + ((2.0 * (vxAvg[0] - vxTrend[1])) / 65.0);
         }
         double num6 = 0.0;
         if (vxTrend[0] > 0.0)
         {
             num6 = vx[0] / vxTrend[0];
         }
         num6 = Math.Min(Math.Pow(lengthParam, 1.0 / expFactor), num6);
         if (num6 < 1.0)
         {
             num6 = 1.0;
         }
         double d     = Math.Pow(num6, expFactor);
         double num8  = Math.Pow(beta, Math.Sqrt(d));
         double x     = windowLength / (windowLength + 2.0);
         double num10 = Math.Pow(x, d);
         uSigma[0] = (num2 > 0.0) ? num : (num - (num8 * num2));
         lSigma[0] = (num3 < 0.0) ? num : (num - (num8 * num3));
         int      currentBar = CurrentBar;
         double[] numArray   = new double[5];
         fbank[currentBar] = numArray;
         if (currentBar == 2)
         {
             numArray[0] = num;
             numArray[2] = num;
             numArray[4] = num;
         }
         else
         {
             numArray[0] = ((1.0 - num10) * num) + (num10 * fbank[currentBar - 1][0]);
             numArray[1] = ((num - numArray[0]) * (1.0 - x)) + (x * fbank[currentBar - 1][1]);
             numArray[2] = numArray[0] + (permissivity * numArray[1]);
             numArray[3] = ((numArray[2] - fbank[currentBar - 1][4]) * Math.Pow(1.0 - num10, 2.0)) + (Math.Pow(num10, 2.0) * fbank[currentBar - 1][3]);
             numArray[4] = fbank[currentBar - 1][4] + numArray[3];
         }
         RawTrend.Set(numArray[1]);
         Prediction.Set(numArray[3]);
         DrawDots();
         if (colorBars)
         {
             if (RawTrend[0] > 0.0)
             {
                 BarColor           = barColorUp;
                 CandleOutlineColor = Color.Silver;
             }
             if (RawTrend[0] < 0.0)
             {
                 BarColor           = barColorDown;
                 CandleOutlineColor = Color.Silver;
             }
         }
         if (drawArrow)
         {
             if (CrossAbove(RawTrend, 0.0, 1))
             {
                 DrawArrowUp(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, Low[0] - (distance * TickSize), Color.Navy);
                 Alert("Long", Priority.High, "Long Entry", "Alert4.wav", 10, Color.Black, Color.Yellow);
             }
             if (CrossBelow(RawTrend, 0.0, 1))
             {
                 DrawArrowDown(CurrentBar.ToString(CultureInfo.InvariantCulture), true, 0, High[0] + (distance * TickSize), Color.Red);
                 Alert("Short", Priority.High, "Short Entry", "Alert4.wav", 10, Color.Black, Color.Yellow);
             }
         }
         if (colorbackground)
         {
             if (!CrossAbove(RawTrend, 0.0, 1) && (RawTrend[0] <= 0.0))
             {
                 if (CrossBelow(RawTrend, 0.0, 1) || (RawTrend[0] < 0.0))
                 {
                     BackColor = Color.FromArgb(opacity, backgroundcolorDn);
                 }
             }
             else
             {
                 BackColor = Color.FromArgb(opacity, backgroundcolorUp);
             }
         }
         if (colorAlLbackgrounds)
         {
             if (CrossAbove(RawTrend, 0.0, 1) || (RawTrend[0] > 0.0))
             {
                 BackColorAll = Color.FromArgb(opacity, backgroundcolorUp);
             }
             else if (CrossBelow(RawTrend, 0.0, 1) || (RawTrend[0] < 0.0))
             {
                 BackColorAll = Color.FromArgb(opacity, backgroundcolorDn);
             }
         }
     }
 }