//Universe Code
AddUniverse(coarse =>
{
return (from cf in coarse
// grab th SelectionData instance for this symbol
let avg = _averages.GetOrAdd(cf.Symbol, sym => new SelectionData(fast, intermediate, slow))
// Update returns true when the indicators are ready, so don't accept until they are
where avg.Update(cf.EndTime, cf.AdjustedPrice)
// only pick symbols who have their fast ema over their intermediateema
where avg.Fast > avg.Intermediate*(1 + Tolerance)
//only pick symbolaa who have their intermediate ema over their slow ema
where avg.Intermediate > avg.Slow*(1 + Tolerance)
// prefer symbols with a larger delta by percentage between the two averages
where cf.Price > 10
where cf.Volume > 1000*1000
orderby avg.ScaledDelta descending
// we only need to return the symbol and return 'Count' symbols
select cf.Symbol).Take(Count);
});
//Selection Data
public class SelectionData
{
public readonly ExponentialMovingAverage Fast;
public readonly ExponentialMovingAverage Intermediate;
public SelectionData(int fast, int intermediate)
{
Fast = new ExponentialMovingAverage(fast);
Intermediate = new ExponentialMovingAverage(intermediate);
}
// computes an object score of how much large the fast is than the slow
public decimal ScaledDelta
{
get { return (Fast - Intermediate)/((Fast + Intermediate)/2m); }
}
public bool Update(DateTime time, decimal value)
{
return Fast.Update(time, value) && Intermediate.Update(time, value); // && Slow.Update(time, value);
}
}
}
Trying to create a Universe with EMA, Volume, and Price restrictions as above, but no data is being pumped to OnData.
Link Liang
Hi Saurabh,With only snippets, I could not testify if it works for your algorithm. But here is my suggestion: use coarse selection model.
// in Initialize() SetUniverseSelection(new CoarseFundamentalUniverseSelectionModel(CoarseSelectionFunction)); // later in algorithm public static IEnumerable<Symbol> CoarseSelectionFunction(IEnumerable<CoarseFundamental> coarse){ return (from cf in coarse // grab th SelectionData instance for this symbol let avg = _averages.GetOrAdd(cf.Symbol, sym => new SelectionData(fast, intermediate, slow)) // Update returns true when the indicators are ready, so don't accept until they are where avg.Update(cf.EndTime, cf.AdjustedPrice) // only pick symbols who have their fast ema over their intermediateema where avg.Fast > avg.Intermediate*(1 + Tolerance) //only pick symbolaa who have their intermediate ema over their slow ema where avg.Intermediate > avg.Slow*(1 + Tolerance) // prefer symbols with a larger delta by percentage between the two averages where cf.Price > 10 where cf.Volume > 1000*1000 orderby avg.ScaledDelta descending // we only need to return the symbol and return 'Count' symbols select cf.Symbol).Take(Count); }
Feel free to share your algorithm and discuss further issues in the forum or in our slack channel. Hope it helps!
Saurabh Maheshwari
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!