在Pine中,如何检索不同参数值产生的strategy.netprofit?
我想显示策略在不同场景下的净利润,即在退出订单的不同条件下:
//@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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以执行类似的操作,运行循环检查条目 ID 并按名称累加利润。
您还可以查找退出 ID:
此名称空间中还有许多其他方便的内置程序值得研究
You can do something like this running a loop checking for the entry id and adding up the profit by name.
You could also look for the exit id:
There are many other handy built-ins in this name space that are worth looking in to