使用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 });
}
** *下方*
部分加入任何地方它計數是我不確定它是否真的在計算我正試圖完成的交易量。
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++; }
}
}
}
}
什麼不按計劃工作? – dbarnes
顯然是局部變量。該方法返回後,不再列表。 –