Overall Statistics
Total Trades
170
Average Win
3.41%
Average Loss
-5.92%
Compounding Annual Return
-60.923%
Drawdown
71.700%
Expectancy
-0.165
Net Profit
-64.005%
Sharpe Ratio
-0.885
Loss Rate
47%
Win Rate
53%
Profit-Loss Ratio
0.58
Alpha
0.108
Beta
-43.398
Annual Standard Deviation
0.553
Annual Variance
0.305
Information Ratio
-0.91
Tracking Error
0.553
Treynor Ratio
0.011
Total Fees
$0.00
using QuantConnect.Brokerages;
using QuantConnect.Indicators;
using QuantConnect.Orders;
using QuantConnect.Interfaces;
using QuantConnect.Data.Consolidators;
using QuantConnect.Data.Market;
using QuantConnect.Data;

namespace QuantConnect.Algorithm.CSharp
{
    
    class CryptoRsi : QCAlgorithm
    {
        Securities.Crypto.Crypto _crypto;
        int _RSI_Period = 14;               // RSI Look back period 
        int _RSI_OB = 60;                // RSI Overbought level
        int _RSI_OS   = 40;               // RSI Oversold level
        RelativeStrengthIndex _rsi;
        public override void Initialize()
        {
            SetStartDate(2017, 01, 01);
            SetEndDate(2018, 02, 01);
            SetCash(1000);

            _crypto = AddCrypto("BTCUSD", Resolution.Hour, "bitfinex");
            _rsi = RSI(_crypto.Symbol, _RSI_Period);
            SetWarmup(_RSI_Period);
        }

        public override void OnData(Slice slice)
        {

            if (!Portfolio.Invested && _rsi.Current.Value < _RSI_OS)
            {
                SetHoldings(_crypto.Symbol, 1);
            }
            else if(Portfolio.Invested && _rsi.Current.Value > _RSI_OB)
            {
                Liquidate(_crypto.Symbol);
            }
        }

        public override void OnEndOfAlgorithm()
        {
            if(Portfolio.Invested)
                Liquidate(_crypto.Symbol);

            Debug("----------initial cash=1000 final cash=" + Portfolio.Cash);

            Debug("invested=" + Portfolio.Invested + " MarginRemaining=" + Portfolio.MarginRemaining + " TotalPortfolioValue=" + Portfolio.TotalPortfolioValue);
        }
    }
}