【发布时间】:2019-12-19 07:49:39
【问题描述】:
目标是存储和绘制自上次买入/卖出以来的最大价格值。
以下方法将当前高点与自上次多头/空头以来过去蜡烛的历史高点进行比较。如果当前高点较大,它将成为历史高点。
情节确实计算了,但它似乎不正确或不符合预期。有什么建议吗?
//@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)
【问题讨论】:
标签: pine-script