//populate public override void Populate() { //get parameter values TimeSeries source = Parameters[0].AsTimeSeries; int fastPeriod = Parameters[1].AsInt; int slowPeriod = Parameters[2].AsInt; DateTimes = source.DateTimes; //calculate EMA emaFast = new EMA(source, fastPeriod); EMA emaSlow = new EMA(source, slowPeriod); TimeSeries result = ((emaFast - emaSlow) / emaSlow) * 100.0; Values = result.Values; }
public void EMATest() { BacktestBroker backtestBroker = new BacktestBroker(); BrokerAccount brokerAccount = new BrokerAccount(); backtestBroker.LoadAccount(new BrokerAccount(), Guid.Empty); BacktestSession backtestSession = backtestBroker.CreateSession(brokerAccount.AccountId, SpotForex.EURUSD, Timeframes.M1, @"data\EURUSD-M1.bar", Guid.Empty); EMA ema = new EMA(Timeframes.M1, 100); backtestSession.Indicators.Add(ema); backtestSession.Start(); }
//populate public override void Populate() { TimeSeries ds = Parameters[0].AsTimeSeries; Int32 period = Parameters[1].AsInt; Boolean useEMA = Parameters[2].AsBoolean; DateTimes = ds.DateTimes; if (period <= 0 || ds.Count == 0 || ds.Count < period) { return; } var weight = 2d / (period + 1); TimeSeries sma = FastSMA.Series(ds, period); TimeSeries ema = EMA.Series(ds, period); TimeSeries ma = !useEMA ? sma : ema; double mdev = 0; var exd = new TimeSeries(DateTimes); var absDif = (ma - ds).Abs(); var Rate = 2 / (double)(period + 1); for (int i = 0; i > period; i--) { mdev += Math.Abs(ma[i] - ds[i]); } mdev /= period; for (int bar = 1; bar < ds.Count; bar++) { if (bar <= period) { exd[bar] = mdev; } else { exd[bar] = absDif[bar] * Rate + exd[bar - 1] * (1.0 - Rate); } } for (int bar = 0; bar < ds.Count; bar++) { Values[bar] = exd[bar]; } }
// returns price where MACD cross signal line or MACD histogram crosses 0 private double PMACDsignal(int bar, TimeSeries price, int periodX, int periodY, int periodZ) { double alphaX = 2.0 / (1.0 + periodX); double alphaY = 2.0 / (1.0 + periodY); double alphaZ = 2.0 / (1.0 + periodZ); double OneAlphaX = 1.0 - alphaX; double OneAlphaY = 1.0 - alphaY; double OneAlphaZ = 1.0 - alphaZ; // leftover? not used in the formula var ema1 = new EMA(price, periodX); var ema2 = new EMA(price, periodY); var macdex = ema1 - ema2; var macdexSignal = new EMA(macdex, periodZ); double MACDvalue = macdex[bar]; double MACDsignal = macdexSignal[bar]; return((MACDsignal - ema1[bar] * OneAlphaX + ema2[bar] * OneAlphaY) / (alphaX - alphaY)); }
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"TTMS momentum histogram with squeeze dots."; Name = "TTMS"; Calculate = Calculate.OnPriceChange; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = false; DrawHorizontalGridLines = false; DrawVerticalGridLines = false; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; IsSuspendedWhileInactive = true; MomentumLength = 20; SqueezeLength = 20; SqueezeDotBrush = Brushes.Red; NormalDotBrush = Brushes.Blue; HistAboveZeroRising = Brushes.Lime; HistAboveZeroFalling = Brushes.DarkSlateGray; HistBelowZeroFalling = Brushes.Red; HistBelowZeroRising = Brushes.DarkSlateGray; SoundAlertsOn = false; BuySoundAlert = "Alert3.wav"; SellSoundAlert = "Alert4.wav"; AddPlot(new Stroke(Brushes.DarkSlateGray, 5), PlotStyle.Bar, "MomentumHistogram"); AddPlot(new Stroke(NormalDotBrush, 2), PlotStyle.Dot, "SqueezeDots"); } else if (State == State.Configure) { lrm_ = new Series <double>(this); medianPriceOsc_ = new Series <double>(this); BB = Bollinger(2.0, SqueezeLength); KC = KeltnerChannel(1.5, SqueezeLength); DC = DonchianChannel(MomentumLength); LR = LinReg(medianPriceOsc_, MomentumLength); ema_ = EMA(MomentumLength); } }
public PBFastOsc(Bars bars, int period, int FSmooth, string description) : base(bars, description) { base.FirstValidValue = Math.Max(FSmooth, period) * 3; PBandLower PBL = PBandLower.Series(bars, period); PBandUpper PBU = PBandUpper.Series(bars, period); DataSeries A = bars.Close - PBL; DataSeries B = PBU - PBL; DataSeries Result = EMA.Series((A / B) * 100, FSmooth, EMACalculation.Modern); for (int bar = FirstValidValue; bar < bars.Count; bar++) { base[bar] = Result[bar]; } }
void Analysize(object sender, EventHandler.BackTesting.Datum e) { if (GetCheckOnTime(e.Date)) { Short.Pop(); Long.Pop(); } Short.Push(EMA.Make(specify.Short, Short.Count, e.Price, Short.Peek())); Long.Push(EMA.Make(specify.Long, Long.Count, e.Price, Long.Peek())); double popShort = Short.Pop(), popLong = Long.Pop(); bt.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify); Short.Push(popShort); Long.Push(popLong); if (specify.Time == 1440) { if (GetCheckTime(e.Date.ToString())) { OnReceiveTrend(e.Volume); } var date = e.Date.ToString().Substring(6, 6); if (date.Equals(end)) { bt.SetStatisticalStorage(e.Date.ToString().Substring(0, 6), e.Price, RollOver); } if (uint.TryParse(date, out uint cme) && cme > 45958 && cme < 85959) { bt.SellOrder.Clear(); bt.BuyOrder.Clear(); } if (bt.SellOrder.Count > 0 && e.Volume > 0) { bt.SetSellConclusion(e.Date.ToString(), e.Price, e.Volume); } if (bt.BuyOrder.Count > 0 && e.Volume < 0) { bt.SetBuyConclusion(e.Date.ToString(), e.Price, e.Volume); } } bt.TradingJudge[specify.Time] = popShort; }
public void TestCalculate() { double[] inputData = new double[] { 22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, 22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82, 23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 22.40, 22.17 }; int len = inputData.Length; double?[] outData = new double?[len]; int period = 10; EMA.Calculate(inputData, period, 2, outData); }
public PPO(DataSeries ds, int period1, int period2, string description) : base(ds, description) { FirstValidValue = Math.Max(period1, period2) * 3; if (FirstValidValue < 2) { FirstValidValue = 2; } WealthLab.Indicators.EMACalculation m = WealthLab.Indicators.EMACalculation.Modern; EMA ema1 = EMA.Series(ds, period1, m); EMA ema2 = EMA.Series(ds, period2, m); for (int bar = FirstValidValue; bar < ds.Count; bar++) { base[bar] = (ema1[bar] - ema2[bar]) / ema2[bar]; } }
public override void Populate() { TimeSeries ds = base.Parameters[0].AsTimeSeries; string symbol = Parameters[1].AsString; BarHistory idx = IndicatorFactory.GetHistory(ds, symbol, Bars.Scale); TimeSeries index = idx.Close; int period = base.Parameters[2].AsInt; int emaPeriod = base.Parameters[3].AsInt; this.DateTimes = ds.DateTimes; int FirstValidValue = Math.Max(period, emaPeriod) + 1; if (ds.Count < FirstValidValue) { return; } TimeSeries log1 = new TimeSeries(ds.DateTimes); TimeSeries log2 = new TimeSeries(index.DateTimes); TimeSeries tmp1 = new TimeSeries(ds.DateTimes); tmp1 = ds * 0; for (int i = 0; i < FirstValidValue; i++) { log1[i] = 0;// checked(Math.Log( ds[i] / index[i] )); log2[i] = 0; } for (int i = FirstValidValue; i < ds.Count; i++) { log1[i] = checked (Math.Log(ds[i] / index[i])); log2[i] = checked (Math.Log((ds[i - period]) / index[i - period])); tmp1[i] = log1[i] - log2[i]; } TimeSeries rsmk = EMA.Series(tmp1, emaPeriod) * 100d; for (int j = FirstValidValue; j < ds.Count; j++) { double val = rsmk[j]; base.Values[j] = double.IsNaN(val) ? 0 : val; } }
public static double[] GetSharpe(double[] prices, int numDaysReturns, bool useBPReturns, int SharpeWindow, int annualisationFactor, bool returnZScore, int ZWindow, bool exponentialSharpe) { double[] ret = CalculateReturns(prices, numDaysReturns, useBPReturns); int nRet = prices.Length; CircularBuffer <double> returns = new CircularBuffer <double>(SharpeWindow); CircularBuffer <double> sharpes = new CircularBuffer <double>(ZWindow); double decayFactor = 1 - 2.0 / (SharpeWindow + 1); EMA r_ema = new EMA(decayFactor); EWVol v_ema = new EWVol(decayFactor); for (int i = 0; i < nRet; ++i) { returns.Insert(ret[i]); if (returns.Full) { double sharpe = 0; if (!exponentialSharpe) { double r_t = (prices[i] - prices[i - SharpeWindow + 1]) / prices[i - SharpeWindow + 1] / SharpeWindow; sharpe = r_t / returns.SD() * Math.Sqrt(annualisationFactor); } else { r_ema.Update(ret[i]); v_ema.Update(ret[i]); sharpe = r_ema.Value / v_ema.Value * Math.Sqrt(annualisationFactor); } sharpes.Insert(sharpe); } } double[] r = new double[2]; r[0] = sharpes.Last(); r[1] = sharpes.Last() / sharpes.SD(); return(r); }
/* * public double MACDSignal * { * get * { * return signal.EMAverage; * } * }*/ public void Init(int shortPeriod, int longPeriod, int macdSumSize, int emaStartTime) { emaShort = new EMA(); emaShort.Init(shortPeriod, 1); //emaShort.Init(shortPeriod,emaStartTime); emaLong = new EMA(); emaLong.Init(longPeriod, 1); //emaLong.Init(longPeriod, emaStartTime); emaMacdSum = new EMA(); emaMacdSum.Init(longPeriod * 5, emaStartTime); macdSum = new MovingSum(); macdSum.Init(macdSumSize); //signal = new EMA(); //signal.Init(signalPeriod, emaStartTime); //this.signalThreshold = signalThreshold; }
public IrwinCycle(Bars bars, DataSeries ds, int period, string description) : base(ds, description) { base.FirstValidValue = period * 3; Highest H1 = Highest.Series(bars.High, period); Lowest L1 = Lowest.Series(bars.Low, period); DataSeries C1 = H1 - L1; EMA R1 = EMA.Series(((ds - L1) / C1) * 100, 3, EMACalculation.Modern); Highest H2 = Highest.Series(R1, period); Lowest L2 = Lowest.Series(R1, period); DataSeries C2 = H2 - L2; DataSeries Result = EMA.Series(((R1 - L2) / C2) * 100, 3, EMACalculation.Modern); for (int bar = FirstValidValue; bar < bars.Count; bar++) { base[bar] = Result[bar]; } }
public static XElement GetEmaElement(EMA ema) { var result = new XElement("Material"); result.SetAttributeValueWithDefault("Name", ema.Name); result.SetAttributeValueWithDefault("Color1", ema.Color1.GetString(), "Transparent"); result.SetAttributeValueWithDefault("Color2", ema.Color2.GetString(), "Transparent"); result.SetAttributeValueWithDefault("Color3", ema.Color3.GetString(), "Transparent"); result.SetAttributeValueWithDefault("Color4", ema.Color4.GetString(), "Transparent"); result.SetAttributeValueWithDefault("Float1", ema.Float1); result.SetAttributeValueWithDefault("Int1", ema.Int1); result.SetAttributeValueWithDefault("Int2", ema.Int2); result.SetAttributeValueWithDefault("Int3", ema.Int3); foreach (var texture in ema.Textures) { var e = new XElement("Texture"); e.SetAttributeValueWithDefault("Asset", texture.Asset); e.SetAttributeValueWithDefault("IntArray1", string.Join(",", texture.IntArray1), "0,0,0,0"); e.SetAttributeValueWithDefault("IntArray2", string.Join(",", texture.IntArray2), "0,0,0"); result.Add(e); } foreach (var transform in ema.DefaultTransforms) { var e = new XElement("DefaultTransform"); e.SetAttributeValueWithDefault("ScaleU", transform.ScaleU, 1); e.SetAttributeValueWithDefault("ScaleV", transform.ScaleV, 1); e.SetAttributeValueWithDefault("Rotation", transform.Rotation); e.SetAttributeValueWithDefault("TranslationU", transform.TranslationU); e.SetAttributeValueWithDefault("TranslationV", transform.TranslationV); result.Add(e); } foreach (var block in ema.AnimationBlocks) { var e = new XElement("AnimationBlock"); e.AddIfNotEmpty(GetKeyframeBlockElement(block.ScaleU, "ScaleU")); e.AddIfNotEmpty(GetKeyframeBlockElement(block.ScaleV, "ScaleV")); e.AddIfNotEmpty(GetKeyframeBlockElement(block.Rotation, "Rotation")); e.AddIfNotEmpty(GetKeyframeBlockElement(block.TranslationU, "TranslationU")); e.AddIfNotEmpty(GetKeyframeBlockElement(block.TranslationV, "TranslationV")); result.Add(e); } return(result); }
private void CalculateRenkoValues() { _rVar51Sma = SMA(51)[0]; _rVar20Ema = EMA(20); _rVarUpperFractal0 = FractalLevel(1).UpFractals[0]; _rVarLowerFractal0 = FractalLevel(1).DownFractals[0]; _rVarWaveBLong = NtGetWaveBLong(0); _rVarWaveBShort = NtGetWaveBShort(0); _rVarWaveALong = NtGetWaveALong(0); _rVarWaveAShort = NtGetWaveAShort(0); var r = HeikenAshi().HAClose[0]; //Print("Plot 0 is: " + FractalLevel(1).Plot0[0]); //Print("Plot 1 is: " + FractalLevel(1).Plot1[0]); if (!_series2) { _series2 = true; } }
public void TestCalculateRealData() { TickerBLL tbll = new TickerBLL(_unit); List <Ticker> tList = tbll.GetTickerListByShareDB(1585, null, 21100000); double[] inputData = new double[tList.Count]; double?[] outData = new double?[tList.Count]; var i = 0; foreach (var t in tList) { inputData[i] = t.Close; i++; } Result res = EMA.Calculate(inputData, 20, 2, outData); }
public void TestEMA() { double[] inputData = new double[] { 22.27, 22.19, 22.08, 22.17, 22.18, 22.13, 22.23, 22.43, 22.24, 22.29, 22.15, 22.39, 22.38, 22.61, 23.36, 24.05, 23.75, 23.83, 23.95, 23.63, 23.82, 23.87, 23.65, 23.19, 23.10, 23.33, 22.68, 23.10, 22.40, 22.17 }; int len = inputData.Length; double?[] outData = new double?[len]; int period = 10; EMA.Calculate(inputData, period, 2, outData); Console.WriteLine(ObjectHelper.ToJson(outData)); }
public static List <Model.Candle> HA_D_Candles(Instrument instrument, out InstrumentDayPrice instrumentDayPrice) { instrumentDayPrice = new InstrumentDayPrice(); Model.Candle haPreviounsCandle = null; Model.Candle haCurrentCandle = null; List <Model.Candle> haCandles = new List <Candle>(); List <Model.Candle> candles = Data.Prices.GetCandles(instrument.Name, 22, "D"); EMA ema = new EMA(22); for (int i = 0; i < candles.Count; i++) { instrumentDayPrice.Max = Math.Max(instrumentDayPrice.Max, candles[i].Hight); instrumentDayPrice.Current = candles.LastOrDefault().Close; if (i == 0) { instrumentDayPrice.Min = candles[i].Low; instrumentDayPrice.Min = Math.Min(candles[i].Low, instrumentDayPrice.Min); haPreviounsCandle = Data.Candle.GeneratePrevious(candles[i]); haCandles.Add(haPreviounsCandle); //Console.WriteLine(haPreviounsCandle.OriginalColor); } else { haCurrentCandle = Data.Candle.Generate(haPreviounsCandle, candles[i]); //Console.WriteLine(haCurrentCandle.OriginalColor); haCandles.Add(haCurrentCandle); haPreviounsCandle = haCurrentCandle; } if (i < 5) { ema.AddDataPoint(candles[i].Close); } else { instrumentDayPrice.EMA = ema.Average; } } return(haCandles); }
public OutParameter InitialForecast() { HistryData histryData; float avg = 0, crntPrice = 0, initialAvg; try{ if ((histryData = rqstController.GetHistoricalData(parameters.Coin, 2000)) != null) { if (parameters.Strategy.Equals("SMA")) { avg = new SMA().GetAverage(histryData.Data.ConvertAll(data => data.close).GetRange(2000 - parameters.Limit - 2, parameters.Limit)); crntPrice = this.LiveMarketPrice(); } else if (parameters.Strategy.Equals("EMA")) { MovingAverage ma = new EMA(); initialAvg = ma.GetAverage(histryData.Data.ConvertAll(data => data.close).GetRange(0, 100)); avg = ma.PredictedPrice(histryData.Data.ConvertAll(data => data.close).GetRange(100, 1900), initialAvg, parameters.Period); crntPrice = this.LiveMarketPrice(); } else if (parameters.Strategy.Equals("EMADC")) { MovingAverage ma = new EMA(); initialAvg = ma.GetAverage(histryData.Data.ConvertAll(data => data.close).GetRange(0, 100)); avg = ma.PredictedPrice(histryData.Data.ConvertAll(data => data.close).GetRange(100, 1900), initialAvg, parameters.Period_1); crntPrice = ma.PredictedPrice(histryData.Data.ConvertAll(data => data.close).GetRange(100, 1900), initialAvg, parameters.Period); } coinUpdate[parameters.Coin] = Builder <OutParameter> .CreateNew().With(x => x.Coin = parameters.Coin) .With(x => x.Current = crntPrice).With(x => x.Predicted = avg) .With(x => x.Decision = this.Decision(crntPrice, avg)).Build(); return(coinUpdate[parameters.Coin]); } else { System.Diagnostics.Debug.WriteLine("Exiting App..."); } } catch (Exception ex) { Console.WriteLine("Exception: " + ex); } return(null); }
//populate public override void Populate() { TimeSeries ds = Parameters[0].AsTimeSeries; Int32 period = Parameters[1].AsInt; Int32 volaperiod = Parameters[2].AsInt; DateTimes = ds.DateTimes; if (period <= 0 || ds.Count == 0) { return; } //Avoid exception errors if (period < 12) { period = 12; // 3 is minimum for LinearReg, that uses 1/4 of period } period = period / 2; var y = new EMA(ds, period / 2) / new EMA(ds, period); var lry = new LR(y, period / 2); var dvs = new DVS(ds, volaperiod); //Assign first bar that contains indicator data var FirstValidValue = Math.Max(dvs.FirstValidIndex, ds.FirstValidIndex + period + period / 2 - 2); //Initialize start of series with zeroes //for (int bar = 0; bar < FirstValidValue; bar++) // Values[bar] = 0; //Rest of series for (int bar = FirstValidValue; bar < ds.Count; bar++) { if (dvs[bar] != 0) { Values[bar] = 10000 * (lry[bar] - 1) / dvs[bar]; } } //else // Values[bar] = 0; }
//ABCDWave abcdWave = null; #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { // These only display for the primary Bars object on the chart BarsArray[0] ema = EMA(EmaPeriod); Add(ema); ema.Plots[0].Pen.Color = Color.Black; ema.Plots[0].Pen.Width = 2; sma = SMARick(SmaPeriod); Add(sma); sma200 = SMARick(100); Add(sma200); //abcdWave = ncatABCDWave(true, true, true, 5000, "bextABCD", "bexI_ABCD", "bexIT_ABCD", "8", 20, true, false); SetTrailStop(CalculationMode.Percent, trailingStop); SetProfitTarget(CalculationMode.Percent, profitTarget); CalculateOnBarClose = true; }
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]; } }
//populate public override void Populate() { TimeSeries ds = Parameters[0].AsTimeSeries; Int32 period = Parameters[1].AsInt; Double deviations = Parameters[2].AsDouble; DateTimes = ds.DateTimes; if (period <= 0 || ds.Count == 0 || ds.Count < period) { return; } var ema = new EMA(ds, 20); var esd = new EStdDev(ds, period); for (int bar = period; bar < ds.Count; bar++) { Values[bar] = ema[bar] - esd[bar] * deviations; } }
public TSI(DataSeries ds, int period1, int period2, string description) : base(ds, description) { base.FirstValidValue = Math.Max(period1, period2) * 3; if (FirstValidValue <= 1) { return; } DataSeries mtm = Momentum.Series(ds, 1); DataSeries absmtm = DataSeries.Abs(mtm); DataSeries Numer = EMA.Series(EMA.Series(mtm, period1, EMACalculation.Modern), period2, EMACalculation.Modern); DataSeries Denom = EMA.Series(EMA.Series(absmtm, period1, EMACalculation.Modern), period2, EMACalculation.Modern); DataSeries TS = Numer / Denom; DataSeries TSI = TS * 100; for (int bar = base.FirstValidValue; bar < ds.Count; bar++) { base[bar] = TSI[bar]; } }
internal void DrawChart(string time, int price) { if (GetCheckOnTimeByAPI(time)) { Short.Pop(); Long.Pop(); Trend.Pop(); } Short.Push(EMA.Make(specify.Short, Short.Count, price, Short.Peek())); Long.Push(EMA.Make(specify.Long, Long.Count, price, Long.Peek())); Trend.Push(EMA.Make(specify.Trend, Trend.Count, price, Trend.Peek())); double popShort = Short.Pop(), popLong = Long.Pop(), gap = popShort - popLong - (Short.Peek() - Long.Peek()); Short.Push(popShort); Long.Push(popLong); if (specify.Short < Short.Count && specify.Long < Long.Count && specify.Trend < Trend.Count && price < Trend.Peek() && gap > 0 && (price <= Price || Price == 0) && price <= BuyPrice) { Price = API.OnReceiveOrder(Code, price); } }
public MCO(Bars advBars, Bars decBars, int period1, int period2, string description) : base(advBars, description) { DataSeries Advancers = advBars.Close; DataSeries Decliners = decBars.Close; EMACalculation md = EMACalculation.Modern; base.FirstValidValue = Math.Max(period1, period2) * 3; if (FirstValidValue <= 1) { return; } DataSeries AD_Diff = Advancers - Decliners; DataSeries MCO = EMA.Series(AD_Diff, period1, md) - EMA.Series(AD_Diff, period2, md); for (int bar = base.FirstValidValue; bar < advBars.Count; bar++) { base[bar] = MCO[bar]; } }
void Analysize(object sender, Datum e) { if (GetCheckOnTimeByAPI(e.Time)) { Short.Pop(); Long.Pop(); } Short.Push(EMA.Make(specify.Short, Short.Count, e.Price, Short.Peek())); Long.Push(EMA.Make(specify.Long, Long.Count, e.Price, Long.Peek())); double popShort = Short.Pop(), popLong = Long.Pop(); API.Max(popShort - popLong - (Short.Peek() - Long.Peek()), specify, Check); Short.Push(popShort); Long.Push(popLong); API.TradingJudge[specify.Time] = popShort; if (specify.Time == 1440 && GetCheckTime(e.Time)) { OnReceiveTrend(e.Volume); } }
public double[] CalculateEMA(IEnumerable <Quote> quotes, int period) { var listOhlc = quotes.Select( x => new Ohlc { Date = x.Date, Close = x.Close, AdjClose = x.Close, High = x.High, Low = x.Low, Open = x.Open, Volume = x.Volume }).ToList(); var ema = new EMA(period, true); ema.Load(listOhlc); var result = ema.Calculate(); return(result.Values.Select(x => x.GetValueOrDefault()).ToArray()); }
public DerivativeOscillator(DataSeries ds, int periodRSI, int periodEMA1, int periodEMA2, int periodSMA, string description) : base(ds, description) { base.FirstValidValue = Math.Max(Math.Max(Math.Max(periodEMA1, periodEMA2), periodSMA), periodRSI); if (FirstValidValue <= 1) { return; } EMACalculation em = EMACalculation.Modern; RSI rsi = RSI.Series(ds, periodRSI); EMA rsiEma1 = EMA.Series(rsi, periodEMA1, em); EMA rsiEma2 = EMA.Series(rsiEma1, periodEMA2, em); DataSeries rsiSma = Community.Indicators.FastSMA.Series(rsiEma2, periodSMA); DataSeries derivOsc = rsiEma2 - rsiSma; for (int bar = base.FirstValidValue; bar < ds.Count; bar++) { base[bar] = derivOsc[bar]; } }
protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Strategy here."; Name = "ThreeEMA"; Calculate = Calculate.OnEachTick; EntriesPerDirection = 1; EntryHandling = EntryHandling.AllEntries; IsExitOnSessionCloseStrategy = true; ExitOnSessionCloseSeconds = 30; IsFillLimitOnTouch = false; MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix; OrderFillResolution = OrderFillResolution.Standard; Slippage = 0; StartBehavior = StartBehavior.WaitUntilFlat; TimeInForce = TimeInForce.Gtc; TraceOrders = false; RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose; StopTargetHandling = StopTargetHandling.PerEntryExecution; BarsRequiredToTrade = 20; // Disable this property for performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = true; EMA_Period1 = 5; EMA_Period2 = 30; EMA_Period3 = 60; Profit_Target = 10; } else if (State == State.Configure) { } else if (State == State.DataLoaded) { EMA1 = EMA(Close, Convert.ToInt32(EMA_Period3)); CurrentDayOHL1 = CurrentDayOHL(Close); EMA2 = EMA(Close, Convert.ToInt32(EMA_Period1)); EMA3 = EMA(Close, Convert.ToInt32(EMA_Period2)); } }