I have calculated my profit target:
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + (Instrument.MasterInstrument.Round2TickSize(10 * (ATR(14)[0]))), "LE Target", "LE Mmamo2");
Please note I have used a value of ATR on the bar of entry to calculate a number of ticks to set my target at. (This is coded under 'OnExecution').
Question is ...... how do I reference this value (# of ticks from formula 10 * (ATR(14)[0]) for use in other calculations in 'OnBarUpdate'.
For example if I wished to code a proximity exit along the lines of 'If Close[2] is > 90% of my target and the most recent closes were down .... exit.
If I use 'targetOrder' .... eg (0.9 * targetOrder) ... I get error messages about using operands etc.
So far I have:
OnBarUpdate
{ //Proximity exit here. If unrealized PnL > 90% of target in the last 3 bars but price retracing, exit
if (Position.MarketPosition == MarketPosition.Long && Close[0] < Close[1] && Close[1] < Close[2] && Close[2] > (0.9 * (Instrument.MasterInstrument.Round2TickSize(15 * (ATR(5)[0]))))
if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice)
{
ExitLong(stopOrder.Quantity, "Prox-Stop", "LE Mmamo2");
}
}
Obvious problem here is I am now using a different value for ATR and as I don't know how many bars will have passed since entry I cant reference the entry bar !!!
Any suggestions please.
Ben.
Have missed Position avg price in formula above sorry. Should read:
........ && Close[2] > 0.9 * (Position.AvgPrice + (Instrument.MasterInstrument.Round2TickSize(15 * (ATR(5)[0])))))

Comment