I have the current setup:
- Open simultaneously 3 positions (S1, S2, S3), based on a channel ("Box").
- If price goes against me and crosses the middle of the box, I close one position at the time. If it happens three times, all positions are closed.
Initially, I used a "counter", set at 0 when no trades are closed, then 1 if S1 is closed, 2 if S2 is closed but it doesnt work with an object based code.
I am now using the BarsSinceExit but I am still failing.
Please find below the code extract and also attached a screenshot that shows that S1 and S2 are closed simultaneously and not one after the other.
// Partial close of short position S1 & then S2
if ((Close[1] < midboxSize) && (Close[0] >= midboxSize) &&
(Position.MarketPosition == MarketPosition.Short)) // && (tradeShClosingCounter == 0))
{
ExitShort("S1");
//tradeShClosingCounter = tradeShClosingCounter + 1;
}
if ((Close[1] < midboxSize) && (Close[0] >= midboxSize) && (BarsSinceExit(0,"S1",0) > 2) &&
(Position.MarketPosition == MarketPosition.Short)) // && (tradeShClosingCounter == 1))
{
ExitShort("S2");
//tradeShClosingCounter = tradeShClosingCounter + 1;
}
Thank you,
Best
Nicolas
Comment