繁体   English   中英

Plot 形状一旦满足两个条件,但在满足 100 条后才重新绘制

[英]Plot shape once two conditions are met but don't repaint until it is met after 100 bars

一旦满足两个单独的条件,我想 plot 一个形状,并且在 100 条之后再次满足条件之前不再重新绘制。 到目前为止,我一直在玩以下游戏;

    var bool bull1=na, bool bull2=na, var a_thisBar=1, var a_barCount=bar_index-a_thisBar, var b_thisBar=1, var b_barCount=bar_index-b_thisBar

    a4K:=sma(stoch(close,high,low,8),3)
    a5K:=sma(stoch(close,high,low,32),12)

    if a5K>50
         bull1:=true,a_thisBar:=bar_index
    if bull1 and a_barCount<25 and crossover(a4K,a4D)
         bull2:=true,bull1:=false

   plotshape(bull2,style=shape.arrowup,location=location.belowbar,color=color.blue,size=size.small)

Atm 这工作正常,但可以理解的是,每次满足这两个条件时,它都会绘制一个形状。 我想要它做的是 plot 它在第一个实例上,然后不是 plot 它再次,直到两个条件在第一个实例后至少满足 100 条。

我尝试过使用以下变体但没有成功;

    if a5K>50
        bull1:=true,a_thisBar:=bar_index
    if bull1 and a_barCount<25 and crossover(a4K,a4D) and b_barCount>100
        bull2:=true,bull1:=false,b_thisBar:=bar_index

有一个变量告诉您是否可以开始计数(当您的购买条件变为true时)。

在您的买入条件变为true后,使用另一个变量来计算柱数。

然后等待您的买入条件再次变为true ,并检查您的计数器的值。 当它是有效的买入信号时,重置您的计数器。

下面是一个使用crossunder(RSI, 50)事件进行购买的示例。 出于演示目的,我的计数器设置为 15。 当交叉发生时,我绘制了X标记。

//@version=5
indicator("My script", overlay=true)

var cnt = 0
var startCounting = false

_rsi = ta.rsi(close, 14)
_buy_condition = ta.crossunder(_rsi, 50)

startCounting := _buy_condition ? true : startCounting  // Start counting if the buy condition is true, keep the old value otherwise
cnt := startCounting ? cnt + 1 : cnt    // INcrement the counter if startCounting is true, keep the old value otherwise

canBuy = _buy_condition and cnt > 15
cnt := canBuy ? 0 : cnt     // If there is a buy signal, reset the counter for next buy signal

plotshape(_buy_condition, size=size.small)
plotshape(canBuy, style=shape.triangleup, location=location.belowbar, color=color.green, text="Buy", size=size.small)

在此处输入图像描述

暂无
暂无

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

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