如何仅在价格下跌 1% 时发出下一个买入信号?我不想一遍又一遍地以几乎相同的价格购买。脚本

How to make a next BuySignal only if the price goes 1% lower? I don't wanna buy almost at the same price over and over again. Pinescript

如何仅在价格下跌 1% 时发出下一个买入信号?我不想一遍又一遍地以几乎相同的价格购买。 Pinescript

//@version=5


indicator(title="Main Channel", overlay=true)
src = close
len = input(100)
mult = input(2)
a = ta.linreg(src, len, 0)
a1 = ta.linreg(src,len,1)
b = (a-a1)

MD(a,b,shift)=>
    md = math.pow(a-b*shift - close[shift], 2)

sum2 = 0.0
for shift = 0 to len-1
    sum2:=sum2+MD(a,b,shift)
    
ranges = math.sqrt(sum2/(len+1))*mult
top = a+ranges
bot = a-ranges
plot(top, color=color.red, linewidth=2, transp=0, title = "Upper Line")
plot(bot, color=color.green, linewidth=2, transp=0, title = "Lower Line")

//CROSSES///////////////////////////////////////////////////////////

sell=ta.crossover(high,top)

buy=ta.crossunder(low,bot)

//SHAPES/////////////////////////////////////////////////////////////////////////
plotshape(top and sell, style=shape.triangledown, location=location.abovebar, color =color.red, transp=0, size = size.small, title="Upper 6 Signal")
plotshape(bot and buy, style=shape.triangleup, location=location.belowbar, color =color.lime, transp=0, size = size.small, title="Lower 6 Signal")

您可以使用如下价格过滤器

//@version=5


indicator(title="Main Channel", overlay=true)
src = close
len = input(100)
mult = input(2)
a = ta.linreg(src, len, 0)
a1 = ta.linreg(src,len,1)
b = (a-a1)

MD(a,b,shift)=>
    md = math.pow(a-b*shift - close[shift], 2)

sum2 = 0.0
for shift = 0 to len-1
    sum2:=sum2+MD(a,b,shift)
    
ranges = math.sqrt(sum2/(len+1))*mult
top = a+ranges
bot = a-ranges
plot(top, color=color.red, linewidth=2, transp=0, title = "Upper Line")
plot(bot, color=color.green, linewidth=2, transp=0, title = "Lower Line")

//CROSSES///////////////////////////////////////////////////////////

sell=ta.crossover(high,top)

buy=ta.crossunder(low,bot)

/////// anonimm support ///
k2=0
k2:= buy  ? 1 : sell ? -1 : 0
 
price= 0.0
price:= k2== 1 ? close :  k2== -1 ? close : price[1]
 
Dif = math.abs(price-close)
PriceCheckPer = input.float(title="Price Check (%)",    minval=0.00, step=0.01, defval=1.00) * 0.01   

k3=0
k3:= (k2 ==1 or k2 == -1 ) and math.abs(price-price[1]) < price[1] * PriceCheckPer ? 0 : 
     k2 ==1 and math.abs(price-price[1]) >= price[1] * PriceCheckPer ? 1 : k2 ==-1 and math.abs(price-price[1]) >= price[1] * PriceCheckPer ? -1 :0 
 
////////




//SHAPES/////////////////////////////////////////////////////////////////////////
plotshape(top and k3==-1, style=shape.triangledown, location=location.abovebar, color =color.red, transp=0, size = size.small, title="Upper 6 Signal")
plotshape(bot and k3==1, style=shape.triangleup, location=location.belowbar, color =color.lime, transp=0, size = size.small, title="Lower 6 Signal")