Basically looking to expand on the boot camp using the output of a consolidator to detect an open range breakout for multiple stocks instead of just one, but it doesn't seem to ever invest
// I have these objects, the Dictionary is used to hold the consolidated tradebar
private Dictionary<string, TradeBar> MyStocks = new Dictionary<string, TradeBar>();
private string[] _stocks = new string[] { "TSLA", "AMD", "BAC", "SYMC", "HP" };
//then in Initialize() I add the equities with 1 minute resolution, and add it to my dictionary as well
//as set the consolidation
for(int i = 0; i < _stocks.Length; i++)
{
AddEquity(_stocks[i], Resolution.Minute);
MyStocks.Add(_stocks[i], null);
Consolidate(_stocks[i], TimeSpan.FromMinutes(30), OnDataConsolidation);
}
//With my OnDataConsolidation method being as follows -
private void OnDataConsolidation(TradeBar bar)
{
if(bar.Time.Hour == 9 && bar.Time.Minute == 30)
{
MyStocks[bar.Symbol] = bar;
}
}
//And my OnData function looking as follows to check each equity of the proper parameters
public override void OnData(Slice data)
{
for(int i = 0; i < _stocks.Length; i++)
{
if(!Portfolio[_stocks[i]].Invested && MyStocks[_stocks[i]] != null)
{
if(data[_stocks[i]].Close > MyStocks[_stocks[i]].High)
{
SetHoldings(_stocks[i], 1/_stocks.Length);
}
if(data[_stocks[i]].Close < MyStocks[_stocks[i]].Low)
{
SetHoldings(_stocks[i], -1/_stocks.Length);
}
}
}
}