簡體   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