namespace QuantConnect.Algorithm.CSharp
{
public class DynamicVerticalRegulators : QCAlgorithm
{
public override void Initialize()
{
SetStartDate(2020, 6, 1); //Set Start Date
SetCash(100000); //Set Strategy Cash
SetExecution(new ImmediateExecutionModel());
SetPortfolioConstruction(new EqualWeightingPortfolioConstructionModel());
UniverseSettings.Resolution = Resolution.Minute;
var symbols = new[] { QuantConnect.Symbol.Create("SPY", SecurityType.Equity, Market.USA), QuantConnect.Symbol.Create("GLD", SecurityType.Equity, Market.USA),
QuantConnect.Symbol.Create("TLT", SecurityType.Equity, Market.USA)};
SetUniverseSelection( new ManualUniverseSelectionModel(symbols) );
SetAlpha(new MyAlpha());
}
}
public class MyAlpha : AlphaModel
{
public override IEnumerable<Insight> Update(QCAlgorithm algorithm, Slice data){
var insights = new List<Insight>();
var now = algorithm.Time;
foreach(var symbol in data.Keys)
{
if (!algorithm.Portfolio[symbol].Invested)
{
// close insight today at 3:59 PM
var nextClose = algorithm.Securities[symbol].Exchange.Hours.GetNextMarketClose(algorithm.Time, false).AddMinutes(-2);
if(now < nextClose){
var insight = Insight.Price(symbol, nextClose, InsightDirection.Up);
insights.Add(insight);
}
}
}
return insights;
}
}
}