[英]Pine script - Enter position when multiple conditions are true or false
[英]Pine script - Enter position when multiple conditions are true
几天来我一直试图弄清楚这一点,我知道答案将非常简单......
我想在多个条件为真时进入一个位置。 编译脚本时不会产生任何错误,但图表上不会出现应有的买卖(也许代码中还有其他错误??)。 我尝试了很多东西,但这是我最近的尝试。
//@version=3
strategy("Easy BTC Trading", overlay=true,pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
Multiple = input(2, minval=0,step=0.01)
ATR1 = atr(21)*Multiple
volumeavg = (volume[2]+volume[3]+volume[4])/3
highest = highest(high,5)
lowest = lowest(low,5)
long1 = high > highest
long2 = volume[1] >= volumeavg*2
go_long = high > highest and volume[1] > volumeavg*2
exit_long = low < lowest
strategy.entry("Long",strategy.long, when = go_long)
strategy.exit("Exit long","Long", profit = 5, stop = strategy.position_avg_price - ATR1, when = exit_long)
我让你的脚本工作,我复制/粘贴了下面的代码,并附有注释来解释:
//@version=3
strategy("Easy BTC Trading", overlay=true,pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10)
Multiple = input(2, minval=0,step=0.01)
ATR1 = atr(21)*Multiple
volumeavg = (volume[2]+volume[3]+volume[4])/3
//I guess that you want to know the highest value for the last 5 bars
//if yes, in the highest & lowest functions, you need to use close[1]
//which is the previous close before the actual one
//if you just use close, your actual close can be the highest one
//so your long order would never trigger as your close would never
//be higher than the highest
highest = highest(close[1],5)
lowest = lowest(close[1],5)
long1 = close > highest
long2 = volume[1] >= (volumeavg*2)
//go_long = high > highest and volume[1] > volumeavg*2
//there was a problem with that condition above, so I wrote it a clearer way,
// with an if and it works better
go_long = 0
if (close > highest and volume[1] > volumeavg)
go_long := 1
exit_long = close < lowest
strategy.entry("Long",strategy.long, when = go_long)
strategy.exit("Exit long","Long", profit = 5, stop = strategy.position_avg_price - ATR1, when = exit_long)
Vsoler 是对的。 高永远不会高于最高。 当新高达到最高等于最高时,因此您需要将当前蜡烛从最高检查中取出。
改变这个:
highest = highest(high,5)
对此:
highest = highest(high[1],5)
通过这种方式,您将传递给 'highest()' 不包括当前蜡烛的最后 5 根蜡烛。
你认为“高”可以大于“最高”吗? Perhahs 它可以大于最高 [1]
问候维森特·索勒
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.