OPEN-SOURCE SCRIPT
Test

this is a test script
bool newClosed = strategy.closedtrades > strategy.closedtrades[1]
if newClosed
int last = strategy.closedtrades - 1
// 最新平仓 trade 的关键信息
string eid = strategy.closedtrades.entry_id(last)
float epx = strategy.closedtrades.entry_price(last)
string xid = strategy.closedtrades.exit_id(last)
float xpx = strategy.closedtrades.exit_price(last)
float pnl = strategy.closedtrades.profit(last) // 注意:单位是策略币种/合约计价(受 commission 等影响)
// 判断是不是“止损”触发(看 exit_id)
bool isStop = str.startswith(xid, "S_SL_")
string msg = "CLOSED TRADE (new)\n" +"entry: " + eid + " @ " + str.tostring(epx) + "\n" +"exit : " + xid + " @ " + str.tostring(xpx) + "\n" +"pnl : " + str.tostring(pnl) + "\n" +"isStop=" + str.tostring(isStop)
label.new(bar_index, high, msg, style=label.style_label_down, textalign=text.align_left)
bool newClosed = strategy.closedtrades > strategy.closedtrades[1]
if newClosed
int last = strategy.closedtrades - 1
// 最新平仓 trade 的关键信息
string eid = strategy.closedtrades.entry_id(last)
float epx = strategy.closedtrades.entry_price(last)
string xid = strategy.closedtrades.exit_id(last)
float xpx = strategy.closedtrades.exit_price(last)
float pnl = strategy.closedtrades.profit(last) // 注意:单位是策略币种/合约计价(受 commission 等影响)
// 判断是不是“止损”触发(看 exit_id)
bool isStop = str.startswith(xid, "S_SL_")
string msg = "CLOSED TRADE (new)\n" +"entry: " + eid + " @ " + str.tostring(epx) + "\n" +"exit : " + xid + " @ " + str.tostring(xpx) + "\n" +"pnl : " + str.tostring(pnl) + "\n" +"isStop=" + str.tostring(isStop)
label.new(bar_index, high, msg, style=label.style_label_down, textalign=text.align_left)
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。