I managed to get this strategy to work, following your recommendations. However, when it triggers a trade, I am getting an error. Here is the log and some screenshots of errors that happen when the limit order is first placed. Then when the limit order is filled, I get additional errors.
1. When I enter a long limit order, I want the stop placed at the low of the previous bar that triggered the trade. Hence the use of Low[1]
2. When I short, I want the stop placed at the high of the previous candle that triggered the trade. Use of High[1]
After the limit order is filled, this is what is shown
Below is the code I am using.
// Set 1
.....
{
EnterLongLimit(0, true, Convert.ToInt32(Quantity), Open[0], @"MyEntry");
}
if (Position.MarketPosition == MarketPosition.Long)
{
ExitLongStopLimit(0, true, Convert.ToInt32(Quantity), 0, Low[1], @"MyStop", @"MyEntry");
ExitLongLimit(0, true, Convert.ToInt32(Quantity), (High[0] + (TargetProfit * TickSize)) , @"TakeProfit", @"MyEntry");
}
// Set 2
....
{
EnterShortLimit(0, true, Convert.ToInt32(Quantity), Low[0], @"MyEntry");
}
if (Position.MarketPosition == MarketPosition.Short)
{
ExitShortStopLimit(Convert.ToInt32(Quantity), 0, High[1], @"MyStop", @"MyEntry");
ExitShortLimit(Convert.ToInt32(Quantity), (Low[0] + (TargetProfit * TickSize)) , @"TakeProfit", @"MyEntry");
}
}
Comment