I have a strategy that calculates some metrics on each bar and decides to enter a short or a long trade with two contracts. I want to implement a feature that allows me to enter a trade on the metrics calculated on two bars ago. In other words, if on bar number 100 I have a signal, on bar number 101 I submit an order, if the order does not get filled I want to submit an order on bar number 102. However, I am facing an issue based on the way that I submit my orders.
1. Enter two separate orders with different names so I can control where my take profit is using the "SetProfitTarget" method. I use the following code for this purpose:
EnterLongLimit(1, limitPrice, orderName); SetStopLoss(orderName, CalculationMode.Ticks, StopLossTickSize, true); SetProfitTarget(orderName, CalculationMode.Ticks, TakeProfitTickSize); EnterLongLimit(1, limitPrice, orderName +" 2"); SetStopLoss(orderName +" 2", CalculationMode.Ticks, StopLossTickSize, true); SetProfitTarget(orderName +" 2", CalculationMode.Ticks, TakeProfitTickSize + 5);
2. Enter one trade with two contracts and set the take profit with "ExitShortStopMarket" method. I use the following code for this purpose:
EnterLongLimit(2, limitPrice, orderName); SetStopLoss(orderName, CalculationMode.Ticks, StopLossTickSize, true); double tp1 = limitPrice + 5 * TickSize; double tp2 = limitPrice + 10 * TickSize; ExitLongStopMarket(1, tp1, " tp1", orderName); ExitLongStopMarket(1, tp2, " tp2", orderName);
So my questions are:
- Why aren't the orders submitted on the second bar when they are not filled on the first bar when I enter two separate positions?
- How can I enter a position with multiple contracts but exit them with different take profits?
Regards,
Pouya
Comment