I'm having some issue with using the below for getting the unrealized profit/loss. I'm using the below code, but for some reason, it decides not to obey the target all the time. It will work correctly for a number of trades, then just decide to go for something like 10x my target. Not sure what I'm doing or if there are some ideas of what I can look at.
if (Position.MarketPosition == MarketPosition.Long && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Percent, Close[0])) >= PercentGain/100)
{
ExitLong("Exit Profit Target", "Long Position");
Draw.ArrowDown(this, "Exit Long Profit Target" + CurrentBar, false, 0, High[0] - 4*TickSize, Brushes.Red);
Print("EXIT LONG PROFIT TARGET " + " " + Time[0].Date);
Print(Position.GetUnrealizedProfitLoss(Performance Unit.Percent, Close[0]) + " Unrealized Profit " + Time[0].Date);
}
I have all my entries using Position.MarketPosition == MarketPosition.Flat as a requirement before entry. I'm also using SetProfitTarget("Long Position", CalculationMode.Percent, PercentGain/100, true) as a check on this, but I have them set conditionally using a bool to where only one or the other can be utilized during the strategy. And I have a Stop Loss enabled using SetStopLoss.
Any help or recommendations would be appreciated.
Thanks,
Ray

Comment