繁体   English   中英

Pine 脚本多条件更改栏 Colors

[英]Pine Script Multiple Conditions to Change Bar Colors

我有 10 个条件,例如购买 1 购买 2 购买 3 等

由于真实条件的数量,我想更改条形颜色

3 个条件为真条颜色为红色,5 个条件为真条颜色为蓝色,9 个条件为真条颜色为黑色

我该如何编码,我尝试了 if 语句,但它不起作用。

对于每个买入/卖出条件,创建一个 boolean 测试...例如

close > close[1]  // current close is higher than the prior close

符合您的条件要求。 然后根据您的标准总结真实条件的数量并为条形着色......这是一个简短的示例,可以让您继续前进。 请注意,这些条件适用于图表的时间范围......例如,如果您想要不同的时间范围 - 60 分钟图表上的 1D - 您将需要额外的代码。

//@version=5
indicator("Condition Test", overlay=true)

// Code the conditions as booleans

// close is above the prior bar close
priceAdvance  = close > close[1]
// 10 period SMA is above the 20 period SMA
movAvgAdvance = ta.sma(close,10) > ta.sma(close,20)

// Condition Summation - set counter to zero before 
// adding each true condition for each bar

conditionSum = 0
conditionSum += (priceAdvance ? 1 : 0)
conditionSum += (movAvgAdvance ? 1 : 0)

// color the bar yellow if we have exactly two conditions that match
// otherwise do nothing... eg color = na if total conditions != 2
barcolor(color=(conditionSum == 2 ? color.yellow : na))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM