/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // used to set values for bars less than the period int tmpPeriod = Math.Min(CurrentBar, Period); double average = Close[0]; switch (averageType) { case BollingerBandwidth_MATypes.EMA: average = EMA(tmpPeriod)[0]; break; case BollingerBandwidth_MATypes.SMA: average = SMA(tmpPeriod)[0]; break; } double stdDevValue = StdDev(tmpPeriod)[0]; double upperValue = average + numStdDev * stdDevValue; double lowerValue = average - numStdDev * stdDevValue; Bandwidth.Set((upperValue - lowerValue) / average * 100); Bulge.Set(MAX(Bandwidth, bulgeLength)[0]); Squeeze.Set(MIN(Bandwidth, squeezeLength)[0]); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBars[0] < length) { return; } SQZresult.Set(SJCRSU(Input, length, 4, 4)[0]); EMAInputData1.Set(SJCRSU(Input, length, 3.5, 3.5)[0]); EMAresult.Set(EMA(EMAInputData1, 7)[0]); double SqueezeValue = SQZresult[0]; Squeeze.Set(100 * SqueezeValue); Print("Squeeze = " + SQZresult[0]); if (SQZresult[0] > SQZresult[1] && SQZresult[0] > 0) { _SqzColor = buyColor1; } if (SQZresult[0] < SQZresult[1] && SQZresult[0] < 0) { _SqzColor = sellColor1; } if (SQZresult[0] > SQZresult[1] && SQZresult[0] < 0) { _SqzColor = sellColor2; } if (SQZresult[0] < SQZresult[1] && SQZresult[0] > 0) { _SqzColor = buyColor2; } Print("ctTrend = " + ctTrend); if (ctTrend && SQZresult[0] > 0 && SQZresult[0] < EMAresult[0]) { _SqzColor = sellColor2; } if (ctTrend && SQZresult[0] < 0 && SQZresult[0] > EMAresult[0]) { _SqzColor = buyColor2; } PlotColors[1][0] = _SqzColor; BIASresult.Set(SJC_NLR(0, 9).NLRprice[0] - KAMA(Typical, 2, 11, 11)[0]); //BIASresult.Set(SJC_NLR.NLRprice[0] - KAMA(Typical, 2, 11, 11)[0]); //double BiasValue = BIASresult[0]; Bias.Set(0); if (BIASresult[0] > 0) { _BiasColor = biasUpColor; } if (BIASresult[0] < 0) { _BiasColor = biasDnColor; } PlotColors[0][0] = _BiasColor; //Print("Bias = " + BIASresult[0]); }
protected override void OnBarUpdate() { // Are there enough bars if (CurrentBar < length) { return; } try { bool debug = false; //CurrentBar == 33; if (CurrentBar != 0) { double num1 = ATR(length)[0]; double num2 = StdDev(Close, length)[0]; double num3; if (number_1_5 * num1 == 0.0) { num3 = 1.0; } else { num3 = number_2_0 * num2 / (number_1_5 * num1); } if (num3 <= 1.0) { if (Squeeze[1] != 0.0) { startBarNumber = CurrentBar; squeezeHigh = High[0]; squeezeLow = Low[0]; ++breakoutRecNumb; if (debug) { Print(Time + " in != 0.0 - Squeeze[1] " + Squeeze[1] + " breakoutRecNumb: " + breakoutRecNumb); } } if (Squeeze[1] == 0.0) { //Print(Time + " in == 0.0 - Squeeze[1] " + Squeeze[1] + " "); if (High[0] > squeezeHigh) { squeezeHigh = High[0]; } if (Low[0] < squeezeLow) { squeezeLow = Low[0]; } endBarNumber = CurrentBar; if (startBarNumber != endBarNumber) { squeezeMidPoint = (squeezeHigh + squeezeLow) / 2.0; squeezeRange = squeezeHigh - squeezeLow; if (debug) { Print("breakoutRecNumb: " + breakoutRecNumb + " startBarNumber: " + startBarNumber + " endBarNumber: " + endBarNumber + " squeezeHigh: " + squeezeHigh + " squeezeLow: " + squeezeLow); } iRectangle = DrawRectangle("rectangle" + breakoutRecNumb, AutoScale, CurrentBar - startBarNumber, squeezeHigh, CurrentBar - endBarNumber, squeezeLow, boxOutline.Pen.Color, boxAreaColor, boxAreaOpacity); //iRectangle = DrawRectangle("r" +breakoutRecNumb, 5, squeezeHigh, 0, squeezeLow, Color.Green); if (debug) { Print("307"); } if (iRectangle == null) { if (debug) { Print("iRectangle is null"); } } else { iRectangle.Pen.DashStyle = boxOutline.Pen.DashStyle; iRectangle.Pen.Width = boxOutline.Pen.Width; } if (debug) { Print("309"); } if (extendedHighVisible) { iLine = DrawLine("extendedHigh" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeHigh, CurrentBar - endBarNumber - extendedLineLength, squeezeHigh, extendedHigh.Pen.Color, extendedHigh.Pen.DashStyle, (int)extendedHigh.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } } if (debug) { Print("51"); } if (extendedLowVisible) { iLine = DrawLine("extendedLow" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeLow, CurrentBar - endBarNumber - extendedLineLength, squeezeLow, extendedLow.Pen.Color, extendedLow.Pen.DashStyle, (int)extendedLow.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } } if (extendedMiddleVisible) { iLine = DrawLine("extendedMiddle" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeMidPoint, CurrentBar - endBarNumber - extendedMiddleLineLength, squeezeMidPoint, extendedMiddle.Pen.Color, extendedMiddle.Pen.DashStyle, (int)extendedMiddle.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } } if (debug) { Print("32"); } if (extendedLevel1Visible) { double num4 = squeezeRange * (double)extendedLevel1 / 100.0; iLine = DrawLine("extendedLevel1High" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeHigh + num4, CurrentBar - endBarNumber - extendedLineLength, squeezeHigh + num4, extendedLineLevel1.Pen.Color, extendedLineLevel1.Pen.DashStyle, (int)extendedLineLevel1.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } iLine = DrawLine("extendedLevel1Low" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeLow - num4, CurrentBar - endBarNumber - extendedLineLength, squeezeLow - num4, extendedLineLevel1.Pen.Color, extendedLineLevel1.Pen.DashStyle, (int)extendedLineLevel1.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } } if (extendedLevel2Visible) { double num4 = squeezeRange * (double)extendedLevel2 / 100.0; iLine = DrawLine("extendedLevel2High" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeHigh + num4, CurrentBar - endBarNumber - extendedLineLength, squeezeHigh + num4, extendedLineLevel2.Pen.Color, extendedLineLevel2.Pen.DashStyle, (int)extendedLineLevel2.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } iLine = DrawLine("extendedLevel2Low" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeLow - num4, CurrentBar - endBarNumber - extendedLineLength, squeezeLow - num4, extendedLineLevel2.Pen.Color, extendedLineLevel2.Pen.DashStyle, (int)extendedLineLevel2.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } } if (debug) { Print("33"); } if (extendedLevel3Visible) { double num4 = squeezeRange * (double)extendedLevel3 / 100.0; Plot plot = extendedLineLevel3; iLine = DrawLine("extendedLevel3High" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeHigh + num4, CurrentBar - endBarNumber - extendedLineLength, squeezeHigh + num4, plot.Pen.Color, plot.Pen.DashStyle, (int)plot.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } iLine = DrawLine("extendedLevel3Low" + breakoutRecNumb, AutoScale, CurrentBar - endBarNumber, squeezeLow - num4, CurrentBar - endBarNumber - extendedLineLength, squeezeLow - num4, plot.Pen.Color, plot.Pen.DashStyle, (int)plot.Pen.Width); if (iLine != null) { if (!dictionary1.ContainsKey(iLine)) { dictionary1.Add(iLine, iLine.Pen.Color); } if (!showLines) { iLine.Pen.Color = Color.Transparent; } } } if (tickHeightVisible) { int num4 = Convert.ToInt32((squeezeHigh - squeezeLow) / TickSize); if (tickHeightPosition == RIGHT || tickHeightPosition == BOTH) { iText = DrawText("LText" + breakoutRecNumb, AutoScale, num4.ToString(), CurrentBar - endBarNumber, squeezeMidPoint, 0, tickHeightColor, font, StringAlignment.Near, Color.Transparent, Color.Transparent, 1); if (iLine != null) { if (!dictionary2.ContainsKey(iText)) { dictionary2.Add(iText, iText.TextColor); } if (!extendedVisible) { iText.TextColor = Color.Transparent; } } } if (tickHeightPosition == LEFT || tickHeightPosition == BOTH) { iText = DrawText("RText" + breakoutRecNumb, AutoScale, num4.ToString(), CurrentBar - startBarNumber, squeezeMidPoint, 0, tickHeightColor, font, StringAlignment.Far, Color.Transparent, Color.Transparent, 1); if (iLine != null) { if (!dictionary2.ContainsKey(iText)) { dictionary2.Add(iText, iText.TextColor); } if (!extendedVisible) { iText.TextColor = Color.Transparent; } } } } if (debug) { Print("4"); } if (!extendedVisible) { color1 = ((IShape)iRectangle).AreaColor; color2 = ((IShape)iRectangle).Pen.Color; ((IShape)iRectangle).AreaColor = Color.Transparent; ((IShape)iRectangle).Pen.Color = Color.Transparent; } if (iLine != null) { if (!this.list_IRectangle.Contains(this.iRectangle)) { list_IRectangle.Add(iRectangle); } } } } Squeeze.Set(0.0); SqueezeOn.Reset(); } else { if (debug) { Print("5"); } Squeeze.Reset(); SqueezeOn.Set(0.0); } dataSeries2.Set(Input[0] - (DonchianChannel(Input, number_20).Mean[CurrentBar] + EMA(Input, number_20)[0]) / 2.0); dataSeries1.Set(LinReg((IDataSeries)dataSeries2, number_20)[0]); PMomentumUp.Set(0.0); PMomentumDown.Set(0.0); NMomentumUp.Set(0.0); NMomentumDown.Set(0.0); if (dataSeries1[0] > 0.0) { if (dataSeries1[0] > dataSeries1[1]) { PMomentumUp.Set(dataSeries1[0]); } else { PMomentumDown.Set(dataSeries1[0]); } } else if (dataSeries1[0] > dataSeries1[1]) { NMomentumUp.Set(dataSeries1[0]); } else { NMomentumDown.Set(dataSeries1[0]); } } if (debug) { Print("6"); } processLongAlert(soundHigh, 0, squeezeHigh, "squeezeHigh"); processLongAlert(soundLevel1, 1, squeezeHigh + squeezeRange * (double)extendedLevel1 / 100.0, "extendedLevel1"); processLongAlert(soundLevel2, 2, squeezeHigh + squeezeRange * (double)extendedLevel2 / 100.0, "extendedLevel2"); processLongAlert(soundLevel3, 3, squeezeHigh + squeezeRange * (double)extendedLevel3 / 100.0, "extendedLevel3"); processShortAlert(soundLow, 4, squeezeLow, "squeezeLow"); processShortAlert(soundLevel1, 5, squeezeLow - squeezeRange * (double)extendedLevel1 / 100.0, "extendedLevel1"); processShortAlert(soundLevel2, 6, squeezeLow - squeezeRange * (double)extendedLevel2 / 100.0, "extendedLevel2"); processShortAlert(soundLevel3, 7, squeezeLow - squeezeRange * (double)extendedLevel3 / 100.0, "extendedLevel3"); CurrentValue.Set(dataSeries1[0]); if (tempCurrentBar2 != CurrentBar) { tempCurrentBar2 = CurrentBar; if (SqueezeOn[0] == 0.0) { ++barsSinceSqueeze; } else { barsSinceSqueeze = 0; } if (Squeeze[0] == 0.0) { ++squeezeLength; } else { squeezeLength = 0; } } if (debug) { Print("7"); } if (barsSinceSqueeze > barsLookback) { BarsSinceSqueeze.Set(0.0); } else { BarsSinceSqueeze.Set((double)barsSinceSqueeze); } SqueezeLength.Set((double)squeezeLength); SqueezeHigh.Set(squeezeHigh); SqueezeLow.Set(squeezeLow); } catch (Exception ex) { Print("Exception thrown " + ex.Message); Print(ex.StackTrace); } }
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; } }