首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >if/else的Guppy颜色变化问题。如何解决?

if/else的Guppy颜色变化问题。如何解决?
EN

Stack Overflow用户
提问于 2021-02-26 07:55:16
回答 1查看 80关注 0票数 0

我有一个孔雀鱼的策略,它应该进入长(当孔雀鱼在特定条件下变成绿色)或短(当孔雀鱼在特定条件下变成红色时)。为了确定pine脚本中的颜色,我使用了if/else。问题出在哪里?当两个条件都不满足时,我得到第三种颜色(比方说灰色),例如,在我得到red1=>grey=>red2的情况下,当red2发生时,我的策略发送信号关闭先前的交易,并以相同的方向打开新的交易。在我的策略中,灰色不是进入/退出位置的信号,所以我想让当前的“灰色”以与前一段着色相同的方式着色,直到满足完全相反的条件。我尝试了其他na,但这些中间条件仍然给我错误的信号,我也尝试将plotcolor=plotcolor 1 在'else‘中,但此类型的命令不能放在pine脚本中。有谁能帮我解决这个问题吗?

代码语言:javascript
复制
plot_color0 = if hma8>hma0[2] and hma7>hma0[2] and hma6>hma0[2] and hma5>hma0[2] and hma4>hma0[2] and hma3>hma0[2] and hma2>hma0[2] and hma1>hma0[2] 
      aqua
  else 
      if hma8

basically the problem happens when tradingview.com/x/AnFOTdEa colour turns blue (long signal which gives me command to close previous positions and to open new) after that turns grey and again blue and once again i get long signal (which closes my previous long position and opens it once again). What i want to figure out is how to set alert which either would not trigger after grey colour if previous trade signal direction was the same direction to previous signal or to remove this 'else gray' in the way, where the colour will change only if opposite direction conditions was met

if i put plot0 != gray in conditions alert simply doesn't trigger at all obviously, and i can't exclude 'else gray'

in the end i want alert to trigger only if previous trigger was in opposite direction besides longCondition and shortCondition mentioned above

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-02-27 09:43:42

尝试此表单中的条件,灰色将仅保留在前几个条形上。

代码语言:javascript
复制
plot_color0 = gray
plot_color0 := if hma8>hma0[2] and hma7>hma0[2] and hma6>hma0[2] and hma5>hma0[2] and hma4>hma0[2] and hma3>hma0[2] and hma2>hma0[2] and hma1>hma0[2] 
      aqua
  else 
      if hma8
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66378206

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档