Basic example:
I have a strategy that:
- takes any 2 stocks, A and B.
- at 9 AM, longs A buying 10 shares, goes long on B buying 20 shares
- at 4 PM, exits both positions.
Can you point me in the right direction in terms of specifying 2 instruments? I see EnterLong() but I don't see a way to specify an instrument for the EnterLong function:
How can I specify multiple instruments for a strategy and then refer to them for entry and exit?
Here is some pseudocode. (Untested, just to demonstrate what I want to do.)
protected override void OnBarUpdate()
{
if ((ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 100000)) {
if (!this.hasEnteredA) {
EnterLong("SPECIFY SECURITY A at 10 shares?");
this.hasEnteredA = true;
}
if (!this.hasEnteredB) {
EnterLong("SPECIFY SECURITY B at 20 shares?");
this.hasEnteredB = true;
}
} else if (ToTime(Time[0]) >= 140000 && ToTime(Time[0]) < 143000))
{
if (this.hasEnteredA) {
ExitLong("SPECIFY A?");
this.hasEnteredA = false;
}
if (this.hasEnteredB) {
ExitLong("SPECIFY B?");
this.hasEnteredB = false;
}
}
}

Comment