I discovered the cause of my frustrations, and it was my reliance on boilerplate code without thinking through the consequences. I was running two simple models, so they were easy to combine into one combo model that I thought should be the same as a MetaModel of the two. Both models, however, used this common construct in the Execute() method:
if (!HasOpenPosition(bars, PositionType.Long))
{
//logic here to take a long position
}
else
{
//use the selling logic here
}
Trouble is, there are now two of these code constructs (one for each component model), and our Execute function runs through bars symbol by symbol. So if Model 1 is long, it may have its position sold by either Model 1 (expected behavior) or by Model 2 (unexpected, and often premature).
The solution is simple enough, just set transaction tags that differ between the models in the Buy transaction, then test for them instead of simply for any long position:
//if (!HasOpenPosition(bars, PositionType.Long))
Position foundPosition = FindOpenPosition(2);
if ( foundPosition == null) // no long positions open
{
//logic here to take a long position AND SET TAG = 2 FOR THIS MODEL
}
Now my combined model is very close to the MetaModel. Still not exactly the same results, but very very close, so I'm moving forward. Copy, paste, fail... anybody know the Latin for this to put on my personal coat of arms? Google says "Exemplum, crustulum, deficient." About right for a Bitfool.
I discovered the cause of my frustrations, and it was my reliance on boilerplate code without thinking through the consequences. I was running two simple models, so they were easy to combine into one combo model that I thought should be the same as a MetaModel of the two. Both models, however, used this common construct in the Execute() method:
[CODE]
if (!HasOpenPosition(bars, PositionType.Long))
{
//logic here to take a long position
}
else
{
//use the selling logic here
}
[/CODE]
Trouble is, there are now two of these code constructs (one for each component model), and our Execute function runs through bars symbol by symbol. So if Model 1 is long, it may have its position sold by either Model 1 (expected behavior) or by Model 2 (unexpected, and often premature).
The solution is simple enough, just set transaction tags that differ between the models in the Buy transaction, then test for them instead of simply for any long position:
[CODE]
//if (!HasOpenPosition(bars, PositionType.Long))
Position foundPosition = FindOpenPosition(2);
if ( foundPosition == null) // no long positions open
{
//logic here to take a long position AND SET TAG = 2 FOR THIS MODEL
}
[/CODE]
Now my combined model is very close to the MetaModel. Still not exactly the same results, but very very close, so I'm moving forward. Copy, paste, fail... anybody know the Latin for this to put on my personal coat of arms? Google says "Exemplum, crustulum, deficient." About right for a Bitfool.