I would like to be able to adjust the Profit Target and Stop Loss similar to entering an ATM order from the chart trader where you can drag the profit and stop on the chart.
I was able to accomplish this if I run a strategy on the primary chart by following the example from a previous post on exit methods and the ExitMethodsSample strategy (attached).
When I try to use the same exit method using MNQ as the secondary the position immediately closes after opening. Aside from referencing the secondary series the code is the same.
AddDataSeries(Data.BarsPeriodType.Tick, 1);
AddDataSeries("MNQ 03-21", Data.BarsPeriodType.Tick, 1, Data.MarketDataType.Last);
If (Entry Logic True)
EnterLong(2,Convert.ToInt32(Contracts), Convert.ToString(EntryNameTrevDtv));
PositionOpen = true;
**
Exit Logic
if (Positions[2].MarketPosition == MarketPosition.Long && PositionOpen == true)
{
ExitLongStopMarket(2, true, Position.Quantity, Position.AveragePrice - StopLoss * TickSize, "Stop Loss","");
ExitLongLimit(2, true, Position.Quantity, Position.AveragePrice + ProfitTarget * TickSize, "Profit Target", "");
PositionOpen = false;
}
However if I use SetProfitTarget and SetStopLoss the position does not close immediately and the target and stop appear on the MNQ (secondary) chart.
//SetProfitTarget(Convert.ToString(""), CalculationMode.Ticks, ProfitTarget);
//SetStopLoss(Convert.ToString(""), CalculationMode.Ticks, StopLoss, false);
Any help with this is appreciated.
Comment