I have got some issues with my profit targets in live trading. As soon as I change the account in my strategy from Sim101 to my real IB acc the strategy is sending wrong profit target orders.
Everything works fine in Sim101 acc though.
The Take Profit for a long position sent by strategy is below entry price and vice versa for a short position. I printed the values for tp and sl calculated as you can see in my code below and the values are correct.
Something strange must happen in SetProfitTarget(CalculationMode.Price,tp) because the value for tp is correct.
This is an example for a misstrade i got today. These are the printed values:
Market Position
Short
Average Position Price
4050,75
execution Price
4050,75
execution avg order Price
4050,75
TP
4038,5
SL
4058
But the TP Limit Order the strategy sent had a limit price of 4057.25.
protected override void OnExecution(IExecution execution) { if (Position.MarketPosition != MarketPosition.Flat) { if (execution.Order.Name.Contains("Trend")) { double sl = (Position.MarketPosition == MarketPosition.Long) ? customRound(Position.AvgPrice - _targetRangeTrend * _slPercTrend) : customRound(Position.AvgPrice + _targetRangeTrend * _slPercTrend); double tp = (Position.MarketPosition == MarketPosition.Long) ? customRound(Position.AvgPrice + _targetRangeTrend * _tpPercTrend) : customRound(Position.AvgPrice - _targetRangeTrend * _tpPercTrend); SetProfitTarget(CalculationMode.Price, tp); SetStopLoss(CalculationMode.Price, sl); Print("Market Position"); Print(Position.MarketPosition.ToString()); Print("Average Position Price"); Print(Position.AvgPrice); Print("execution Price"); Print(execution.Price); Print("execution avg order Price"); Print(execution.Order.AvgFillPrice); Print("TP"); Print(tp); Print("SL"); Print(sl); } } }
Thanks in advance!
Comment