public static List <Stoch> Stochastic(StockData aStock, int aFastKPeriod, int aSlowKPeriod, int aSlowDPeriod) { int nStartIndex = 0; int nEndIndex = aStock.DataPoints.Count - 1; double[] nInHigh = getHighValues(aStock); double[] nInLow = getLowValues(aStock); double[] nInClose = getCloseValues(aStock); int nOutBegIdx; int nOutNBElement; double[] nOutSlowK = new double[nEndIndex - nStartIndex + 1]; double[] nOutSlowD = new double[nEndIndex - nStartIndex + 1]; TicTacTec.TA.Library.Core.Stoch(nStartIndex, nEndIndex, nInHigh, nInLow, nInClose, aFastKPeriod, aSlowKPeriod, Core.MAType.Sma, aSlowDPeriod, Core.MAType.Sma, out nOutBegIdx, out nOutNBElement, nOutSlowK, nOutSlowD); List <Stoch> nOutput = new List <Stoch>(); for (int j = 0; j < nOutBegIdx; j++) { nOutput.Add(new Stoch()); } for (int i = nStartIndex; i < nEndIndex - nStartIndex + 1 - nOutBegIdx; i++) { Stoch nStoch = new Stoch(); nStoch.SlowK = nOutSlowK[i]; nStoch.SlowD = nOutSlowD[i]; nOutput.Add(nStoch); } return(nOutput); }
public override void Compute(StockData aStockData) { List <Stoch> nStochs = TAUtil.Stochastic(aStockData, 14, 3, 3); Stoch nCurStoch = nStochs[nStochs.Count - 1]; if (nCurStoch.SlowK < 20) { this.Score = 1; this.Signal = true; } }
/// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { var diff = zmax[0] - zmin[0]; if (diff > 0.0) { Stoch.Set((Input[0] - zmin[0]) / diff); } else { Stoch.Set(0.5); } }
public static StochItem Stoch(this IEnumerable <ICandle> candles, int?fastPeriod = null, int?slowKPeriod = null, TicTacTec.TA.Library.Core.MAType?slowKmaType = null, int?slowDPeriod = null, TicTacTec.TA.Library.Core.MAType?slowDmaType = null) { fastPeriod ??= 5; slowKPeriod ??= 3; slowKmaType ??= TicTacTec.TA.Library.Core.MAType.Sma; slowDPeriod ??= 3; slowDmaType ??= TicTacTec.TA.Library.Core.MAType.Sma; IIndicatorOptions options = new StochOptions(fastPeriod.Value, slowDPeriod.Value, slowKmaType.Value, slowDPeriod.Value, slowDmaType.Value); Stoch stosh = new Stoch(); return((StochItem)stosh.Get(candles, options)); }
// TODO: implement smooth public static Stoch[] GetStoch(float[] high, float[] low, float[] close, int kperiod = 14, int dperiod = 3, int smooth = 1) { Stoch[] stochs = new Stoch[high.Length - kperiod]; for (int c = kperiod; c < high.Length; c++) { float highest = high[c], lowest = low[c]; for (int i = c - kperiod; i < c; i++) { if (highest < high[i]) { highest = high[i]; } else if (lowest > low[i]) { lowest = low[i]; } } stochs[c - kperiod].stoch = (close[c] - lowest) / (highest - lowest) * 100; // %K if (c - kperiod - dperiod + 1 <= 0) { stochs[c - kperiod].stoch_ma = 0; } else { List <float> tmp = new List <float>(dperiod); for (int i = c - kperiod - dperiod; i < c - kperiod; i++) { tmp.Add(stochs[i].stoch); } stochs[c - kperiod].stoch_ma = GetSMA(tmp.ToArray(), dperiod).Last(); // %D } } return(stochs); }
internal static TradeIdeasGeneratorArgument Create(List <Signal> signals, HistoricalData historicalData) { TradeIdeasGeneratorArgument result = new TradeIdeasGeneratorArgument(); SmaVol smaVol20 = new SmaVol(20); Sma sma50 = new Sma(50); Rsi stRsi5 = new Rsi(5); Rsi rsi14 = new Rsi(14); Rsi ltrsi50 = new Rsi(50); Cci stCci5 = new Cci(5); Cci cci14 = new Cci(14); Cci ltCci50 = new Cci(50); Stoch stoch14 = new Stoch(14, 14, 3); WillR willr14 = new WillR(14); Mfi mfi14 = new Mfi(14); Adx adx20 = new Adx(20); Atr atr20 = new Atr(20); //Assuming that signals are sorted by dates descending and all signals are present. otherwize an exception will be thrown during fetching signals (First()) #region Indicators result.Rsi14 = GetValue(signals.LatestForIndicator(rsi14)); result.YesterdayRsi14 = GetValue(signals.PreviousForIndicator(rsi14, 1)); result.StRsi5 = GetValue(signals.LatestForIndicator(stRsi5)); result.YesterdayStRsi5 = GetValue(signals.PreviousForIndicator(stRsi5, 1)); result.LtRsi50 = GetValue(signals.LatestForIndicator(ltrsi50)); result.Cci14 = GetValue(signals.LatestForIndicator(cci14)); result.YesterdayCci14 = GetValue(signals.PreviousForIndicator(cci14, 1)); result.StCci5 = GetValue(signals.LatestForIndicator(stCci5)); result.YesterdayStCci5 = GetValue(signals.PreviousForIndicator(stCci5, 1)); result.LtCci50 = GetValue(signals.LatestForIndicator(ltCci50)); result.Stoch14 = GetValue(signals.LatestForIndicator(stoch14)); result.YesterdayStoch14 = GetValue(signals.PreviousForIndicator(stoch14, 1)); result.WillR14 = GetValue(signals.LatestForIndicator(willr14)); result.YesterdayWillR14 = GetValue(signals.PreviousForIndicator(willr14, 1)); result.Mfi14 = GetValue(signals.LatestForIndicator(mfi14)); result.YesterdayMfi14 = GetValue(signals.PreviousForIndicator(mfi14, 1)); result.SmaVol20 = GetValue(signals.LatestForIndicator(smaVol20)); result.Sma50 = GetValue(signals.LatestForIndicator(sma50)); result.Adx20 = GetValue(signals.LatestForIndicator(adx20)); result.Atr20 = GetValue(signals.LatestForIndicator(atr20)); //Long Term Sentiment(6 months) Signal syrahSentiment = signals.LatestForIndicator(LongTermSentimentForDependencies); int? sentimentValue = syrahSentiment == null ? null : (int?)syrahSentiment.Value; result.LongTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue); //Short Term Sentiment(1 month) syrahSentiment = signals.LatestForIndicator(ShortTermSentimentForDependencies); sentimentValue = syrahSentiment == null ? null : (int?)syrahSentiment.Value; result.ShortTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue); #endregion //if (expandedQuote == null) //{ // result.LastPrice = historicalData.Close[historicalData.Count - 1]; //} //else //{ // result.LastPrice = expandedQuote.Last; // result.HasOption = expandedQuote.HasOption; //} result.RangeStdDev = historicalData.GetPriceRangeStdDevFor6Months(); //result.NearestSupport = supportAndResistance.GetClosestSupport(expandedQuote.Last); //result.NearestResistance = supportAndResistance.GetClosestResistance(expandedQuote.Last); //TODO: check int yesterdayIndex = historicalData.High.Length - 2; result.YesterdayHigh = historicalData.High[yesterdayIndex]; result.YesterdayLow = historicalData.Low[yesterdayIndex]; return(result); }