Overall Statistics
//Copyright HardingSoftware.com, 2018.
//Granted to the public domain.
//Use at your own risk.
namespace QuantConnect.Algorithm.CSharp
{
    public class Coins : QCAlgorithm
    {
		string tickersString ="BTCUSD,ETHUSD,LTCUSD";
		Resolution resolution=Resolution.Hour;
		List<StockData> stockDatas = new List<StockData>();
		int rsiPeriod=24;
		string stockHeld="";
		
        public override void Initialize() 
        {
            SetStartDate(2017, 1, 1);    
            SetEndDate(DateTime.Now);
            SetCash(100);
			string[] tickers = tickersString.Split(new string[1] { "," }, StringSplitOptions.RemoveEmptyEntries);
			foreach (string ticker in tickers)
			{
				Symbol symbol = QuantConnect.Symbol.Create(ticker, SecurityType.Crypto, Market.GDAX);
				AddCrypto(symbol, resolution);
				StockData stockData=new StockData();
				stockData.Ticker=ticker;
				stockData.Rsi=RSI(ticker,rsiPeriod,MovingAverageType.Exponential,resolution);
				stockDatas.Add(stockData);
			}
			foreach (Security s in Securities.Values)
            {
            	s.FeeModel=new CustomFeeModel();
            }
        }

        public override void OnData(Slice data) 
        {
        	foreach (StockData stockData in stockDatas)
        	{
				stockData.Fitness=stockData.Rsi;
        	}

    	    var q1 = from x in stockDatas
    			orderby x.Fitness descending
    			select x;
        	
        	List<StockData> q2=q1.ToList();
        	if (q2.Count>0)		
        	{
        		StockData selectedStockData=q2.First();
        		if (selectedStockData.Ticker != stockHeld)
        		{
        			Liquidate(stockHeld);
        			SetHoldings(selectedStockData.Ticker, 1.0);
					stockHeld=selectedStockData.Ticker;
        		}
        	}
        }
        
        class StockData
        {
        	public string Ticker;
			public RelativeStrengthIndex Rsi;
			public decimal Fitness;
        }
        
        public class CustomFeeModel : IFeeModel
	    {
	        public decimal GetOrderFee(Security security, Order order)
	        {
	            var fee = order.AbsoluteQuantity*0.001m*security.Price;
	            return fee;
	        }
	    }
    }
}