Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
namespace QuantConnect 
{   
   
    public class BasicTemplateAlgorithm : QCAlgorithm
    {
    
    	// we'll hold some computed data in these guys
        List<SymbolData> _symbolData = new List<SymbolData>();
    	
		//private mySlope Slope45;
	   	public readonly IReadOnlyList<string> EquitySymbols = new List<string>
        {
            "AAPL", "SPY", "SLB", "IBM"
        };
    	
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize() 
        {
			
            SetStartDate(2018, 01 ,01);
            SetEndDate(2018, 5, 17);
            
            foreach (var symbol in EquitySymbols)
            {
               AddSecurity(SecurityType.Equity, symbol, Resolution.Daily);
               Securities[symbol].SetDataNormalizationMode(DataNormalizationMode.Raw); 
               // Slope45 = new mySlope(45);
               
               var oneMonthPerformance = MOM(symbol,30,Resolution.Daily);
               var threeMonthPerformance = MOM(symbol,90,Resolution.Daily);
               var macd = MACD(symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Daily);
               var Slope45 = new mySlope(10); 
               RegisterIndicator(symbol, Slope45, Resolution.Daily, Field.Close);
                
               
                 _symbolData.Add(new SymbolData
                {
                    Symbol = symbol,
                    OneMonthPerformance = oneMonthPerformance,
                    ThreeMonthPerformance = threeMonthPerformance,
                    Macd = macd,
                    myslope = Slope45
                });
            }
        }

        
        public void OnData(TradeBars data) 
        {
        	
			Debug("=======");
			
            foreach (var sym in _symbolData)
            {
               
               Debug (String.Format("1Buy {0} - OHLC[{1:0.00}, {2:0.00}, {3:0.00}, {4:0.00}, {5:0}] 1mo: {6:0.00} 3mo: {7:0.00} macd: {8:0.00} slp: {9:0.000} ", 
               	sym.Symbol,
               	data[sym.Symbol].Open,data[sym.Symbol].High,data[sym.Symbol].Low,data[sym.Symbol].Close,data[sym.Symbol].Volume,
        		sym.OneMonthPerformance,
        		sym.ThreeMonthPerformance,
        		sym.Macd,
        		sym.myslope));
            }
			
	  }
	}
	
	 class SymbolData
    {
        public string Symbol;

        public Momentum OneMonthPerformance { get; set; }
        public Momentum ThreeMonthPerformance { get; set; }
        public MovingAverageConvergenceDivergence Macd { get; set; }
        public mySlope myslope {get; set;}
        
        public decimal ObjectiveScore
        {
            get
            {
                // we weight the one month performance higher
                decimal weight1 = 100;
                decimal weight2 = 75;

                return (weight1 * OneMonthPerformance + weight2 * ThreeMonthPerformance) / (weight1 + weight2);
            }
        }
    } //SymbolData
	
	
	
} //namespace
using MathNet.Numerics;

namespace QuantConnect
{
	public class mySlope : WindowIndicator<IndicatorDataPoint>
    {
    	
    	private int _days;
    	private int _dayCounter;
    	
    	private List<double> _xValues;
    	private List<double> _yValues;
    	
        public mySlope(int period)
            : base("Slope1" + period, period)
        {
        	
        	//_days = period - 1;
        	_days = period;
        	_dayCounter = 0;
        	_xValues = new List<double>();
        	_yValues = new List<double>();
        }

        /*public mySlope(string name, int period)
            : base(name, period)
        {
        	
        }
	*/
        protected override decimal ComputeNextValue(IReadOnlyWindow<IndicatorDataPoint> window, IndicatorDataPoint input)
        {
            //if (window.Count < 3) return 0m;

            var xVals = new double[window.Count];
            var yVals = new double[window.Count];

            for (int i = 0; i < window.Count; i++)
            {
                xVals[i] = i;
                yVals[i] = (double) input.Value;
            }
            
            _xValues.Add(_dayCounter);
            _yValues.Add((double)input.Value);
 			_dayCounter = _yValues.Count() - 1;
 			//_dayCounter = _yValues.Count();
			//Console.WriteLine("[yCount]: " + _yValues.Count() + " [xCount]: " + _xValues.Count());
			
			if (_dayCounter < _days)
			{
				return 0;
			}
			else
			{
				var x1 = _xValues[_dayCounter-_days];
				var x2 = _xValues[_dayCounter];
				var y1 = _yValues[_dayCounter-_days];
				var y2 = _yValues[_dayCounter];
				decimal slope = (decimal)(y2 - y1) / (decimal)(x2 - x1);
				
				//Console.WriteLine("x1: " + x1 + ", y1: " + y1); 
				//Console.WriteLine("x2: " + x2 + ", y2: " + y2 + " slope: ", slope);
				
				//Console.WriteLine (String.Format(" x1: {0} y1 {1:0.000} x2 {2:0} y2 {3:0.000} Slope {4:0.000} ",
        		//									x1,y1,x2,y2,slope));
				return slope;
			}
        }
    }
}