In my strategy I am generating Stop loss & Profit Target after sending initial entry order. It works fine but in some cases SL/TP doesnt execute or executes late. Following are some of its instances
Late execution case:
------Long Signal Generated------
7/29/2013 11:03:12 AM
Close Price = 8357 | takeProfitValue = 8360 | stopLossValue = 8354 | takeProfitAmount = 75 | stopLossAmount = 75
Bar time = 09:13:00 | Close Price = 8354 | Market Position = 0 | High = 8352 | Low = 8332 | tick size = 1 | Big point value = 25
------Long Signal Generated------
7/29/2013 11:03:12 AM
Close Price = 8354 | takeProfitValue = 8357 | stopLossValue = 8351 | takeProfitAmount = 75 | stopLossAmount = 75
Bar time = 09:14:00 | Close Price = 8348 | Market Position = 0 | High = 8352 | Low = 8332 | tick size = 1 | Big point value = 25
...
Bar time = 09:23:00 | Close Price = 8337 | Market Position = 0 | High = 8352 | Low = 8332 | tick size = 1 | Big point value = 25
Bar time = 09:24:00 | Close Price = 8322 | Market Position = 0 | High = 8352 | Low = 8332 | tick size = 1 | Big point value = 25
Stop loss executes at 8322 but it should do at price 8348
No execution
------Short Signal Generated-----
7/29/2013 11:03:12 AM
Close Price = 8330 | takeProfitValue = 8327 | stopLossValue = 8333 | takeProfitAmount = 75 | stopLossAmount = 75
Bar time = 09:29:00 | Close Price = 8330 | Market Position = -1 | High = 8352 | Low = 8332 | tick size = 1 | Big point value = 25
Bar time = 09:30:00 | Close Price = 8324 | Market Position = -1 | High = 8352 | Low = 8332 | tick size = 1 | Big point value = 25
i have also attached portfolio report snapshot.
Here is the code:
Code: Select all
CurSpecOrdersMode = ESpecOrdersMode.PerPosition;
buy_order.Send(_tradeSize); //buy_order is a Market Buy order
double _takeProfitValue=CalculateTakeProfit(closePrice,_takeProfit,_tickSize,"Buy"); //CalculateTakeProfit calculates take profit price using close price and _takeProfit(pips)
double _stopLossValue=CalculateStopLoss(closePrice,_stopLoss,_tickSize,"Buy"); //CalculateStopLoss calculates stoploss price price using close price and _stopLoss(pips)
_takeProfitAmount=GetRiskAmount(closePrice,_takeProfitValue,_tradeSize,_pointValue); //GetRiskAmount calculates risk amount using takeProfitValue price
_stopLossAmount=GetRiskAmount(closePrice,_stopLossValue,_tradeSize,_pointValue); //GetRiskAmount calculates risk amount using stoplossValue price
GenerateProfitTarget(_takeProfitAmount);
GenerateStopLoss(_stopLossAmount);