- ago
In the case of multiple entries, how can I ensure that when an exit signal occurs, all positions are closed simultaneously? When I use the following code, it only closes the initial entry position and does not close the additional positions.

CODE:
if (LastOpenPosition?.PositionType == PositionType.Short)             {                if ((index - 1 >= 0 && bars.Close[index] < BBlower[index - 1])                           && bars.Close[index] < bars.Open[index]                                {                   Backtester.CancelationCode = 3;                   _transaction = PlaceTrade(bars, TransactionType.Short, OrderType.Market, 0, 1, "ShortAdd");                   count++;                }                else                {                   if (count > 1)                   {                      Backtester.CancelationCode = 4;                      stops[index] = foundPosition1.TrailingStopPrice;                      CloseAtTrailingStop(foundPosition1, TrailingStopType.ATR, Parameters[2].AsDouble, "Cover at Trailing Stop");                   }                   else                   {                      stops[index] = Math.Min(BBupper[index], stops[index - 1]);                      Backtester.CancelationCode = 4;                      _transaction = PlaceTrade(bars, TransactionType.Cover, OrderType.Stop, stops[index], 0, "Cover");
0
210
Solved
1 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.98% )
- ago
#1
1. Open a new Block Strategy
2. Click Multiple Positions
3. Click Open as C# Code Strategy
This will show you how to do it.
0
Best Answer

Reply

Bookmark

Sort