You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TradingView PineScript连续盈亏次数统计:代码结果存验证问题

连续盈亏次数统计代码的可靠性问题

我正尝试统计连续盈利与连续亏损的次数,当前代码可得出统计数值,但将其与策略测试器显示的总盈亏次数进行可靠性验证时,二者并不匹配,因此不确定代码结果是否正确。

当前使用的代码

print(string txt1, string txt2,string txt) => 
    var table t = table.new(position.middle_right, 1, 3)
    table.cell(t, 0, 0, txt1, bgcolor = color.rgb(0, 254, 21))
    table.cell(t, 0, 1, txt2, bgcolor = color.rgb(0, 254, 21))
    table.cell(t, 0, 2, txt, bgcolor = color.rgb(0, 254, 21))

print2(string txt) => 
    var table t = table.new(position.top_right, 1, 1)
    table.cell(t, 0, 0, txt, bgcolor = color.rgb(246, 4, 4))

newLoss = (strategy.losstrades > strategy.losstrades[1]) and (strategy.wintrades == strategy.wintrades[1]) and (strategy.eventrades == strategy.eventrades[1])

var streakLenloss = 0
var lossnum = 0 
 
if (newLoss)
    streakLenloss := streakLenloss + 1
else
    if (strategy.wintrades > strategy.wintrades[1])
        streakLenloss := 0
    else
        streakLenloss := streakLenloss

if ( streakLenloss>= 1)// or streakLenloss == 4 or streakLenloss == 8......
    lossnum := lossnum+1


b = lossnum
print2(str.tostring(b))

此前遇到的问题

曾用以下条件统计连续两次亏损的总次数,但验证时发现得出的亏损数超过了总交易数:

if ( streakLenloss== 2 or streakLenloss == 4 or streakLenloss == 6 or streakLenloss == 8 or streakLenloss == 10)

内容的提问来源于stack exchange,提问作者Sewatech

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 07:01:10