/// <summary> /// Calculates the indicator value(s) at the current index. /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { fastEma.Set(Input[0]); slowEma.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); } else { upDown = 0; fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]); slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]); double macd = fastEma[0] - slowEma[0]; double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; Value.Set(macd); Avg.Set(macdAvg); //Diff.Set(macd - macdAvg); Diff.Set(macd); if (Value[0] > Value[1]) { PlotColors[0][0] = Color.Green; upDown++; } else { PlotColors[0][0] = Color.Red; upDown--; } if (Rising(Avg)) { PlotColors[1][0] = Color.Green; upDown++; } else { PlotColors[1][0] = Color.Red; upDown--; } Mom.Set(macd); // dad = macdAvg // mom = macd if (macd > 0 && macdAvg > 0) { BackColorAll = Color.FromArgb(Opacity, BackgroundLongColor); } else if (macd < 0 && macdAvg < 0) { BackColorAll = Color.FromArgb(Opacity, BackgroundShortColor); } } }
/// <summary> /// Calculates the indicator value(s) at the current index. /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { fastEma.Set(Input[0]); slowEma.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); } else { upDown = 0; fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]); slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]); double macd = fastEma[0] - slowEma[0]; double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; Value.Set(macd); Avg.Set(macdAvg); //Diff.Set(macd - macdAvg); Diff.Set(macd); if (Math.Abs(Value[0]) > Math.Abs(Value[1])) { PlotColors[0][0] = Color.Green; upDown++; } else { PlotColors[0][0] = Color.Red; upDown--; } if (Rising(Avg)) { PlotColors[1][0] = Color.Green; upDown++; } else { PlotColors[1][0] = Color.Red; upDown--; } Mom.Set(macd); } }
/// <summary> /// Calculates the indicator value(s) at the current index. /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { fastEma.Set(Input[0]); slowEma.Set(Input[0]); Value.Set(0); Avg.Set(0); Diff.Set(0); } else { upDown = 0; fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]); slowEma.Set((2.0 / (1 + Slow)) * Input[0] + (1 - (2.0 / (1 + Slow))) * slowEma[1]); double macd = fastEma[0] - slowEma[0]; double macdAvg = (2.0 / (1 + Smooth)) * macd + (1 - (2.0 / (1 + Smooth))) * Avg[1]; Value.Set(macd); Avg.Set(macdAvg); //Diff.Set(macd - macdAvg); Diff.Set(macd); if (Math.Abs(Value[0]) > Math.Abs(Value[1])) { PlotColors[0][0] = Color.Green; upDown++; } else { PlotColors[0][0] = Color.Red; upDown--; } if (Rising(Avg)) { PlotColors[1][0] = Color.Green; upDown++; } else { PlotColors[1][0] = Color.Red; upDown--; } // Sets the bar color to its default color as defined in the chart properties dialog //BarColor = Color.Empty; //CandleOutlineColorSeries[0] = Color.Black; //CandleOutlineColor = Color.Black; if (macd > 0 && macd > macdAvg) { BarColor = Color.Green; } else if (macd < 0 && macd < macdAvg) { BarColor = Color.Red; } else { BarColor = Color.Black; } Mom.Set(macd); } }
protected override void OnBarUpdate() { Squeeze.Set(0); switch (_sStyle) { case SqueezeStyle.BBSqueeze: { double avtrrg = ATR(_length)[0]; double sd = StdDev(Close, _length)[0]; double bbsInd = (_nK * avtrrg) != 0 ? _nBb * sd / (_nK * avtrrg) : 1; PlotColors[0][0] = bbsInd <= 1 ? _alertcolor : _normalcolor; _myValue2.Set(Input[0] - (((DonchianChannel(Input, _mLength).Mean.Get(CurrentBar)) + (EMA(Input, _mLength)[0])) / 2)); Mom.Set(LinReg(_myValue2, _mLength)[0]); if (CurrentBar > 0) { PlotColors[1][0] = Mom[0] > 0 ? (Mom[0] > Mom[1] ? _pmup : _pmdown) : (Mom[0] > Mom[1] ? _nmup : _nmdown); } } break; case SqueezeStyle.PBFSqueeze: if (CurrentBar == 0) { _myValue2.Set(Close[0]); } else { _myValue2.Set(RGaussianFilter(Typical, _gaussperiod, _gausspoles)[0]); PlotColors[0][0] = _myValue2[0] <= _myValue2[1] ? _pbfsell : _pbfbuy; _fv1 = RGaussianFilter(Typical, 8, 4)[0]; _sv1 = RGaussianFilter(Typical, 21, 4)[0]; _d1 = _fv1 - _sv1; _fv2 = RGaussianFilter(Typical, 13, 4)[0]; _sv2 = RGaussianFilter(Typical, 34, 4)[0]; _d2 = _fv2 - _sv2; _fv3 = RGaussianFilter(Typical, 21, 4)[0]; _sv3 = RGaussianFilter(Typical, 55, 4)[0]; _d3 = _fv3 - _sv3; _fv4 = RGaussianFilter(Typical, 34, 4)[0]; _sv4 = RGaussianFilter(Typical, 89, 4)[0]; _d4 = _fv4 - _sv4; Mom.Set((_d1 + _d2 + _d3 + _d4) / 4); PlotColors[1][0] = Mom[0] > 0 ? (Mom[0] > Mom[1] ? _pmup : _pmdown) : (Mom[0] > Mom[1] ? _nmup : _nmdown); } break; default: if (CurrentBar == 0) { _myValue2.Set(Close[0]); } else { _myValue2.Set(RGaussianFilter(Typical, _gaussperiod, _gausspoles)[0]); PlotColors[0][0] = _myValue2[0] <= _myValue2[1] ? _pbfsell : _pbfbuy; _fv1 = RGaussianFilter(Typical, 8, _gausspolescounter)[0]; _sv1 = RGaussianFilter(Typical, 21, _gausspolescounter)[0]; _d1 = _fv1 - _sv1; _fv2 = RGaussianFilter(Typical, 13, _gausspolescounter)[0]; _sv2 = RGaussianFilter(Typical, 34, _gausspolescounter)[0]; _d2 = _fv2 - _sv2; _fv3 = RGaussianFilter(Typical, 21, _gausspolescounter)[0]; _sv3 = RGaussianFilter(Typical, 55, _gausspolescounter)[0]; _d3 = _fv3 - _sv3; _fv4 = RGaussianFilter(Typical, 34, _gausspolescounter)[0]; _sv4 = RGaussianFilter(Typical, 89, _gausspolescounter)[0]; _d4 = _fv4 - _sv4; Mom.Set((_d1 + _d2 + _d3 + _d4) / 4); PlotColors[1][0] = Mom[0] > 0 ? (Mom[0] > Mom[1] ? _pmup : _pmdown) : (Mom[0] > Mom[1] ? _nmup : _nmdown); if (CCI(_cciperiod)[1] > 50 && CCI(_cciperiod)[0] <= 50 && Mom[0] > 0 && Mom[1] > 0 && Mom[2] > 0) { PlotColors[1][0] = _nmup; _downct = 1; } if (_downct == 1 && Mom[0] > 0 && CCI(_cciperiod)[0] < 100) { PlotColors[1][0] = _nmup; } if (_downct == 1 && CCI(_cciperiod)[1] < 100 && CCI(_cciperiod)[0] > 100) { PlotColors[1][0] = _pmup; _downct = 0; } if (_downct == 1 && Mom[0] < 0) { _downct = 0; } if (CCI(_cciperiod)[1] < -50 && CCI(_cciperiod)[0] > -50 && Mom[0] < 0 && Mom[1] < 0 && Mom[2] < 0) { PlotColors[1][0] = _pmdown; _upct = 1; } if (_upct == 1 && Mom[0] > 0) { _upct = 0; } if (_upct == 1 && Mom[0] < 0 && CCI(_cciperiod)[0] > -100) { PlotColors[1][0] = _pmdown; } if (_upct == 1 && CCI(_cciperiod)[1] > -100 && CCI(_cciperiod)[0] < -100) { PlotColors[1][0] = _nmdown; _upct = 0; } } break; } }