protected override void OnStartUp() { MA = new DataSeries(this); VarMA = 0; VarMAPrev = 0; vma = 0; vmaPrev = 0; sPDI = 0; sPDIPrev = 0; sMDI = 0; sMDIPrev = 0; STR = 0; STRPrev = 0; adx = new DataSeries(this); alfa = 1.0 / ADXPeriod; ema = EMA(MA, MAPeriod); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (CurrentBar <= BarsRequired) return; if (_emaSlow == null) _emaSlow = EMA(Open, slowEMAPeriod); if (_emaFast == null) _emaFast = EMA(fastEMAPeriod); if (_adx == null) _adx = ADX(_adxPeriod); if (_adx[0] >= _adxMin) { PlotColors[0][0] = Color.Blue; } else { PlotColors[0][0] = Color.LightBlue; } FastEMAPlot.Set(_emaFast[0]); SlowEMAPlot.Set(_emaSlow[0]); if (CrossAbove(_emaFast, _emaSlow, 1)&& _adx[0] >= _adxMin) { _signal = 1; BackColor = Color.LightGreen; } else if (CrossBelow(_emaFast, _emaSlow, 1) && _adx[0] >= _adxMin) { _signal = -1; BackColor = Color.Pink; } else { _signal = 0; BackColor = Color.White; } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double value1 = 0.0; double value2 = 0.0; o.Update(); h.Update(); l.Update(); c.Update(); for (int i = 0; i < len; ++i) { value1 += (c.filtered(i) - o.filtered(i)); value2 += (h.filtered(i) - l.filtered(i)); } if (value2 != 0.0) { unsmoothed.Set(100.0 * value1 / value2); } else { if ((CurrentBar > 1) && unsmoothed.ContainsValue(1)) { unsmoothed.Set(unsmoothed[1]); } else { unsmoothed.Set(0); } } if (weightma == null) { weightma = WMA(unsmoothed, smoothing); expma = EMA(weightma.Value, trigger); } ECO.Set(weightma[0]); TriggerLine.Set(expma[0]); Histogram.Set(weightma[0] - expma[0]); }
protected override void OnStartUp() { weightma = null; expma = null; ol = new double[4]; pol = new double[4]; hl = new double[4]; phl = new double[4]; ll = new double[4]; pll = new double[4]; cl = new double[4]; pcl = new double[4]; unsmoothed = new DataSeries(this); lastSeenBar = -1; extdat = Bars.BarsType as rwt.IExtendedData; if (extdat == null) { throw new Exception("Only use this indicator on an Extended Data BarType!"); } }
public void SetupObjects() { if (_emaSlow == null) { _emaSlow = EMA(_emaSlowPeriod); } if (_emaFast == null) { _emaFast = EMA(_emaFastPeriod); } if (_rsi == null) { _rsi = RSI(Median, _rsiPeriod, 1); } if (_adx == null) { _adx = ADX(_adxPeriod); } if (_atr == null) { _atr = ATR(_atrPeriod); } }
/// <summary> /// The Exponential Moving Average is an indicator that shows the average value of a security's price over a period of time. When calculating a moving average. The EMA applies more weight to recent prices than the SMA. /// </summary> /// <returns></returns> public EMA EMA(Data.IDataSeries input, int period) { if (cacheEMA != null) for (int idx = 0; idx < cacheEMA.Length; idx++) if (cacheEMA[idx].Period == period && cacheEMA[idx].EqualsInput(input)) return cacheEMA[idx]; lock (checkEMA) { checkEMA.Period = period; period = checkEMA.Period; if (cacheEMA != null) for (int idx = 0; idx < cacheEMA.Length; idx++) if (cacheEMA[idx].Period == period && cacheEMA[idx].EqualsInput(input)) return cacheEMA[idx]; EMA indicator = new EMA(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; #if NT7 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256; indicator.MaximumBarsLookBack = MaximumBarsLookBack; #endif indicator.Input = input; indicator.Period = period; Indicators.Add(indicator); indicator.SetUp(); EMA[] tmp = new EMA[cacheEMA == null ? 1 : cacheEMA.Length + 1]; if (cacheEMA != null) cacheEMA.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheEMA = tmp; return indicator; } }
protected override void OnStartUp() { ema1 = EMA(Inputs[0], Period); ema2 = EMA(ema1, Period); ema3 = EMA(ema2, Period); }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { var ed = extdat.getExtraData(0, Bars, CurrentBar); if (ed == null) { return; } if (CurrentBar != lastSeenBar) { for (int i = 0; i < 4; ++i) { pol[i] = ol[i]; // remember previous bar value... phl[i] = hl[i]; pll[i] = ll[i]; pcl[i] = cl[i]; } lastSeenBar = CurrentBar; } // update all the Laguerre numbers.... ol[0] = (1 - gamma) * ed.dOpen + gamma * pol[0]; hl[0] = (1 - gamma) * ed.dHigh + gamma * phl[0]; ll[0] = (1 - gamma) * ed.dLow + gamma * pll[0]; cl[0] = (1 - gamma) * ed.dClose + gamma * pcl[0]; for (int i = 1; i < 4; ++i) { ol[i] = -gamma * ol[i - 1] + pol[i - 1] + gamma * pol[i]; hl[i] = -gamma * hl[i - 1] + phl[i - 1] + gamma * phl[i]; ll[i] = -gamma * ll[i - 1] + pll[i - 1] + gamma * pll[i]; cl[i] = -gamma * cl[i - 1] + pcl[i - 1] + gamma * pcl[i]; } double value1 = 0.0; double value2 = 0.0; for (int i = 0; i < 4; ++i) { value1 += (cl[i] - ol[i]); value2 += (hl[i] - ll[i]); } if (value2 != 0.0) { unsmoothed.Set(100.0 * value1 / value2); } else { if ((CurrentBar > 1) && unsmoothed.ContainsValue(1)) { unsmoothed.Set(unsmoothed[1]); } else { unsmoothed.Set(0); } } if (weightma == null) { weightma = WMA(unsmoothed, smoothing); expma = EMA(weightma.Value, trigger); } ECO.Set(weightma[0]); TriggerLine.Set(expma[0]); Histogram.Set(weightma[0] - expma[0]); }
/// <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(); } } }
public void SetupObjects() { if (_emaSlow == null) _emaSlow = EMA(_emaSlowPeriod); if (_emaFast == null) _emaFast = EMA(_emaFastPeriod); if (_rsi == null) _rsi = RSI(Median, _rsiPeriod, 1); if (_adx == null) _adx = ADX(_adxPeriod); if (_atr == null) _atr = ATR(_atrPeriod); }
/// <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; }