问题:已执行和关闭的交易的背景颜色有问题

huangapple go评论60阅读模式
英文:

Issue with color backgrounding executed and closed trades

问题

我有两个关于已执行和关闭交易的背景颜色的问题:

我想用背景颜色突出显示盈利和亏损的交易:

longExists = strategy.position_size > 1
// --- 检查交易是盈利还是亏损
isProfitable = strategy.netprofit > 0
// --- 根据结果设置背景颜色
profitColor = color.new(color.green, 5)
lossColor = color.new(color.red, 5)

bgcolor(longExists ? isProfitable ? profitColor : lossColor : na)

背景颜色已设置,但存在以下问题:
1a. 一个应该被设置为绿色(赢得的)的交易被设置为红色,而实际上该交易是赢得的。
1b. 一个应该被设置为红色(亏损的)的交易被设置为绿色,而实际上该交易是亏损的。
问题:已执行和关闭的交易的背景颜色有问题
问题:已执行和关闭的交易的背景颜色有问题
感谢您的专业知识。
2. 显然透明度不起作用

感谢您的专业知识。谢谢。

英文:

I have two issues with color backgrounding executed and closed trades :

I would like to highlight with a background color win and loss trades :

longExists          =  strategy.position_size > 1
// --- Check if trade is won or lost
isProfitable = strategy.netprofit > 0
// --- Background colors according to outcome
profitColor = color.new(color.green, 5)
lossColor   = color.new(color.red, 5)

bgcolor(longExists ? isProfitable ? profitColor : lossColor : na)

Background is set, but :
1a. one trade which should be backgrounded green (won) is backgrounded red and the trade is indeed won.
问题:已执行和关闭的交易的背景颜色有问题
1b. one trade which should be backgrounded red(lost) is backgrounded green and the trade is indeed lost.
问题:已执行和关闭的交易的背景颜色有问题
Would appreciate your expertise
2. Transparency isn't working obviously

Would appreciate your expertise. Thanks.

答案1

得分: 1

您的脚本检查 strategy.netprofit,它表示策略的总利润,会在每笔交易结束时更新。

如果您想根据当前开放交易的盈亏情况来设置背景颜色,您可以检查 strategy.openprofit

bool longExists = strategy.position_size > 0
bool isProfitable = strategy.openprofit > 0

profitColor = color.new(#4caf4f, 5)
lossColor = color.new(color.red, 5)

bgcolor(longExists ? isProfitable ? profitColor : lossColor : na)

背景颜色将动态变化,每根柱状图代表一个开放的交易,显示它是盈利还是亏损,直到交易结束。

英文:

Your script checks strategy.netprofit, which represents the total profit of the strategy and is updated at the close of each trade.

If you want to background color based on the PnL of currently opened trades only, you can check strategy.openprofit instead:

bool longExists =  strategy.position_size > 0
bool isProfitable = strategy.openprofit > 0

profitColor = color.new(#4caf4f, 5)
lossColor   = color.new(color.red, 5)

bgcolor(longExists ? isProfitable ? profitColor : lossColor : na)

The background will change dynamically, indicating on each bar of an open trade whether it was at a loss or a profit, until it is closed.

问题:已执行和关闭的交易的背景颜色有问题

huangapple
  • 本文由 发表于 2023年2月10日 11:22:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/75406626.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定