[英]Pine Script: Unique ID for strategy.entry function
我想为 PineScript 的 strategy.entry 函数生成唯一 ID:
unique_id = tostring(bar_index)
strategy.entry(unique_id, ...)
这里的问题是 strategy.entry 只接受const string类型的 ID 参数,而我尝试的任何解决方案都给出了series[string]或string 。 有什么办法让它工作吗?
先感谢您!
id = "Two candle reversal " + tostring(time("") / 100000)
也许是这样的:
strategy("Unique_Id")
whprng(Seed) => // Wichmann–Hill Pseudo-Random Number Generator
var germinate = Seed * hlc3 * timenow
float s1 = na, s1 := 171.0 * nz(s1[1], germinate) % 30269.0
float s2 = na, s2 := 172.0 * nz(s2[1], s1 * Seed) % 30307.0
float s3 = na, s3 := 170.0 * nz(s3[1], s2 * Seed) % 30323.0
(s1 / 30269.0 + s2 / 30307.0 + s3 / 30323.0) % 1.0
idLength = 5
rndIndex = 0
alpha = array.from('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9','0')
isUnique = false
rstring = ""
while isUnique == false
rstring := ""
isUnique := true
for i = 0 to idLength
rndIndex := math.floor(whprng(23+i) * array.size(alpha))
rstring := rstring + array.get(alpha, rndIndex)
alert("Routine 1")
entryId = ''
// check open orders for uniqueness
for tradeNo = 0 to strategy.opentrades - 1
entryId := strategy.opentrades.entry_id(tradeNo)
if(entryId == rstring)
isUnique := false
break
// check closed orders for uniqueness
if(isUnique == true)
for tradeNo = 0 to strategy.closedtrades - 1
entryId := strategy.closedtrades.entry_id(tradeNo)
if(entryId == rstring)
isUnique := false
break
// end while
alert("Unique ID = " + rstring)
const someId = rstring
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.