我有一个策略松树脚本。我希望能够更好地识别我的图上的亏损交易,所以我尝试像这样制作一个条形图:

理想情况下,这只在交易完成时显示条形图(所以我只对每笔交易的最终利润%感兴趣(而不是波动率)。如果我可以在交易开盘(而不是收盘)的时候绘制出来,那就更好了,这样我就可以尝试确定哪些交易不应该开盘。
我看到的一种选择是跟踪利润并以某种方式创建一个系列(对语法不太确定)。或者,很有可能,这些信息保存在策略中,对吗?
更新:在尝试Andrey-D的代码后,它显示如下(即使没有overlay = true):

发布于 2021-06-18 17:35:52
您的位置如下:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © adolgov
//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
float lastTradeProfit = na
if strategy.position_size != strategy.position_size[1]
lastTradeProfit := strategy.netprofit - strategy.netprofit[1]
plot(lastTradeProfit, style = plot.style_columns, color = lastTradeProfit > 0 ? color.green : lastTradeProfit == 0 ? color.gray : color.red, title = "Trade profit/loss")https://stackoverflow.com/questions/68030218
复制相似问题