public Rex(Bars bars, int period, ChoiceOfMA option, string description) : base(bars, description) { base.FirstValidValue = period; DataSeries TVB = (bars.Close - bars.Low) + (bars.Close - bars.Open) - (bars.High - bars.Close); //DataSeries TVB = 3 * bars.Close - (bars.Low + bars.Open + bars.High); var rangePartitioner = Partitioner.Create(FirstValidValue, bars.Count); Parallel.ForEach(rangePartitioner, (range, loopState) => { for (int bar = range.Item1; bar < range.Item2; bar++) { if (option == ChoiceOfMA.EMA) { base[bar] = EMA.Series(TVB, period, EMACalculation.Modern)[bar]; } else if (option == ChoiceOfMA.SMA) { base[bar] = Community.Indicators.FastSMA.Series(TVB, period)[bar]; } else if (option == ChoiceOfMA.WMA) { base[bar] = WMA.Series(TVB, period)[bar]; } else if (option == ChoiceOfMA.SMMA) { base[bar] = SMMA.Series(TVB, period)[bar]; } } }); }
public Coppock(DataSeries ds, int ROCPeriod1, int ROCPeriod2, int MAPeriod, CoppockCalculation option, string description) : base(ds, description) { base.FirstValidValue = Math.Max(MAPeriod, Math.Max(ROCPeriod1, ROCPeriod2)); if (FirstValidValue > ds.Count || FirstValidValue < 0) { FirstValidValue = ds.Count; } if (ds.Count < Math.Max(ROCPeriod1, ROCPeriod2)) { return; } DataSeries Coppock = WMA.Series((ROC.Series(ds, ROCPeriod1) + ROC.Series(ds, ROCPeriod2)), MAPeriod); DataSeries Coppock2 = WMA.Series((Community.Indicators.FastSMA.Series(ds, 22) / Community.Indicators.FastSMA.Series(ds >> 250, 22) - 1), 150); for (int bar = FirstValidValue; bar < ds.Count; bar++) { if (option == CoppockCalculation.Option1) { base[bar] = Coppock[bar]; } else { base[bar] = Coppock2[bar]; } } }
//populate public override void Populate() { TimeSeries source = Parameters[0].AsTimeSeries; TimeSeries ds = new TimeSeries(source.DateTimes, false); ds.Values.AddRange(source.Values); Int32 rainbowPeriod = Parameters[1].AsInt; Int32 wmaSmoothingPeriod = Parameters[2].AsInt; Int32 rsiPeriod = Parameters[3].AsInt; DateTimes = ds.DateTimes; int period = Math.Max(Math.Max(rainbowPeriod, wmaSmoothingPeriod), rsiPeriod); if (period <= 0 || ds.Count == 0) { return; } var FirstValidValue = Math.Max(rainbowPeriod * 3, wmaSmoothingPeriod); if (FirstValidValue > ds.Count) { FirstValidValue = ds.Count; } // Clip the raw Put/Call Ratio data for (int bar = 0; bar < ds.Count; bar++) { if (ds[bar] > 0.9) { ds[bar] = 0.9; } else if (ds[bar] < 0.45) { ds[bar] = 0.45; } } // Rainbow smoothing var rbw = new TimeSeries(DateTimes); var ma = new WMA(ds, rainbowPeriod); for (int w = 1; w <= 9; w++) { ma = new WMA(ma, rainbowPeriod); rbw += ma; } rbw /= 10d; var pcri = new WMA(rbw, wmaSmoothingPeriod); var x = 0.1 * (new RSI(pcri, rsiPeriod) - 50); for (int bar = FirstValidValue; bar < ds.Count; bar++) { double e2y = Math.Exp(2 * x[bar]); Values[bar] = 50 * ((e2y - 1) / (e2y + 1) + 1); // with scaling } }
//populate public override void Populate() { BarHistory ds = Parameters[0].AsBarHistory; Int32 period = Parameters[1].AsInt; Int32 periodSmooth = Parameters[1].AsInt; DateTimes = ds.DateTimes; if (period <= 0 || periodSmooth <= 0 || ds.Count == 0) { return; } //Assign first bar that contains indicator data var FirstValidValue = Math.Max(periodSmooth, period); if (FirstValidValue > ds.Count) { FirstValidValue = ds.Count; } if (ds.Count < 2) { return; } var _avg = (ds.Open + ds.High + ds.Low + ds.Close) / 4d; //TODO fill with 0 in the loop var _haOpen = new TimeSeries(DateTimes); var _haC = new TimeSeries(DateTimes); _haOpen[0] = _avg[0]; _haC[0] = _avg[0]; for (int bar = 1; bar < ds.Count; bar++) { _haOpen[bar] = (_avg[bar - 1] + _haOpen[bar - 1]) / 2d; _haC[bar] = (_avg[bar] + _haOpen[bar] + Math.Max(ds.High[bar], _haOpen[bar]) + Math.Min(ds.Low[bar], _haOpen[bar])) / 4d; } var TMA1 = new TEMA_TASC(_haC, periodSmooth); var TMA2 = new TEMA_TASC(TMA1, periodSmooth); var Diff = TMA1 - TMA2; var ZLHA = TMA1 + Diff; var temaZLHA = new TEMA_TASC(ZLHA, periodSmooth); var _sd = new StdDev(temaZLHA, period); var _wma = new WMA(temaZLHA, period); for (int bar = FirstValidValue; bar < ds.Count; bar++) { Values[bar] = 100 * (temaZLHA[bar] + 2 * _sd[bar] - _wma[bar]) / (4 * _sd[bar]); } }
//populate public override void Populate() { TimeSeries source = Parameters[0].AsTimeSeries; TimeSeries ds = new TimeSeries(source.DateTimes, false); ds.Values.AddRange(source.Values); Int32 rsiPeriod = Parameters[1].AsInt; Int32 wmaPeriod = Parameters[2].AsInt; DateTimes = ds.DateTimes; int period = Math.Max(rsiPeriod, wmaPeriod); if (period <= 0 || ds.Count == 0) { return; } var FirstValidValue = Math.Max(rsiPeriod * 3, wmaPeriod); if (FirstValidValue > ds.Count) { FirstValidValue = ds.Count; } // Clip the raw Put/Call Ratio data for (int bar = 0; bar < ds.Count; bar++) { if (ds[bar] > 0.9) { ds[bar] = 0.9; } else if (ds[bar] < 0.45) { ds[bar] = 0.45; } } // TEMA smoothing ds = new TEMA_TASC(ds, 5); // Rainbow smoothing var rbw = new TimeSeries(DateTimes); var ma = new WMA(ds, 2); for (int w = 1; w <= 9; w++) { ma = new WMA(ma, 2); rbw += ma; } rbw /= 10d; rbw = new RSI(rbw, rsiPeriod); for (int bar = wmaPeriod - 1; bar < ds.Count; bar++) { Values[bar] = new WMA(rbw, wmaPeriod)[bar]; } }
public void WMA() { WMA wma = new WMA(10); wma.Load(csvPath); SingleDoubleSerie serie = wma.Calculate(); Assert.NotNull(serie); Assert.True(serie.Values.Count > 0); }
public void WMA() { WMA wma = new WMA(10); wma.Load(OhlcList); SingleDoubleSerie serie = wma.Calculate(); Assert.IsNotNull(serie); Assert.IsTrue(serie.Values.Count > 0); }
public void WMA() { WMA wma = new WMA(10); wma.Load(Directory.GetCurrentDirectory() + "\\table.csv"); SingleDoubleSerie serie = wma.Calculate(); Assert.IsNotNull(serie); Assert.IsTrue(serie.Values.Count > 0); }
// User defined variables (add any user defined variables below) #endregion #region Events /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { try { base.Initialize(); #region instantiate indicator references eMA = _indicator.EMA(this.EMAPeriod); eMA.Plots[0].Pen.Color = Color.Red; eMA.Plots[0].Pen.Width = 2; sMA = _indicator.SMA(this.SMAPeriod); sMA.Plots[0].Pen.Color = Color.Blue; sMA.Plots[0].Pen.Width = 3; wMA = _indicator.WMA(this.WMAPeriod); wMA.Plots[0].Pen.Color = Color.Gray; wMA.Plots[0].Pen.Width = 4; #endregion #region add indicators to chart bool addEMA = (TradeSetupMode & 1) == 1 || (TradeSetupMode & 2) == 2 || this.TrailStopType == 4; bool addSMA = (TradeSetupMode & 2) == 2 || (TradeSetupMode & 4) == 4 || this.TrailStopType == 5; bool addWMA = (TradeSetupMode & 4) == 4 || this.TrailStopType == 6; #region GraphicsMode if (GraphicsMode) { mTDoubleShotStrategyInfoBar = _indicator.MTDoubleShotStrategyInfoBar(); mTDoubleShotStrategyVisualiser = _indicator.MTDoubleShotStrategyVisualiser(); Add(mTDoubleShotStrategyInfoBar); Add(mTDoubleShotStrategyVisualiser); if (addEMA) { Add(eMA); } if (addSMA) { Add(sMA); } if (addWMA) { Add(wMA); } } #endregion #endregion } catch (Exception ex) { Print(ex.ToString()); Log(ex.ToString(), LogLevel.Alert); } }
public EnvelopeLower(DataSeries ds, int period, double pct, ChoiceOfMA ma, string description) : base(ds, description) { if (ma == ChoiceOfMA.SMA) { base.FirstValidValue = period; } else { base.FirstValidValue = (period * 3); } if (FirstValidValue > ds.Count || FirstValidValue < 0) { FirstValidValue = ds.Count; } if (ds.Count < period) { return; } var rangePartitioner = Partitioner.Create(0, ds.Count); Parallel.ForEach(rangePartitioner, (range, loopState) => { for (int bar = range.Item1; bar < range.Item2; bar++) { if (ma == ChoiceOfMA.EMA) { base[bar] = EMA.Series(ds, period, EMACalculation.Modern)[bar] * (1 - (pct / 100)); } else if (ma == ChoiceOfMA.SMA) { base[bar] = Community.Indicators.FastSMA.Series(ds, period)[bar] * (1 - (pct / 100)); } else if (ma == ChoiceOfMA.WMA) { base[bar] = WMA.Series(ds, period)[bar] * (1 - (pct / 100)); } else if (ma == ChoiceOfMA.SMMA) { base[bar] = SMMA.Series(ds, period)[bar] * (1 - (pct / 100)); } } }); }
//populate public override void Populate() { TimeSeries ds = Parameters[0].AsTimeSeries; Int32 emaPeriod = Parameters[1].AsInt; Int32 rsiPeriod = Parameters[2].AsInt; DateTimes = ds.DateTimes; if (emaPeriod <= 0 || rsiPeriod <= 0 || ds.Count == 0) { return; } //Assign first bar that contains indicator data var FirstValidValue = Math.Max(ds.FirstValidIndex, Math.Max(emaPeriod, rsiPeriod)); if (FirstValidValue > ds.Count) { FirstValidValue = ds.Count; } var rbw = new WMA(ds, 2); var sve = 5 * rbw; for (int w = 4; w >= -4; w--) { rbw = new WMA(rbw, 2); if (w > 1) { sve += (w * rbw); } else { sve += rbw; } } sve /= 20d; // sve.Description = "SVE Rainbow"; var x = 0.1 * (new RSI(sve, rsiPeriod) - 50); var e1 = new EMA(x, emaPeriod); var e2 = new EMA(e1, emaPeriod); var z1ema = e1 + (e1 - e2); for (int bar = 0; bar < ds.Count; bar++) { Values[bar] = (InverseFisher.Calculate(bar, z1ema) + 1) * 50; } }
private void RunWma() { var list = GetAllModelForWeekday(selectedWeekday); var takeNumber = list.Count; var comeHomingValues = list.OrderByDescending(u => u.Date) .Select(z => new TimeSpan(0, int.Parse(z.Hour), int.Parse(z.Minutes), 0)) .Take(takeNumber) .ToList(); var prediction = WMA.WeightedMovingAverage( comeHomingValues.Select(y => TimeConverter.ConvertFromTimeToDouble(y.TotalMinutes)).ToArray(), 1, 0.05, 0.15, 0.20, 0.25, 0, 0.35); _predictWma = prediction.Value; }
//populate public override void Populate() { TimeSeries ds = Parameters[0].AsTimeSeries; Int32 stochPeriod = Parameters[1].AsInt; Int32 smoothingPeriod = Parameters[2].AsInt; DateTimes = ds.DateTimes; if (stochPeriod <= 0 || smoothingPeriod <= 0 || ds.Count == 0) { return; } var FirstValidValue = Math.Max(stochPeriod, smoothingPeriod); if (FirstValidValue > ds.Count) { FirstValidValue = ds.Count; } // Assymetric Rainbow smoothing, more weight on recent samples var ma = new WMA(ds, 2); int k = 5; var rbw = k * ma; for (int w = 4; w > -5; w--) { ma = new WMA(ma, 2); k = w > 0 ? w : 1; var kSer = k * ma; rbw += kSer; } rbw /= 20d; //rbw.Description = "StochRainbow"; var rbwStoch = StochD(rbw, stochPeriod, smoothingPeriod); var x = 0.1 * (rbwStoch - 50); for (int bar = FirstValidValue; bar < ds.Count; bar++) { double e2y = Math.Exp(2 * x[bar]); Values[bar] = 50 * ((e2y - 1) / (e2y + 1) + 1); // with scaling } }
public NRTR_WATR(Bars bars, int lookback, double multiple, string description) : base(bars, description) { base.FirstValidValue = lookback; int Trend = 0; double Reverse = 0; double HPrice = 0; double LPrice = 0; DataSeries K = WMA.Series(TrueRange.Series(bars), lookback) * multiple; for (int bar = base.FirstValidValue; bar < bars.Count; bar++) { // Calculate the NRTR_WATR Series if (Trend >= 0) { HPrice = Math.Max(bars.Close[bar], HPrice); Reverse = HPrice - K[bar]; if (bars.Close[bar] <= Reverse) { Trend = -1; LPrice = bars.Close[bar]; Reverse = LPrice + K[bar]; } } if (Trend <= 0) { LPrice = Math.Min(bars.Close[bar], LPrice); Reverse = LPrice + K[bar]; if (bars.Close[bar] >= Reverse) { Trend = 1; HPrice = bars.Close[bar]; Reverse = HPrice - K[bar]; } } base[bar] = Reverse; } }
public HullMA(DataSeries ds, int period, string description) : base(ds, description) { base.FirstValidValue = period; if (ds.Count < period) { return; } WMA SlowWMA = WMA.Series(ds, period); WMA FastWMA = WMA.Series(ds, (int)(period / 2)); DataSeries hma = WMA.Series((FastWMA + (FastWMA - SlowWMA)), (int)Math.Sqrt(period)); for (int bar = period; bar < ds.Count; bar++) { base[bar] = hma[bar]; } }
public void TestWMA() { long ticks = 1000; var data = new double[] { 20, 40, 22, 35, 33, 78, 21, 45, 33, 5, 67, 22, 98, 22, 34, 54 }; var input = new TimeSeries(); var wma = new WMA(input, 10); foreach (var d in data) { input.Add(new DateTime().AddTicks(ticks++), d); } Assert.Equal(wma[0], 32.6, precision); Assert.Equal(wma[1], 38.7454545454545, precision); Assert.Equal(wma[2], 35.8545454545455, precision); Assert.Equal(wma[3], 47.1090909090909, precision); Assert.Equal(wma[4], 43.1636363636364, precision); Assert.Equal(wma[5], 41.6363636363636, precision); Assert.Equal(wma[6], 43.7272727272727, precision); }
public override void Populate() { BarHistory bars = Parameters[0].AsBarHistory; Int32 smooth = Parameters[1].AsInt; Int32 sdPeriod = Parameters[2].AsInt; DateTimes = bars.DateTimes; var period = Math.Max(smooth, sdPeriod); if (period <= 0 || DateTimes.Count == 0 || bars.Count < period) { return; } FastSMA sma = new FastSMA(bars.Close, 2); TimeSeries sma1 = sma * 5; TimeSeries sma2 = new FastSMA(sma, 2) * 4; TimeSeries sma3 = new FastSMA(new FastSMA(sma, 2), 2) * 3; TimeSeries sma4 = new FastSMA(new FastSMA(new FastSMA(sma, 2), 2), 2) * 2; TimeSeries sma5 = new FastSMA(new FastSMA(new FastSMA(new FastSMA(sma, 2), 2), 2), 2); TimeSeries sma6 = new FastSMA(sma5, 2); TimeSeries sma7 = new FastSMA(sma6, 2); TimeSeries sma8 = new FastSMA(sma7, 2); TimeSeries sma9 = new FastSMA(sma8, 2); TimeSeries sma10 = new FastSMA(sma9, 2); TimeSeries Rainbow = (sma1 + sma2 + sma3 + sma4 + sma5 + sma6 + sma7 + sma8 + sma9 + sma10) / 20; TimeSeries ema1 = new EMA(Rainbow, smooth); TimeSeries ema2 = new EMA(ema1, smooth); TimeSeries diff = ema1 - ema2; TimeSeries ZLRB = ema1 + diff; TEMA_TASC tema = new TEMA_TASC(ZLRB, smooth); StdDev sd = new StdDev(tema, sdPeriod); WMA wma = new WMA(tema, sdPeriod); var PB = (tema + sd * 2 - wma) / (sd * 4) * 100; for (int bar = 0; bar < bars.Count; bar++) { base[bar] = PB[bar]; } }
public ShiftedMA(DataSeries ds, int period, int shift, ChoiceOfMA option, string description) : base(ds, description) { if (ds.Count < period + shift) { return; } if (option == ChoiceOfMA.SMA) { base.FirstValidValue = period + shift; } else { base.FirstValidValue = (period * 3) + shift; } for (int bar = FirstValidValue; bar < ds.Count; bar++) { if (option == ChoiceOfMA.EMA) { base[bar] = EMA.Series(ds, period, EMACalculation.Modern)[bar - shift]; } else if (option == ChoiceOfMA.SMA) { base[bar] = Community.Indicators.FastSMA.Series(ds, period)[bar - shift]; } else if (option == ChoiceOfMA.WMA) { base[bar] = WMA.Series(ds, period)[bar - shift]; } else if (option == ChoiceOfMA.SMMA) { base[bar] = SMMA.Series(ds, period)[bar - shift]; } } }
public KaseCD(Bars bars, int fastPeriod, int slowPeriod, string description) : base(bars, description) { base.FirstValidValue = Math.Max(fastPeriod, slowPeriod); DataSeries RWH = new DataSeries(bars, "RWH"); DataSeries RWL = new DataSeries(bars, "RWL"); for (int bar = FirstValidValue; bar < bars.Count; bar++) { RWH[bar] = (((bars.High[bar] - bars.Low[bar - slowPeriod])) / ((ATR.Series(bars, slowPeriod)[bar] * Math.Sqrt(slowPeriod)))); RWL[bar] = (((bars.High[bar - slowPeriod] - bars.Low[bar])) / ((ATR.Series(bars, slowPeriod)[bar] * Math.Sqrt(slowPeriod)))); } DataSeries Pk = Community.Indicators.FastSMA.Series(WMA.Series((RWH - RWL), fastPeriod), fastPeriod); DataSeries KCD = Pk - Community.Indicators.FastSMA.Series(Pk, slowPeriod); for (int bar = FirstValidValue; bar < bars.Count; bar++) { base[bar] = KCD[bar]; } }
//populate public override void Populate() { BarHistory bars = Parameters[0].AsBarHistory; Int32 BandsPeriod = Parameters[1].AsInt; Int32 MiddlePeriod = Parameters[2].AsInt; Double DevFact = Parameters[3].AsDouble; Double LowBandAdjust = Parameters[4].AsDouble; DateTimes = bars.DateTimes; int period = Math.Max(BandsPeriod, MiddlePeriod); if (period <= 0 || bars.Count == 0) { return; } if (bars.Count < Math.Max(BandsPeriod, MiddlePeriod)) { return; } var TypicalPrice = bars.AveragePriceHLC; TimeSeries typical = new TimeSeries(DateTimes); TimeSeries deviation = new TimeSeries(DateTimes); TimeSeries medianaverage = new TimeSeries(DateTimes); TimeSeries devhigh = new TimeSeries(DateTimes); TimeSeries devlow = new TimeSeries(DateTimes); TimeSeries UpperBand = new TimeSeries(DateTimes); // Use a price range var TempBuf = new TimeSeries(DateTimes); for (int i = 0; i < bars.Count; i++) { if (i == bars.Count - 1) { TempBuf[i] = bars.High[i] - bars.Low[i]; } else { TempBuf[i] = Math.Max(bars.High[i], bars.Close[i + 1]) - Math.Min(bars.Low[i], bars.Close[i + 1]); } } // calculate price deviation var AtrBuf = new TimeSeries(DateTimes); AtrBuf = new SMA(TempBuf, BandsPeriod * 2 - 1) * DevFact; // Create upper, lower channel and middle line var HighChannel = new TimeSeries(DateTimes); var LowChannel = new TimeSeries(DateTimes); HighChannel = new WMA(bars.Close, BandsPeriod) + new WMA(bars.Close, BandsPeriod) * AtrBuf / bars.Close; //LowChannel = new WMA.Series(bars.Close, BandsPeriod) - new WMA.Series(bars.Close, BandsPeriod) * AtrBuf * LowBandAdjust / bars.Close; for (int bar = Math.Max(BandsPeriod, MiddlePeriod); bar < bars.Count; bar++) { Values[bar] = HighChannel[bar]; } }