Overall Statistics |
Total Trades 10 Average Win 36.91% Average Loss -0.99% Compounding Annual Return 312.608% Drawdown 19.400% Expectancy 29.577 Net Profit 234.559% Sharpe Ratio 2.416 Loss Rate 20% Win Rate 80% Profit-Loss Ratio 37.22 Alpha 1.011 Beta 0.478 Annual Standard Deviation 0.442 Annual Variance 0.196 Information Ratio 2.144 Tracking Error 0.442 Treynor Ratio 2.233 Total Fees $0.00 |
using System; using System.Linq; using QuantConnect.Data.Market; using QuantConnect.Indicators; namespace QuantConnect.Algorithm.CSharp { public class BasicTemplateAlgorithm : QCAlgorithm { private SimpleMovingAverage _fast; private SimpleMovingAverage _slow; private RelativeStrengthIndex _rsi; private string _sym = QuantConnect.Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX); public override void Initialize() { SetStartDate(2017, 1, 1); //Set Start Date SetEndDate(DateTime.Now); AddCrypto("BTCUSD", Resolution.Minute, Market.GDAX); SetCash(40000); _fast = SMA("BTCUSD", 5, Resolution.Daily); _slow = SMA("BTCUSD", 18, Resolution.Daily); _rsi = RSI("BTCUSD", 14, MovingAverageType.Simple, Resolution.Daily); } public override void OnData(Slice data) { Plot(_sym, "Price", Securities[_sym].Price); Plot(_sym, _fast, _slow); Plot(_sym, "RSI", _rsi); if (! _rsi.IsReady) return; // define a small tolerance on our checks to avoid bouncing const decimal tolerance = 0.00015m; var holdings = Portfolio[_sym].Quantity; Log("HOLDINGS " + holdings); // we only want to go long if we're currently short or flat if (holdings <= 0) { Log("FASTSMA " + _fast); Log("SLOWSMA " + _slow); Log("RSI " + _rsi); // if the fast is greater than the slow, we'll go long //if (_fast > _slow * (1 + tolerance)) if(_rsi < 30) { Log("BUY >> " + Securities[_sym].Price); SetHoldings(_sym, 1.0); } } // we only want to liquidate if we're currently long // if the fast is less than the slow we'll liquidate our long if (holdings > 0 && _rsi > 80) { Log("SELL >> " + Securities[_sym].Price); Liquidate(_sym); } } } }