public Signal MACD(List <Double> askTemp, int longPeriod = 26, int midPeriod = 12, int shortPeriod = 9) { try { if (askTemp.Count >= longPeriod) { List <Double> ask = askTemp.GetRange(askTemp.Count - longPeriod, longPeriod); macdLine.Add(exponentialMovingAverage(ask.GetRange(ask.Count - midPeriod, midPeriod)) - exponentialMovingAverage(ask)); if (macdLine.Count >= shortPeriod) { signalLine.Add(exponentialMovingAverage(macdLine)); } if (macdLine.Count > shortPeriod) { if ((macdLine[macdLine.Count - 2] >= signalLine[signalLine.Count - 2]) && (macdLine[macdLine.Count - 1] < signalLine[signalLine.Count - 1])) { trendCurrent = CurrentTrend.Bearish; return(Signal.Sell); } else if ((macdLine[macdLine.Count - 2] < signalLine[signalLine.Count - 2]) && (macdLine[macdLine.Count - 1] >= signalLine[signalLine.Count - 1])) { trendCurrent = CurrentTrend.Bullish; return(Signal.Buy); } } } } catch (Exception e) { logger.Warn("Maybe a message has been skipped"); logger.Warn(e.Message); logger.Warn(e.StackTrace); } return(Signal.Hold); }
//static public decimal SavedMoney { get; set; } //static public decimal SavedCoins { get; set; } public static string CsvRow() { return(string.Format("{0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}, {13}, {14}, {15}, {16}, {17}, {18}", CandleDate.ToString(CultureInfo.InvariantCulture), Bid.ToString(CultureInfo.InvariantCulture), Math.Round(EmaDiff, 4).ToString(CultureInfo.InvariantCulture), Math.Round(Macd, 4).ToString(CultureInfo.InvariantCulture), Math.Round(MacdStandard, 4).ToString(CultureInfo.InvariantCulture), Math.Round(Roc, 4).ToString(CultureInfo.InvariantCulture), Math.Round(RocSpeed, 4).ToString(CultureInfo.InvariantCulture), CurrentTrend.ToString(), CurrentLongTermTrend.ToString(), SuggestedAction.ToString(), (Action == TradeAction.Unknown || Action == TradeAction.Hold) ? "" : Action.ToString(), Indicator, Motivation, Note, Math.Round(TotMoney, 4).ToString(CultureInfo.InvariantCulture), Math.Round(TotCoins, 4).ToString(CultureInfo.InvariantCulture), Math.Round(TotValue, 4).ToString(CultureInfo.InvariantCulture), Math.Round(SellAt, 4).ToString(CultureInfo.InvariantCulture), Math.Round(BuyAt, 4).ToString(CultureInfo.InvariantCulture) )); }
public Signal BollingerBand(List <Double> bidTemp, List <Double> askTemp, int period = 20) { if (bidTemp.Count >= period) { List <Double> bid = bidTemp.GetRange(bidTemp.Count - period, period); List <Double> ask = askTemp.GetRange(askTemp.Count - period, period); Double upperLimit = bid.Mean() + (2 * bid.StandardDeviation()); Double lowerLimit = ask.Mean() - (2 * ask.StandardDeviation()); if (ask[ask.Count - 1] <= lowerLimit && trendBolingerBand != CurrentTrend.Bullish) { trendBolingerBand = CurrentTrend.Bullish; return(Signal.Buy); } else if (bid[bid.Count - 1] >= upperLimit && trendBolingerBand != CurrentTrend.Bearish) { trendBolingerBand = CurrentTrend.Bearish; return(Signal.Sell); } } return(Signal.Hold); }