I'm coding a strategy base on a single entry with (let's say) 3 lots with 3 exits based on objective levels (Position.AvgPrice + target1*TickSize), same for stop level.
All my positions are related to Position.Quantity, so let's say I'm long 3, I place an exit for 1 (target) and 3(stop), if I have 2 lots running (first has been executed) place 1 esit for 1 lot (target) and 2 (stop).....
Now I would like to understand how to manage OnExecution and OnOrderUpdate methods, better ...do I need to use methods for each position? or do I need to use just one at the beginning?
I'm a bit confusing, thanks for your suggestions,
Regrads
MB
Below a piece of code as example:
entry rules are defined within OnBarUpdate()
if (Position.MarketPosition == MarketPosition.Long){//Long position
if (Position.Quantity == ctr)
{
ExitLongLimit(ctr/3, (Position.AvgPrice + target1*TickSize), "1st Exit", "");
ExitLongStop(ctr, (Position.AvgPrice - stop*TickSize), "1stStop", "");
}
else if (Position.Quantity == (ctr/3)*2)
{
ExitLongLimit(ctr/3, (Position.AvgPrice + target2*TickSize), "2nd Exit", "");
ExitLongStop(Position.Quantity , (Position.AvgPrice - secondstop*TickSize), "2ndStop", "");
}
else if (Position.Quantity == (ctr/3))
ExitLongStop(Position.Quantity , (Position.AvgPrice + thirdstop*TickSize), "LastStop", "");
}else{
// Short
if (Position.Quantity == ctr)
{
ExitShortLimit(ctr/3, (Position.AvgPrice - target1*TickSize), "1st Exit", "");
ExitShortStop(Position.Quantity , (Position.AvgPrice + stop*TickSize), "1stStop", "");
}
else if (Position.Quantity == (ctr/3)*2)
{
ExitShortLimit(ctr/3, (Position.AvgPrice - target2*TickSize), "2nd Exit", "");
ExitShortStop(Position.Quantity , (Position.AvgPrice + secondstop*TickSize), "2ndStop", "");
}
else if (Position.Quantity == (ctr/3))
ExitShortStop(Position.Quantity , (Position.AvgPrice - thirdstop*TickSize), "LastStop", "");

Comment