The average entry price of the open position, or na when the strategy is flat.
strategy.position_avg_price is a series float. With several entries open it is the size-weighted average of their fill prices, so adding to a position moves it. Slippage is part of each fill price; commission is not.
Type
series float
Remarks
- It is na while there is no position, so use nz() or a check on
strategy.position_sizebefore doing arithmetic with it. - Use it to build a stop or target relative to the actual fill, as in
strategy.exit("x", stop =strategy.position_avg_price* 0.98).
Example
//@version=6
strategy("Average price stop", overlay = true, pyramiding = 3)
if ta.crossover(close, ta.sma(close, 20))
strategy.entry("Layer", strategy.long)
stopLevel = strategy.position_avg_price * 0.98
strategy.exit("Stop", "Layer", stop = stopLevel)
plot(strategy.position_avg_price, "Average price", color.orange, style = plot.style_linebr)
plot(stopLevel, "Stop", color.red, style = plot.style_linebr)See also
Runs on Sidechair