在Pine中,如何检索不同参数值产生的strategy.netprofit?

发布于 2025-01-17 03:34:13 字数 1437 浏览 1 评论 0原文

我想显示策略在不同场景下的净利润,即在退出订单的不同条件下:

//@version=5
strategy("test 2", overlay=true, max_labels_count=500, calc_on_every_tick=true, initial_capital=500, default_qty_value = 500, currency='USD', process_orders_on_close=true, commission_type='percent', commission_value=0.075, default_qty_type=strategy.cash, calc_on_order_fills=true)


// retrieve Heikin Ashi values
haHandle=ticker.heikinashi(syminfo.tickerid)
haOpen=request.security(haHandle,timeframe.period,open)
haClose=request.security(haHandle,timeframe.period,close)
haDeltaAbs=haClose-haClose[1]
haDeltaRel=haDeltaAbs/haClose[1]*100


// Trade Entry
haEntryCondition=haDeltaRel>0 and haDeltaRel[1]<0
strategy.entry("trade", strategy.long, when = haEntryCondition)


// Trade Exit, I perform one Exit order for three different values of a thresold condition (-1, -0.5, 0)
float haThreshold = -1
for i = 0 to 2
    haThreshold := haThreshold + 0.5
    haExitCondition=haDeltaRel<haThreshold
    strategy.close("trade"+str.tostring(i), when = haExitCondition)
    
// I would like to display the result of the strategy (strategy.netprofit) for each of the "type" of exit performed above
if (barstate.islast)
    label.new(bar_index, open, str.tostring(strategy.netprofit), yloc = yloc.price, style = label.style_none, textcolor = color.red, size = size.normal)

最后一行 (label.new(... ) 仅显示总净利润(考虑到所有进场/退出 ,我如何检索与退出订单上的每个“配置”相对应的净利润?

)。相反

I would like to display the netprofit of a strategy over different scenarios, i.e, over different conditions on the exit order:

//@version=5
strategy("test 2", overlay=true, max_labels_count=500, calc_on_every_tick=true, initial_capital=500, default_qty_value = 500, currency='USD', process_orders_on_close=true, commission_type='percent', commission_value=0.075, default_qty_type=strategy.cash, calc_on_order_fills=true)


// retrieve Heikin Ashi values
haHandle=ticker.heikinashi(syminfo.tickerid)
haOpen=request.security(haHandle,timeframe.period,open)
haClose=request.security(haHandle,timeframe.period,close)
haDeltaAbs=haClose-haClose[1]
haDeltaRel=haDeltaAbs/haClose[1]*100


// Trade Entry
haEntryCondition=haDeltaRel>0 and haDeltaRel[1]<0
strategy.entry("trade", strategy.long, when = haEntryCondition)


// Trade Exit, I perform one Exit order for three different values of a thresold condition (-1, -0.5, 0)
float haThreshold = -1
for i = 0 to 2
    haThreshold := haThreshold + 0.5
    haExitCondition=haDeltaRel<haThreshold
    strategy.close("trade"+str.tostring(i), when = haExitCondition)
    
// I would like to display the result of the strategy (strategy.netprofit) for each of the "type" of exit performed above
if (barstate.islast)
    label.new(bar_index, open, str.tostring(strategy.netprofit), yloc = yloc.price, style = label.style_none, textcolor = color.red, size = size.normal)

The last line (label.new(... ) only displays the total net profit (all entries/exits taken into account). Instead, how can I retrieve the net profit that corresponds to each of the "configurations" on the exit order ?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌化 2025-01-24 03:34:13

您可以执行类似的操作,运行循环检查条目 ID 并按名称累加利润。

profitByName(name) =>
    result = 0.
    for i = 0 to strategy.closedtrades-1
        if strategy.closedtrades.entry_id(i) == name
            result += strategy.closedtrades.profit(i) 
    result

您还可以查找退出 ID:

profitByExitName(name) =>
    result = 0.
    for i = 0 to strategy.closedtrades-1
        if strategy.closedtrades.exit_id(i) == name
            result += strategy.closedtrades.profit(i) 
    result

此名称空间中还有许多其他方便的内置程序值得研究

You can do something like this running a loop checking for the entry id and adding up the profit by name.

profitByName(name) =>
    result = 0.
    for i = 0 to strategy.closedtrades-1
        if strategy.closedtrades.entry_id(i) == name
            result += strategy.closedtrades.profit(i) 
    result

You could also look for the exit id:

profitByExitName(name) =>
    result = 0.
    for i = 0 to strategy.closedtrades-1
        if strategy.closedtrades.exit_id(i) == name
            result += strategy.closedtrades.profit(i) 
    result

There are many other handy built-ins in this name space that are worth looking in to

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文