The goal is to store and plot the max price value since the last buy / sell.
The following method compares the current high with the historical high in the past candles since the last long / short. If current high is larger, it will become the historical high.
Somehow the plot does computes, but it doesn’t seem to be correct or as expected. Any advices?
//@version=4
strategy(title="Max since last buy/sell", overlay=true, process_orders_on_close=true)
// —————————— STATES
hasOpenTrade = strategy.opentrades != 0
notHasOpenTrade = strategy.opentrades == 0
isLong = strategy.position_size > 0
isShort = strategy.position_size < 0
// —————————— VARIABLES
var entryPrice = close
// —————————— MAIN
maxSinceLastBuySell = hasOpenTrade ? high > highest(bar_index) ? high : highest(bar_index) : na
// —————————— EXECUTIONS
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
entryPrice := close
candle := 1
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
entryPrice := close
candle := 1
strategy.entry("My Short Entry Id", strategy.short)
// —————————— DEBUG
plot(entryPrice, color = color.green)
plot(candle, color = color.black)
plot(maxSinceLastBuySell, color = color.red)
