i don't understand how to write simple multi instrument strategies which do the following things:
- add some (e.g. 3) instruments to the strategy
- on OnBarUpdate, evaluate all 3 instruments
- based on the evaluation, place an order for one of the three instruments.
I tried two different approaches:
1)
protected override void Initialize()
{
// Add 3 instruments
Add("AAA", PeriodType.Day, 1);
Add("BBB", PeriodType.Day, 1);
Add("CCC", PeriodType.Day, 1);
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
{ // No call for PRIMARY instrument
return;
}
// Do some fancy calculation based on Closes[0 ... 3][0], RSI(BarsArray[0 ... 3], ....), ...
// Place an order, e.g. for instrument 2:
EnterLong(2, NewLongAmount, "Some text");
}
protected override void Initialize()
{
// Add 3 instruments
Add("AAA", PeriodType.Day, 1);
Add("BBB", PeriodType.Day, 1);
Add("CCC", PeriodType.Day, 1);
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 3)
{ // No call for LAST instrument
return;
}
// Do some fancy calculation based on Closes[0 ... 3][0], RSI(BarsArray[0 ... 3], ....), ...
// Place an order, e.g. for instrument 2:
EnterLong(2, NewLongAmount, "Some text");
}
For 2), Closes[2][0] has the right value but orders placed for instruments 1 - 2 are executed with one day delay -> one day to late!
What am i missing? How can i solve this?
Regards, Robin


Comment