/// <summary> /// Called on each bar update event (incoming tick). /// </summary> protected override void OnBarUpdate() { diff.Set(High[0] - Low[0]); double middle = EMA(Typical, Period)[0]; double offset = EMA(diff, Period)[0] * offsetMultiplier; double upper = middle + offset; double lower = middle - offset; Midline.Set(middle); Upper.Set(upper); Lower.Set(lower); if (Rising(Midline)) { PlotColors[1][0] = upColor; PlotColors[2][0] = upColor; } if (Falling(Midline)) { PlotColors[1][0] = dnColor; PlotColors[2][0] = dnColor; } }
// Override OnBarUpdate method protected override void OnBarUpdate() { // Protect against too few bars if (CurrentBar < period) { Upper.Reset(); Lower.Reset(); return; } // Solve for the price given a probability if (distribution == Distribution.Gaussian) { double side = Math.Sqrt(-2 * Math.Pow(StdDev(period)[0] / TickSize, 2) * Math.Log(probability * StdDev(Period)[0] / TickSize * Math.Sqrt(2 * Math.PI))); Upper.Set((SMA(period)[0] / TickSize + side) * TickSize); Lower.Set((SMA(period)[0] / TickSize - side) * TickSize); } else if (distribution == Distribution.Laplace) { double side = -HawkmatixAvgDiff(period)[0] / TickSize * Math.Log(probability * 2 * HawkmatixAvgDiff(period)[0] / TickSize); Upper.Set((SMA(period)[0] / TickSize + side) * TickSize); Lower.Set((SMA(period)[0] / TickSize - side) * TickSize); } else if (distribution == Distribution.Logistic) { double s = Math.Sqrt(3) / Math.PI * StdDev(period)[0] / TickSize; double left = 1 - 2 * probability * s; double side = Math.Sqrt((2 * probability * s - 1) * (2 * probability * s - 1) - 4 * probability * probability * s * s); double bottom = 2 * probability * s; Upper.Set((SMA(period)[0] / TickSize - s * Math.Log((left - side) / bottom)) * TickSize); Lower.Set((SMA(period)[0] / TickSize - s * Math.Log((left + side) / bottom)) * TickSize); } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // calculate Linear Regression double sumX = (double)Period * (Period - 1) * 0.5; double divisor = sumX * sumX - (double)Period * Period * (Period - 1) * (2 * Period - 1) / 6; double sumXY = 0; for (int count = 0; count < Period && CurrentBar - count >= 0; count++) { sumXY += count * Input[count]; } y.Set(Input[0]); double slope = ((double)Period * sumXY - sumX * SUM(y, Period)[0]) / divisor; double intercept = (SUM(y, Period)[0] - slope * sumX) / Period; double linReg = intercept + slope * (Period - 1); // Calculate Standard Error double sumSquares = 0; for (int count = 0; count < Period && CurrentBar - count >= 0; count++) { double linRegX = intercept + slope * (Period - 1 - count); double valueX = Input[count]; double diff = Math.Abs(valueX - linRegX); sumSquares += diff * diff; } double stdErr = Math.Sqrt(sumSquares / Period); Middle.Set(linReg); Upper.Set(linReg + stdErr); Lower.Set(linReg - stdErr); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { ZigZag zz = ZigZag(deviationType, deviationValue, useHighLow); Upper.Set(zz.ZigZagHigh[0]); Lower.Set(zz.ZigZagLow[0]); UpperFib.Set(Upper[0] - (Upper[0] - Lower[0]) * 0.382); LowerFib.Set(Lower[0] + (Upper[0] - Lower[0]) * 0.382); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double smaValue = AhrensMA(period).AhrensHL[0]; double stdDevValue = StdDev(Period)[0]; Upper.Set(smaValue + NumStdDev * stdDevValue); Middle.Set(smaValue); Lower.Set(smaValue - NumStdDev * stdDevValue); }
protected override void OnBarUpdate() { avg = DYNAverage[0]; stdDevValue = SDBB[0]; PriceLine.Set(DYNPrice[0]); SignalLine.Set(DYNSignal[0]); Average.Set(avg); Upper.Set(avg + stdDevNumber * stdDevValue); Lower.Set(avg - stdDevNumber * stdDevValue); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double smaValue = SMA(Period)[0]; double stdDevValue = StdDev(SMA(Range(), 20), period)[0]; Print("stdDevValue = " + stdDevValue); Upper.Set(smaValue + NumStdDev * stdDevValue); Middle.Set(smaValue); Lower.Set(smaValue - NumStdDev * stdDevValue); }
protected override void OnBarUpdate() { double RSI_value = RSI(this.RSIPeriod, 1)[0]; this._RSI_List.Set(RSI_value); double PRICE_value = SMA(this._RSI_List, this.PricePeriod)[0]; PriceLine.Set(PRICE_value); double SIGNAL_value = SMA(this._RSI_List, this.SignalPeriod)[0]; SignalLine.Set(SIGNAL_value); double AVG_value = SMA(this._RSI_List, this.BandPeriod)[0]; Average.Set(AVG_value); MidLine.Set(50); double stdDevValue = StdDev(this._RSI_List, this.BandPeriod)[0]; Upper.Set(AVG_value + this.StdDevNumber * stdDevValue); Lower.Set(AVG_value - this.StdDevNumber * stdDevValue); PlotColors[0][0] = this.Main; PlotColors[1][0] = this.Signal; PlotColors[2][0] = this.BBAverage; PlotColors[3][0] = this.BBUpper; PlotColors[4][0] = this.BBLower; if (AVG_value > 50) { PlotColors[5][0] = this.MidPositive; } else { PlotColors[5][0] = this.MidNegative; } Plots[0].PenStyle = this.Dash0Style; Plots[0].Pen.Width = this.Plot0Width; Plots[1].PenStyle = this.Dash1Style; Plots[1].Pen.Width = this.Plot1Width; Plots[2].PenStyle = this.Dash2Style; Plots[2].Pen.Width = this.Plot2Width; Plots[3].PenStyle = this.Dash3Style; Plots[3].Pen.Width = this.Plot3Width; Plots[4].PenStyle = this.Dash3Style; Plots[4].Pen.Width = this.Plot3Width; Plots[5].PenStyle = this.Dash3Style; Plots[5].Pen.Width = this.Plot3Width; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < Period) { return; } EMA ema = EMA(EMA(newPeriod), newPeriod); double rangeOffset = BandPct * EMA(Range(), Period)[0]; Lower.Set(ema[0] - rangeOffset); Upper.Set(ema[0] + rangeOffset); }
/// <summary> /// Called on each bar update event (incoming tick). /// </summary> protected override void OnBarUpdate() { diff.Set(High[0] - Low[0]); double middle = SMA(Typical, Period)[0]; double offset = SMA(diff, Period)[0] * offsetMultiplier; double upper = middle + offset; double lower = middle - offset; Midline.Set(middle); Upper.Set(upper); Lower.Set(lower); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double maValue = 0; switch (matype) { case 1: { Middle.Set(maValue = EMA(Inputs[0], Period)[0]); break; } case 2: { Middle.Set(maValue = HMA(Inputs[0], Period)[0]); break; } case 3: { Middle.Set(maValue = SMA(Inputs[0], Period)[0]); break; } case 4: { Middle.Set(maValue = TMA(Inputs[0], Period)[0]); break; } case 5: { Middle.Set(maValue = TEMA(Inputs[0], Period)[0]); break; } case 6: { Middle.Set(maValue = WMA(Inputs[0], Period)[0]); break; } } Upper.Set(maValue + (maValue * EnvelopePercentage / 100)); Lower.Set(maValue - (maValue * EnvelopePercentage / 100)); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double averageValue = 0; if (Smoothed) { averageValue = smoothedAverage[0]; } else { averageValue = average[0]; } double offset = 0; if (Smoothed) { offset = NumStdDev * smoothedVolatility[0]; } else { offset = NumStdDev * volatility[0]; } if (showMidband) { Middle.Set(averageValue); } else { Middle.Reset(); } if (showChannels) { Upper.Set(averageValue + offset); Lower.Set(averageValue - offset); } else { Upper.Reset(); Lower.Reset(); } if (CurrentBar < Math.Max(Period, StdDevPeriod)) { return; } if (FirstTickOfBar) { neutralSlope = threshold * averageTrueRange[1] / 1000; priorBull = bullish; middle = Middle[1] + Middle[2]; upper = Upper[1] + Upper[2]; lower = Lower[1] + Lower[2]; } if (2 * averageValue > middle + 3 * neutralSlope) { PlotColors[1][0] = upColor; if (useCentralSlope) { PlotColors[0][0] = UpColor; PlotColors[2][0] = UpColor; } if (priorBull <= 0) { index = CurrentBar; } if (Opacity != 0) { DrawRegion("bollinger" + index, CurrentBar - index + 1, 0, Upper, Lower, Color.Transparent, UpColor, Opacity); } bullish = 1; } else if (2 * averageValue < middle - 3 * neutralSlope) { PlotColors[1][0] = DownColor; if (useCentralSlope) { PlotColors[0][0] = DownColor; PlotColors[2][0] = DownColor; } if (priorBull >= 0) { index = CurrentBar; } if (Opacity != 0) { DrawRegion("bollinger" + index, CurrentBar - index + 1, 0, Upper, Lower, Color.Transparent, DownColor, Opacity); } bullish = -1; } else { PlotColors[1][0] = NeutralColor; if (useCentralSlope) { PlotColors[0][0] = NeutralColor; PlotColors[2][0] = NeutralColor; } if (priorBull != 0) { index = CurrentBar; } if (Opacity != 0) { DrawRegion("bollinger" + index, CurrentBar - index + 1, 0, Upper, Lower, Color.Transparent, NeutralColor, Opacity); } bullish = 0; } if (!useCentralSlope) { if (2 * averageValue + 2 * offset >= upper + 3 * neutralSlope) { PlotColors[0][0] = UpColor; } else if (2 * averageValue + 2 * offset <= upper - 3 * neutralSlope) { PlotColors[0][0] = DownColor; } else { PlotColors[0][0] = NeutralColor; } if (2 * averageValue - 2 * offset >= lower + 3 * neutralSlope) { PlotColors[2][0] = UpColor; } else if (2 * averageValue - 2 * offset <= lower - 3 * neutralSlope) { PlotColors[2][0] = DownColor; } else { PlotColors[2][0] = NeutralColor; } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { Value.Set((MAX(Close, Period)[0] + MIN(Close, Period)[0]) / 2); Upper.Set(MAX(Close, Period)[0]); Lower.Set(MIN(Close, Period)[0]); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar < period) { return; } if (Low[0] < Low[1]) { Sideset.Set(0); } if (High[0] > High[1]) { Sideset.Set(1); } ratchedval = (1 - (counter * ratched)); if (Sideset[1] == 0) { SigClose = MIN(Low, (period))[0]; Plotset.Set(SigClose + Bars.Instrument.MasterInstrument.Round2TickSize((ratchedval * (ATRTimes * ATR(period)[0])))); } if (Sideset[1] == 1) { SigClose = MAX(High, (period))[0]; Plotset.Set(SigClose - Bars.Instrument.MasterInstrument.Round2TickSize((ratchedval * (ATRTimes * ATR(period)[0])))); } if (Sideset[1] == 1 && Low[1] <= Plotset[1]) { Sideset.Set(0); SigClose = High[1]; counter = 0; Plotset.Set(SigClose + Bars.Instrument.MasterInstrument.Round2TickSize((ratchedval * (ATRTimes * ATR(period)[0])))); Lower.Set(Plotset[0]); } if (Sideset[1] == 1 && Low[1] > Plotset[1]) { Sideset.Set(1); SigClose = MAX(High, (period))[0]; Plotset.Set(SigClose - Bars.Instrument.MasterInstrument.Round2TickSize((ratchedval * (ATRTimes * ATR(period)[0])))); if (Plotset[1] > Plotset[0]) { Plotset.Set(Plotset[1]); } Upper.Set(Plotset[0]); } if (Sideset[1] == 0 && High[1] >= Plotset[1]) { Sideset.Set(1); SigClose = High[1]; counter = 0; Plotset.Set(SigClose - Bars.Instrument.MasterInstrument.Round2TickSize((ratchedval * (ATRTimes * ATR(period)[0])))); Upper.Set(Plotset[0]); } if (Sideset[1] == 0 && High[1] < Plotset[1]) { Sideset.Set(0); SigClose = MIN(Low, (period))[0]; Plotset.Set(SigClose + Bars.Instrument.MasterInstrument.Round2TickSize((ratchedval * (ATRTimes * ATR(period)[0])))); if (Plotset[1] < Plotset[0]) { Plotset.Set(Plotset[1]); } Lower.Set(Plotset[0]); } counter++; }
/// <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(); } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { BuySignal = false; SellSignal = false; if (savedCurrentBar == -1) // Init { currentBarHigh = High[0]; currentBarLow = Low[0]; state = GetNextState(); savedCurrentBar = CurrentBar; } else if (savedCurrentBar != CurrentBar) { // Is new bar ? currentBarHigh = (isRealtime && !CalculateOnBarClose) ? High[1] : High[0]; currentBarLow = (isRealtime && !CalculateOnBarClose) ? Low[1] : Low[0]; // today buy/sell signal is triggered if ((state == 5 && currentBarHigh > boxTop) || (state == 5 && currentBarLow < boxBottom)) { if (state == 5 && currentBarHigh > boxTop) { BuySignal = true; } else { SellSignal = true; } state = 0; startBarActBox = CurrentBar; } state = GetNextState(); // draw with today if (boxBottom == double.MaxValue) { for (int i = CurrentBar - startBarActBox; i >= 0; i--) { Upper.Set(i, boxTop); Lower.Reset(i); } } else { for (int i = CurrentBar - startBarActBox; i >= 0; i--) { Upper.Set(i, boxTop); Lower.Set(i, boxBottom); } } savedCurrentBar = CurrentBar; } else { isRealtime = true; // today buy/sell signal is triggered if ((state == 5 && currentBarHigh > boxTop) || (state == 5 && currentBarLow < boxBottom)) { if (state == 5 && currentBarHigh > boxTop) { BuySignal = true; } else { SellSignal = true; } startBarActBox = CurrentBar + 1; state = 0; } // draw with today if (boxBottom == double.MaxValue) { Upper.Set(boxTop); Lower.Reset(); } else { Upper.Set(boxTop); Lower.Set(boxBottom); } } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar == 0) { return; } // First we calculate the linear regression parameters double sumX = (double)Period * (Period - 1) * 0.5; double divisor = sumX * sumX - (double)Period * Period * (Period - 1) * (2 * Period - 1) / 6; double sumXY = 0; double sumY = 0; int barCount = Math.Min(Period, CurrentBar); for (int count = 0; count < barCount; count++) { sumXY += count * Input[count]; sumY += Input[count]; } if (divisor == 0 || Period == 0) { return; } double slope = ((double)Period * sumXY - sumX * sumY) / divisor; double intercept = (sumY - slope * sumX) / Period; slopeSeries.Set(slope); interceptSeries.Set(intercept); // Next we calculate the standard deviation of the // residuals (vertical distances to the regression line). double sumResiduals = 0; for (int count = 0; count < barCount; count++) { double regressionValue = intercept + slope * (Period - 1 - count); double residual = Math.Abs(Input[count] - regressionValue); sumResiduals += residual; } double avgResiduals = sumResiduals / Math.Min(CurrentBar - 1, Period); sumResiduals = 0; for (int count = 0; count < barCount; count++) { double regressionValue = intercept + slope * (Period - 1 - count); double residual = Math.Abs(Input[count] - regressionValue); sumResiduals += (residual - avgResiduals) * (residual - avgResiduals); } double stdDeviation = Math.Sqrt(sumResiduals / Math.Min(CurrentBar + 1, Period)); stdDeviationSeries.Set(stdDeviation); double middle = intercept + slope * (Period - 1); Middle.Set(middle); Upper.Set(middle + stdDeviation * Width); Lower.Set(middle - stdDeviation * Width); }
/// <summary> /// Calculates the indicator value(s) at the current index. /// </summary> protected override void OnBarUpdate() { if (CurrentBars[0] < bandperiod) { return; } 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]; ZeroLine.Set(0); //double stdDevValue = StdDev(BBMACD,bandperiod)[0]; double stdDevValue = SDBB[0]; Upper.Set(avg + StdDevNumber * stdDevValue); Lower.Set(avg - StdDevNumber * stdDevValue); //1. Green dots, above bands, sloping up Green dot - text UP - prefer up as easy to understand //2. Green dots, above bands, changing to a red dot. - Cell Colour will Change (but may still say UP) //3. Consecutive red dots crossing down through the bands - not sure we discussed this one!!! Cell colour will change Put --- to indicate crossing down //4. Red dots, below bands, sloping down.Red dot - text DOWN - prefer DOWN as easy to understand //5. Red dots, below bands, changing to a green dot.ell Colour will Change (but may still say DOWN) //6. Consecutive green dots, crossing up through the bands - not sure we discussed this one!!! Cell colour will change Put +++ to indicate crossing down //1 & 4 - would be trending signals - don't trade against these //2 & 5 - would be minor alerts for consolidation or the start of direction change //3 & 6 - would be major alerts with direction change confirmed by dots about to break through the opposite band if (Rising(BBMACD)) { if (BBMACD[0] < Upper[0]) { PlotColors[0][0] = DotsUpInside; macdsignal = 1; } else if ((BBMACD[1] < Upper[1]) && (BBMACD[0] > Upper[0])) { PlotColors[0][0] = DotsUpOutside; macdsignal = 2; } else { PlotColors[0][0] = DotsUpOutside; macdsignal = 3; } } else { if (BBMACD[0] > Lower[0]) { PlotColors[0][0] = DotsDownInside; macdsignal = -1; } else if ((BBMACD[1] > Lower[1]) && (BBMACD[0] < Lower[0])) { PlotColors[0][0] = DotsDownOutside; macdsignal = -2; } else { PlotColors[0][0] = DotsDownOutside; macdsignal = -3; } } Signal.Set(macdsignal); /* * * if (BBMACD[0] > BBMACD[1]) * { * PlotColors[0][0] = DotsUpOutside; * if ((BBMACD[0] > Upper[0])) //UP * { * macdsignal = 1; * PlotColors[0][0] = DotsUpOutside; * } * else if ((BBMACD[1] < Lower[1]) && (BBMACD[0] > Lower[0])) //UP * { * macdsignal = 6; * PlotColors[0][0] = DotsDownInside; * } * else if ((BBMACD[1] > BBMACD[2]) && (BBMACD[0] > Lower[0])) //UP * { * macdsignal = 7; * PlotColors[0][0] = DotsUpInside; * } * else if ((BBMACD[1] < Upper[1]) && (BBMACD[0] > Upper[0])) //UP * { * macdsignal = 8; * PlotColors[0][0] = DotsUpOutside; * } * } * else //(BBMACD[0] < BBMACD[1]) * { * PlotColors[0][0] = DotsDownOutside; * if ((BBMACD[0] < Lower[0])) //DN * { * macdsignal = 5; * PlotColors[0][0] = DotsDownOutside; * } * else if ((BBMACD[0] < BBMACD[1])) //DN * { * macdsignal = 2; * PlotColors[0][0] = DotsDownOutside; * } * else if ((BBMACD[1] < BBMACD[2]) && (BBMACD[0] < Upper[0])) //DN * { * macdsignal = 3; * PlotColors[0][0] = DotsDownInside; * } * else if ((BBMACD[1] > Lower[1]) && (BBMACD[0] < Lower[0])) //DN * { * macdsignal = 4; * PlotColors[0][0] = DotsDownOutside; * } * } */ /* * if ((BBMACD[0] > BBMACD[1]) && (BBMACD[0] > Upper[0])) //UP * { * macdsignal = 1; * PlotColors[0][0] = DotsUpOutside; * } * if ((BBMACD[1] > Upper[1]) && (BBMACD[0] < BBMACD[1])) //DN * { * macdsignal = 2; * PlotColors[0][0] = DotsDownOutside; * } * if ((BBMACD[0] < BBMACD[1]) && (BBMACD[1] < BBMACD[2]) && (BBMACD[0] < Upper[0])) //DN * { * macdsignal = 3; * PlotColors[0][0] = DotsDownInside; * } * if ((BBMACD[0] < BBMACD[1]) && (BBMACD[1] > Lower[1]) && (BBMACD[0] < Lower[0])) //DN * { * macdsignal = 4; * PlotColors[0][0] = DotsDownOutside; * } * * if ((BBMACD[0] < BBMACD[1]) && (BBMACD[0] < Lower[0])) //DN * { * macdsignal = 5; * PlotColors[0][0] = DotsDownOutside; * } * if ((BBMACD[1] < Lower[1]) && (BBMACD[0] > BBMACD[1])) //UP * { * macdsignal = 6; * PlotColors[0][0] = DotsDownInside; * } * if ((BBMACD[0] > BBMACD[1]) && (BBMACD[1] > BBMACD[2]) && (BBMACD[0] > Lower[0])) //UP * { * macdsignal = 7; * PlotColors[0][0] = DotsUpInside; * } * if ((BBMACD[0] > BBMACD[1]) && (BBMACD[1] < Upper[1]) && (BBMACD[0] > Upper[0])) //UP * { * macdsignal = 8; * PlotColors[0][0] = DotsUpOutside; * } */ /////PlotColors[2][0] = BBUpper; /////PlotColors[3][0] = BBLower; /////PlotColors[4][0] = SignalCol; /////PlotColors[5][0] = ZeroCol; }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { // Code for SMA 100 line if (CurrentBar == 0) { Trend.Set(Input[0]); } else { double last = Trend[1] * Math.Min(CurrentBar, smaPeriod); if (CurrentBar >= smaPeriod) { Trend.Set((last + Input[0] - Input[smaPeriod]) / Math.Min(CurrentBar, smaPeriod)); if (CountIf(delegate { return(Trend[0] > Trend[1]); }, 15) == 15) //if (Rising(Trend)) { PlotColors[6][0] = upColor; } else if (CountIf(delegate { return(Trend[0] < Trend[1]); }, 15) == 15) { PlotColors[6][0] = downColor; } } else { Trend.Set((last + Input[0]) / (Math.Min(CurrentBar, smaPeriod) + 1)); } } // Code for other indicators if (CurrentBar < 5) { return; } if (High[0] < High[2] && High[1] < High[2] && High[3] < High[2] && High[4] < High[2]) { double halfStdDevValue = (StdDev(period)[2]) / 2; //Plots[0].Pen = new Pen(Color.Green); Values[0][2] = High[2] + halfStdDevValue; if (High[2] > Close[HighestBar(Close, donchianPeriod)]) { UpperTarget.Set(2, High[2] * 1.1); // 10% above } // else // { // Print(Time + " CurrentBar: " + CurrentBar + " HighestBar(High, 22): " + HighestBar(High, 22)); // } } if (Low[0] > Low[2] && Low[1] > Low[2] && Low[3] > Low[2] && Low[4] > Low[2]) { double halfStdDevValue = (StdDev(period)[2]) / 2; //Values[1][2] = Low[2] - halfStdDevValue; Lower.Set(2, Low[2] - halfStdDevValue); if (Low[2] < Close[LowestBar(Close, donchianPeriod)]) { LowerTarget.Set(2, Low[2] * 0.9); // 10% below low } } //UpperDonchian.Set(MAX(Close, donchianPeriod)[0]); //LowerDonchian.Set(MIN(Close, donchianPeriod)[0]); }
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(); } } }