In the screenshot you can see an order for 4 contracts with a TP and SL. However, instead of being 4 as it should be. The TP and SL are for only a quantity of just 1. The order trace also shows a quantity of 4 submitted. I went through the trade again and again and each time it does the same thing in market replay. Every other trade goes through fine.
TRIGGER Long - Limit Order Submitted 11/06/2024 17:21:34
11/06/2024 17:21:35 Strategy 'MS/3277': Entered internal SubmitOrderManaged() method at 11/06/2024 17:21:35: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=4 LimitPrice=5359.00 StopPrice=0 SignalName='myLong' FromEntrySignal=''
MyStop = 5357.5 & MyProfit = 5360
11/06/2024 17:21:35 Strategy 'MS/3277': Entered internal SubmitOrderManaged() method at 11/06/2024 17:21:35: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=4 LimitPrice=0 StopPrice=5357.50 SignalName='' FromEntrySignal='myLong'
11/06/2024 17:21:35 Strategy 'MS/3277': Entered internal SubmitOrderManaged() method at 11/06/2024 17:21:35: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=4 LimitPrice=5360.00 StopPrice=0 SignalName='' FromEntrySignal='myLong'
So when the SL/TP is hit, it leaves my original on running with a position of 3.
In the log in control panel I have lots of entries at the same exact time. After the original order was Submitted > Accepted > Working....the next entry shows 'Partially filled'. Then after this the sell orders go through show here a quantity of 1. Then after this the original order finishes executing leaving me a position of 4L.
In my code SL/TP orders are submitted with the same signal name as the original order. I would have thought they would update to reflect the size of the position?
The exit orders are submitted after the original order and also after the SL/TP values have been stored in a variable. These orders would be resubmitted every bar to stop it expiring.
// Set 5
if ((TriggerState == 2)
&& (Position.MarketPosition == MarketPosition.Long)
&& (MyBar != CurrentBars[0]))
{
ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), MyStop, "", @"myLong");
ExitLongLimit(Convert.ToInt32(DefaultQuantity), MyProfit, "", @"myLong");
MyBar = Convert.ToInt32(CurrentBars[0]);
}
What do I have to do to have this not happen again? and make sure the exit orders always match the position ? I'm using strategy builder but have just started to unlock code.

Comment