| 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 |
using System.Collections.Concurrent;
using System;
namespace QuantConnect
{
public class EmaCrossUniverseSelectionAlgorithm : QCAlgorithm
{
// tolerance to prevent bouncing
const decimal Tolerance = 0.01m;
public int a =0;
private const int Count = 16000;
public string[] symbolArray = new string[5000];
private string symbol;
const decimal OneBillion = 500m*1000m*1000m;
// use Buffer+Count to leave a little in cash
private const decimal TargetPercent = 0.1m;
private SecurityChanges _changes = SecurityChanges.None;
// holds our coarse fundamental indicators by symbol
private readonly ConcurrentDictionary<Symbol, SelectionData> _averages = new ConcurrentDictionary<Symbol, SelectionData>();
// class used to improve readability of the coarse selection function
private class SelectionData
{
public readonly SimpleMovingAverage sma_120;
public readonly SimpleMovingAverage sma_100;
public readonly SimpleMovingAverage sma_80;
public readonly SimpleMovingAverage sma_60;
public readonly SimpleMovingAverage sma_40;
public readonly SimpleMovingAverage sma_20;
public SelectionData()
{
sma_120 = new SimpleMovingAverage(120);
sma_100 = new SimpleMovingAverage(100);
sma_80 = new SimpleMovingAverage(80);
sma_60 = new SimpleMovingAverage(60);
sma_40 = new SimpleMovingAverage(40);
sma_20 = new SimpleMovingAverage(20);
}
// computes an object score of how much large the fast is than the slow
public decimal ScaledDelta
{
get { return (sma_60 - sma_120)/((sma_60 + sma_120)/2m); }
}
// updates the EMA50 and EMA100 indicators, returning true when they're both ready
public bool Update(DateTime time, decimal value)
{
// return sma_100.Update(time, value) && sma_120.Update(time, value);
return sma_20.Update(time, value) && sma_40.Update(time, value) && sma_60.Update(time, value)&& sma_80.Update(time, value)&& sma_100.Update(time, value)&& sma_120.Update(time, value);
}
}
public override void Initialize()
{
UniverseSettings.Leverage = 2.0m;
UniverseSettings.Resolution = Resolution.Daily;
SetStartDate(2015,12,1);
SetEndDate(DateTime.Now.Date.AddDays(-1));
SetCash(100*1000);
AddUniverse(coarse =>
{
return (from cf in coarse
// where cf.DollarVolume > OneBillion
let avg = _averages.GetOrAdd(cf.Symbol, sym => new SelectionData())
where avg.Update(cf.EndTime, cf.Price)
where avg.sma_20 > avg.sma_40 && avg.sma_40 > avg.sma_60//&& avg.sma_80 > avg.sma_100 && avg.sma_100 > avg.sma_120
//select cf.Symbol).Take(Count);
select cf.Symbol);
});
}
public void OnData(TradeBars data)
{
a=0;
foreach (var security in _changes.AddedSecurities)
{
DateTime dateTest = data.Time;
a++;
symbolArray[a] = security.Symbol;//security.Symbol;
//Log(symbolArray[a]);
}
Log("Number:"+a);
}
public override void OnSecuritiesChanged(SecurityChanges changes)
{
_changes = changes;
}
}
}