使用 C#。我没有收到任何编译错误,但它似乎没有按计划工作。我如何在下面设置这个结构列表<>有什么不正确的地方吗?
public struct StockEntry
{
public string Name { get; set; }
public PeriodType Period { get; set; }
public int Value { get; set; }
public int Count { get; set; }
}
List<StockEntry> _stocks = new List<StockEntry>();
protected override void Initialize()
{
//5min price bars
_stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACN", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ADT", Period = PeriodType.Minute, Value = 5, Count = 0 } );
_stocks.Add(new StockEntry { Name = "SCTY", Period = PeriodType.Minute, Value = 5, Count = 0 } );
//1min price bars
_stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACE", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ACN", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "ADT", Period = PeriodType.Minute, Value = 1, Count = 0 } );
_stocks.Add(new StockEntry { Name = "SCTY", Period = PeriodType.Minute, Value = 1, Count = 0 } );
}
**下面添加的部分* *
任何有 Count 的地方都是关键区域,我不确定它是否真的在计算我试图完成的交易数量。
protected override void OnBarUpdate()
{
// for loop to iterate each stock through the required
// entry conditions. "series" is just a 5min price bar
// of each instrument, "series + 5" is 1min of each
// instrument. Hoping the first stock I added above
// takes Index 1, then the next stock added takes Index 2 and so on.
for (int series = 0; series < 5; series++)
{
if (BarsInProgress == series + 5) //OnBarUpdate called for 1min bars
{
var stockEntry = _stocks[series];
bool enterTrade = false;
if (stockEntry.Count < 1)//if 0 entries
{
enterTrade = true;
}
else // if 1 or more entries make sure 2 price bars or 10min has elapsed before entering another trade
{
enterTrade = BarsSinceEntry(series, "", 0) > 2;
}
if (enterTrade)
{
// Condition for Long Entry, fast MA cross above slow MA & current price > high of bar at cross
if (SMA(BarsArray[series],Fast)[1] > SMA(BarsArray[series],Slow)[1] &&
SMA(BarsArray[series],Fast)[2] < SMA(BarsArray[series],Slow)[2] &&
Closes[series + 5][0] > Highs[series][1] + distance &&
SMA(BarsArray[series],Slow)[1] > SMA(BarsArray[series],Slow)[2] + .01)
{
EnterLong(200); //enter long 200 shares
// store/track that a trade for the current stock has
// taken place so that it can process through the condition
// above that requests how many trades have already taken place.
stockEntry.Count++; }
}
}
}
}