Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Strategies

Steven Thewissen edited this page May 1, 2018 · 10 revisions

At the heart of this bot sit the strategies. These are all implementations of the BaseStrategy class and contain a Prepare() method that expects a List<Candle> object. This method returns a list of TradeAdvice values containing any of these three values:

  • TradeAdvice.Sell - This is a sell signal.
  • TradeAdvice.Buy - This is a buy signal
  • TradeAdvice.Hold - This is the signal to do absolutely nothing.

Within this preparation method you are free to use any type of indicator you want to determine what action to take at a specific moment in time.

Signal candle

Each strategy has to implement the GetSignalCandle() method. This method can be used when determining a buying price by setting the BuyInPriceStrategy setting to SignalCandleClose.

Sample strategy

public class SmaCrossover : BaseStrategy
{
    public override string Name => "SMA Crossover";
    public override int MinimumAmountOfCandles => 26;
    public override Period IdealPeriod => Period.Hour;

    public override List<TradeAdvice> Prepare(List<Candle> candles)
    {
        {
            var result = new List<TradeAdvice>();

            var sma12 = candles.Sma(12);
            var sma26 = candles.Sma(26);
            var crossOver = sma12.Crossover(sma26);
            var crossUnder = sma12.Crossunder(sma26);

            for (int i = 0; i < candles.Count; i++)
            {
                // Since we look back 1 candle, the first candle can never be a signal.
                if (i == 0)
                    result.Add(TradeAdvice.Hold);
                // When the fast SMA moves above the slow SMA, we have a positive cross-over
                else if (crossOver[i])
                    result.Add(TradeAdvice.Buy);
                // When the slow SMA moves above the fast SMA, we have a negative cross-over
                else if (crossUnder[i])
                    result.Add(TradeAdvice.Sell);
                else
                    result.Add(TradeAdvice.Hold);
            }

            return result;
        }
    }

    public override Candle GetSignalCandle(List<Candle> candles)
    {
        return Prepare(candles).LastOrDefault();
    }

    public override TradeAdvice Forecast(List<Candle> candles)
    {
        return Prepare(candles).LastOrDefault();
    }
}
Clone this wiki locally