在策略图上绘制每笔交易的利润图 [英] Plotting profit per trade in a strategy on the plot

查看:14
本文介绍了在策略图上绘制每笔交易的利润图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

理想情况下,这只在交易完成时显示条(所以我只对每笔交易的最终利润百分比感兴趣(而不是它的波动性)。如果我可以在交易开盘(而不是收盘)的时候绘制出来,那就更好了,这样我就可以尝试确定哪些交易不应该开盘。

我看到的一种选择是跟踪利润并以某种方式创建一个系列(对语法不太确定)。或者,此信息很可能保存在策略中,对吗?

更新:尝试Andrey-D的代码后,显示如下(即使没有overlay=true):

推荐答案

给您:

// 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")

这篇关于在策略图上绘制每笔交易的利润图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆