我试图写百分比追踪止损。该代码设计为自输入以来,在先前的柱线数量上表现出最高的高位。
longStopPrice = 0.0,shortStopPrice = 0.0,lengthinmp = 0,highesthigh = 0.0,stopValue = 0.0
longStopPrice:=如果(strategy.position_size> 0)
lengthinmp:= barsince(strategy.position_size == 0)
maximumhigh =最高(high,barssince(strategy.position_size == 0))//在此行的早期版本中使用过lengthinmp
stopValue =最高高*(1-StopPerc)
// max(stopValue,longStopPrice [1])
其他
0
我得到的错误是 第49行:无法使用参数(系列[float],系列[integer])调用“最高”;可用的重载:highest(series [float],整数)=> series [float];最高(整数)=>系列[float]
我的理解是,在工作时它将不包括当前的条。有人知道如何包含当前栏吗?谢谢
答案 0 :(得分:0)
以下是如何跟踪最高价和最低价的示例:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
strategy("My Strategy", overlay=true)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
var float hh = na
hh := strategy.position_size > 0 ? max(nz(hh), high) : na
plot(hh, style = plot.style_linebr, color = color.blue)
var float ll = na
ll := strategy.position_size < 0 ? min(na(ll) ? low : ll, low) : na
plot(ll, style = plot.style_linebr, color = color.red)