Overall Statistics
namespace QuantConnect.Algorithm.CSharp
{
    public class VentralTransdimensionalChamber : QCAlgorithm
    {
    	/* 
    		Buying Ethereum with Bitcoin when bitcoin drops -20%
    		Selling Ethereum for Bitcoin when bitcoin rises +20%.
    		
    		At the same time:
    		
    		Buying Bitcoin with USD when bitcoin drops -20%
    		Selling Bitcoin for USD when bitcoin rise +20%.
    	*/
        
        // VARIABELEN DECLAREREN
        private string _ticker1 = "ETHBTC";            //virtueel paar - tracks the current USD value of 1 ether.
        private string _ticker2 = "BTCUSD";
        
        public string valuta1 = "BTC";
        public string valuta2 = "USD";
        
        private decimal _startingCash1 = 1.0m;
        private decimal _startingCash2 = 1000;
        
        private decimal _weight = .5m;             ///Percentage van portfolio dat je wilt investeren // % of portfolio for every trade.
 
        public decimal _targetPrice1;
        public decimal _targetPrice2;
        
        private decimal _targetPercent = .2m;        //x% winst dan verkopen // Sell when x% profit
        private decimal _btcDaling = -20;
        
        private decimal _stopPercent = .10m;
        
        public decimal _stopPrice1;					//verkopen bij de x% verlies / Sell when loss is x%
        public decimal _stopPrice2;
        
        public decimal _trailPercent = .03m;
        
        int _maxPosition = 900;                    // Max USD invested
        decimal _minPosition1 = .45m;                        // min USD needed to invest.
        decimal _minposition2 = 250;
        
        public decimal _btc;                            //Amount of USD in our Cashbook.
        public decimal _usd;


		MomentumPercent _momentumPercent;
  
        //PROGRAMMA VARIABELEN
        public  decimal _price1;
        public  decimal _price2;
        
        public decimal _holding1;            //Het aantal Ether we in onze portfolio hebben zitten.
        public decimal _holding2;
        
        public string _baseSymbol1;            //vertegenwoordigt de basesymbool dat we houden ETH
        public string _baseSymbol2; 


  
        
        //INITIALIZE BLOCK
        public override void Initialize()
        {
            SetStartDate(2017, 1, 1); 
            SetEndDate(2018, 1, 1);
            
            SetAccountCurrency(valuta1);
            SetAccountCurrency(valuta2);
            
            SetCash("BTC", _startingCash1); 
            SetCash("USD", _startingCash2); 
    
            SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
            
            var _crypto1 = AddCrypto("ETHBTC", Resolution.Minute);
            _baseSymbol1 = _crypto1.BaseCurrencySymbol;
            
            var _crypto2 = AddCrypto("BTCUSD", Resolution.Minute);
            _baseSymbol2 = _crypto2.BaseCurrencySymbol;

            
            SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
            
            
            int MomentumPercentPeriod = 1440;


            _momentumPercent = MOMP("BTCUSD", MomentumPercentPeriod, Resolution.Minute);
            SetWarmUp(MomentumPercentPeriod, Resolution.Minute);
        }
        
        

        // ON DATA BLOCK (waar bestanden/data binnenkomt in het programma)
        public override void OnData(Slice data)
        {
            if (!_momentumPercent.IsReady) return;

            _price1 = data[_ticker1].Price;
            _btc = Portfolio.CashBook["BTC"].Amount;   
            
            _price2 = data[_ticker2].Price;
            _usd = Portfolio.CashBook["USD"].Amount;  
               
               
            

            if (!Portfolio.Invested)
			{
            	if (_momentumPercent <= _btcDaling && _btc > _minPosition1)
            	{
            	SetHoldings(_ticker1, _weight);   // om een order te maken ==>percentage van portfolio dat je wilt investeren
            	
            	}
            	
            	if (_momentumPercent <= _btcDaling && _btc > _minposition2)
            	{
            		SetHoldings(_ticker2, _weight);	
            	}
            	
            	
			}
            


            if (Portfolio.Invested)
            {
                _holding1 = Portfolio.CashBook[_baseSymbol1].Amount;
                _holding2 = Portfolio.CashBook[_baseSymbol2].Amount;
                
                if(_price1 >= _targetPercent)
                {
                    Sell(_ticker1, _holding1);
                    Log($"prijs {_price1}");
                }
                /*
                if(_price2 >= _targetPercent)
                {
                    Sell(_ticker2, _holding2);
                    Log($"prijs {_price2}");
                }
				*/
                
            }
            
        }

    }
}
namespace QuantConnect.Algorithm.CSharp
{
}
/*
using QuantConnect.Securities.Crypto;
namespace QuantConnect.Algorithm.CSharp
{
    public class VentralTransdimensionalChamber : QCAlgorithm
    {
    	 
    	//	Trading bot that trades with the highest and lowest exchange rate of the last 24 hours.
    	//	Buying determined bacause the factor and the current price.
    	
      
    	private Dictionary<Symbol, SymbolData> _dataBySymbol;
        
        // VARIABELEN DECLAREREN
        private string _ticker = "ETHEUR";       //virtueel paar - tracks the current USD value of 1 ether.
        private int _startingCash = 2000;
        private decimal _weight = 1m;          ///Percentage van portfolio dat je wilt investeren // % of portfolio for every trade.
        
        private decimal _targetPercent = .01m;   //1% winst dan verkopen // Sell when 1% profit
        private decimal _stopPercent = .10m;     //verkopen bij de 10% verlies / Sell when loss is 10%
        
        int _maxPosition = 900;                  // Max USD invested
        int _minPosition = 750;                  // min USD needed to invest.

        //INITIALIZE BLOCK
        public override void Initialize()
        {
            SetStartDate(2017, 1, 3); 
            SetEndDate(2018, 1, 1);
            SetCash("EUR", _startingCash);
            SetBrokerageModel(BrokerageName.GDAX, AccountType.Cash);
    
    		_dataBySymbol = new Dictionary<Symbol, SymbolData>();
    		
            foreach (var ticker in new [] { "ETHEUR" })
            {
            	var crypto = AddCrypto(ticker, Resolution.Minute);
            	_dataBySymbol.Add(crypto.Symbol, new SymbolData(this, crypto));
            }
            
            SetWarmUp(SymbolData.MinutesOfTrading, Resolution.Minute);
        }

        // ON DATA BLOCK (waar bestanden/data binnenkomt in het programma)
        public override void OnData(Slice data)
        {
        	if (IsWarmingUp) return;
        	
        	foreach (var kvp in _dataBySymbol)
        	{
        		var symbolData = kvp.Value;
        		if (!symbolData.IsReady)
        		{
        			continue;
        		}

        		var symbol = kvp.Key;
        		if (!data.Bars.ContainsKey(symbol))
        		{
        			continue;
        		}

        		var price = data[symbol].Price;
        		var invested = Portfolio[symbol].Invested;

        		if (!invested &&
        		    symbolData.Factor >= 3)// &&
        		    //symbolData.LowestAverage > price)
        		{
        			var qnty = CalculateOrderQuantity(symbol, _weight);
        			SetHoldings(symbol, _weight);          // om een order te maken ==>percentage van portfolio dat je wilt investeren
					Debug($"Purchased Stock: {symbol}");   // Als het order gemaakt is word dit bevestigd door de debug
                    //Log($"prijs {price} en Max 24uur {symbolData.MaxExchange} en MIN 24uur symbolData.MinExchange}");

					symbolData.TargetPrice = price * (1 + _targetPercent);   //Bepalen welke verkoopprijs bij winst (huidige prijs + 1%) // determine wich selling price at profit
					symbolData.StopPrice = price * (1 - _stopPercent);       //bepalen welke verkoopprijs bij verlies (huidige - 2%)     // determine wich selling price at loss.
                }

                if (invested)
                {
                	if (price >= symbolData.TargetPrice)
                	{
                    	Sell(symbol, symbolData.Holding);
                    	//Log($"prijs {price}");
                	}

                	if (price < symbolData.StopPrice)
                	{
                    	Sell(symbol, symbolData.Holding);
                    	//Log($"prijs {price}");
                	}	
                }
        	}
        }
    }

    public class SymbolData
    {
    	private Cash _cash;
    	
		public static int MinutesOfTrading = 1140;

		public decimal StopPrice;
		public decimal TargetPrice;

		//Het aantal Ether we in onze portfolio hebben zitten.
		public decimal Holding => _cash.Amount;
		public Maximum MaxExchange { get; private set; }
		public Minimum MinExchange { get; private set; }

		public bool IsReady => MaxExchange.IsReady && MinExchange.IsReady;

		public decimal Factor => (((MaxExchange - MinExchange)/2)/MaxExchange)*100;

		public decimal LowestAverage => ((MaxExchange + MinExchange)/2 + MinExchange)/2;

	   	public SymbolData(QCAlgorithm algorithm, Crypto crypto)
    	{
    		_cash = algorithm.Portfolio.CashBook[crypto.BaseCurrencySymbol];
            MaxExchange = algorithm.MAX(crypto.Symbol, MinutesOfTrading, Resolution.Minute);
            MinExchange = algorithm.MIN(crypto.Symbol, MinutesOfTrading, Resolution.Minute);
    	}
    }
}
*/