如何只计算屏幕脚本上的最新烛光 [英] How to calculate only latest candle on a screener script

查看:12
本文介绍了如何只计算屏幕脚本上的最新烛光的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下PINE脚本,它使用黄色形状返回两个买入点。arrowdown(买入) 和一个石灰箭头

study("SniperVX", overlay=true, shorttitle="Vdub_SniperBX_v1")

slow = 8
fast = 5
vh1 = ema(highest(avg(low, close), fast), 5)
vl1 = ema(lowest(avg(high, close), slow), 8)
//
e_ema1 = ema(close, 1)
e_ema2 = ema(e_ema1, 1)
e_ema3 = ema(e_ema2, 1)
tema = 1 * (e_ema1 - e_ema2) + e_ema3
//
e_e1 = ema(close, 8)
e_e2 = ema(e_e1, 5)
dema = 2 * e_e1 - e_e2
signal = tema > dema ? max(vh1, vl1) : min(vh1, vl1)
is_call = tema > dema and signal > low and (signal-signal[1] > signal[1]-signal[2])
is_put = tema < dema and signal < high and (signal[1]-signal > signal[2]-signal[1])
 

//plotshape(is_put ? -1 : na, title="SELL ARROW", color=red, text="*SELL*", style=shape.arrowdown)
//
//Modified - Rajandran R Supertrend----------------------------------------------------- //       Signal 2

Factor=input(1, minval=1,maxval = 000, title="Trend Transition Signal")
Pd=input(1, minval=1,maxval = 100)
Up=hl2-(Factor*atr(Pd))
Dn=hl2+(Factor*atr(Pd))
TrendUp=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
TrendDown=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
Trend = close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],0)
 
plotarrow(Trend == 1 and Trend[1] == -1 ? Trend : na, title="Up Entry Arrow", colorup=lime, maxheight=1000, minheight=50, transp=85)
plotarrow(Trend == -1 and Trend[1] == 1 ? Trend : na, title="Down Entry Arrow", colordown=red, maxheight=1000, minheight=50, transp=85)
plotshape(Trend == 1 and Trend[1] == -1 and is_call ? 1 : na, title="BUY ARROW", color=yellow, text="BUY", style=shape.arrowdown, location=location.abovebar)
plotshape(Trend == -1 and Trend[1] == 1 and is_put ? -1 : na, title="SELL ARROW", color=red, text="SELL", style=shape.arrowdown, location=location.abovebar)

我正在尝试将其转换为筛选器,并使用此代码筛选40只股票

//@version=4
study("Help (Screener)", overlay=false)

// blocco 2
s1 = input('MIL:PIA', type=input.symbol)
s2 = input('MIL:BST', type=input.symbol)
s3 = input('MIL:MONC', type=input.symbol)
s4 = input('MIL:AMP', type=input.symbol)
s5 = input('MIL:TGYM', type=input.symbol)
s6 = input('MIL:BZU', type=input.symbol)
s7 = input('MIL:LR', type=input.symbol)
s8 = input('MIL:CVAL', type=input.symbol)
s9 = input('MIL:PRO', type=input.symbol)
s10 = input('MIL:RM', type=input.symbol)
s11 = input('MIL:CASS', type=input.symbol)
s12 = input('MIL:LIT', type=input.symbol)
s13 = input('MIL:BRE', type=input.symbol)
s14 = input('MIL:TFI', type=input.symbol)
s15 = input('MIL:PRL', type=input.symbol)
s16 = input('MIL:EXO', type=input.symbol)
s17 = input('MIL:GAB', type=input.symbol)
s18 = input('MIL:IKG', type=input.symbol)
s19 = input('MIL:PRT', type=input.symbol)
s20 = input('MIL:IMS', type=input.symbol)
s21 = input('MIL:IGD', type=input.symbol)
s22 = input('MIL:BGN', type=input.symbol)
s23 = input('MIL:MTV', type=input.symbol)
s24 = input('MIL:UNIR', type=input.symbol)
s25 = input('MIL:CAI', type=input.symbol)
s26 = input('MIL:SCK', type=input.symbol)
s27 = input('MIL:AEF', type=input.symbol)
s28 = input('MIL:MN', type=input.symbol)
s29 = input('MIL:IP', type=input.symbol)
s30 = input('MIL:CE', type=input.symbol)
s31 = input('MIL:FNM', type=input.symbol)
s32 = input('MIL:RWAY', type=input.symbol)
s33 = input('MIL:RCS', type=input.symbol)
s34 = input('MIL:BEST', type=input.symbol)
s35 = input('MIL:ERG', type=input.symbol)
s36 = input('MIL:EM', type=input.symbol)
s37 = input('MIL:TNXT', type=input.symbol)
s38 = input('MIL:BFE', type=input.symbol)
s39 = input('MIL:MARR', type=input.symbol)
s40 = input('MIL:GVS', type=input.symbol)




///////////////
// FUNCTIONS //


var Factor=input(1, minval=1,maxval = 000, title="Trend Transition Signal")
var Pd=input(1, minval=1,maxval = 100)
slow = 8
fast = 5
vh1 = ema(highest(avg(low, close), fast), 5)
vl1 = ema(lowest(avg(high, close), slow), 8)
e_ema1 = ema(close, 1)
e_ema2 = ema(e_ema1, 1)
e_ema3 = ema(e_ema2, 1)
tema = 1 * (e_ema1 - e_ema2) + e_ema3
//
e_e1 = ema(close, 8)
e_e2 = ema(e_e1, 5)
dema = 2 * e_e1 - e_e2
signal = tema > dema ? max(vh1, vl1) : min(vh1, vl1)
is_call = tema > dema and signal > low and (signal-signal[1] > signal[1]-signal[2])
is_put = tema < dema and signal < high and (signal[1]-signal > signal[2]-signal[1])


// Screener Function
screenerFunc() => 

    Up=hl2-(Factor*atr(Pd))
    Dn=hl2+(Factor*atr(Pd))    

    TrendUp = 0.0
    TrendDown = 0.0
    Trend = 0

    TrendUp :=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
    TrendDown :=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
    Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],0)
    cond = Trend == 1 and Trend[1] == -1 and is_call
    [Trend, cond]
    
    
// Rounding Function
roundn(x, n) => 
    mult_local = 1 
    if n != 0
        for i = 1 to abs(n)
            mult_local := mult_local * 10
    
    n >= 0 ? round(x * mult_local) / mult_local : round(x / mult_local) * mult_local 

///////////////////////////////////////
// Running Functions for all sybmols //

[v1, c1] = security(s1, timeframe.period, screenerFunc())
[v2, c2] = security(s2, timeframe.period, screenerFunc())
[v3, c3] = security(s3, timeframe.period, screenerFunc())
[v4, c4] = security(s4, timeframe.period, screenerFunc())
[v5, c5] = security(s5, timeframe.period, screenerFunc())
[v6, c6] = security(s6, timeframe.period, screenerFunc())
[v7, c7] = security(s7, timeframe.period, screenerFunc())
[v8, c8] = security(s8, timeframe.period, screenerFunc())
[v9, c9] = security(s9, timeframe.period, screenerFunc())
[v10, c10] = security(s10, timeframe.period, screenerFunc())
[v11, c11] = security(s11, timeframe.period, screenerFunc())
[v12, c12] = security(s12, timeframe.period, screenerFunc())
[v13, c13] = security(s13, timeframe.period, screenerFunc())
[v14, c14] = security(s14, timeframe.period, screenerFunc())
[v15, c15] = security(s15, timeframe.period, screenerFunc())
[v16, c16] = security(s16, timeframe.period, screenerFunc())
[v17, c17] = security(s17, timeframe.period, screenerFunc())
[v18, c18] = security(s18, timeframe.period, screenerFunc())
[v19, c19] = security(s19, timeframe.period, screenerFunc())
[v20, c20] = security(s20, timeframe.period, screenerFunc())
[v21, c21] = security(s21, timeframe.period, screenerFunc())
[v22, c22] = security(s22, timeframe.period, screenerFunc())
[v23, c23] = security(s23, timeframe.period, screenerFunc())
[v24, c24] = security(s24, timeframe.period, screenerFunc())
[v25, c25] = security(s25, timeframe.period, screenerFunc())
[v26, c26] = security(s26, timeframe.period, screenerFunc())
[v27, c27] = security(s27, timeframe.period, screenerFunc())
[v28, c28] = security(s28, timeframe.period, screenerFunc())
[v29, c29] = security(s29, timeframe.period, screenerFunc())
[v30, c30] = security(s30, timeframe.period, screenerFunc())
[v31, c31] = security(s31, timeframe.period, screenerFunc())
[v32, c32] = security(s32, timeframe.period, screenerFunc())
[v33, c33] = security(s33, timeframe.period, screenerFunc())
[v34, c34] = security(s34, timeframe.period, screenerFunc())
[v35, c35] = security(s35, timeframe.period, screenerFunc())
[v36, c36] = security(s36, timeframe.period, screenerFunc())
[v37, c37] = security(s37, timeframe.period, screenerFunc())
[v38, c38] = security(s38, timeframe.period, screenerFunc())
[v39, c39] = security(s39, timeframe.period, screenerFunc())
[v40, c40] = security(s40, timeframe.period, screenerFunc())

////////////////////
// Screener label //

f_buildLabel(_c, _s, _v) =>
    _c ? _s + ' ' + tostring(roundn(_v, 3)) + ' :: ' : ''
    
if barstate.islast
    scr_label = ''
    scr_label := scr_label + f_buildLabel(c1, s1, v1)
    scr_label := scr_label + f_buildLabel(c2, s2, v2)
    scr_label := scr_label + f_buildLabel(c3, s3, v3)
    scr_label := scr_label + f_buildLabel(c4, s4, v4)
    scr_label := scr_label + f_buildLabel(c5, s5, v5)
    scr_label := scr_label + f_buildLabel(c6, s6, v6)
    scr_label := scr_label + f_buildLabel(c7, s7, v7)
    scr_label := scr_label + f_buildLabel(c8, s8, v8)
    scr_label := scr_label + f_buildLabel(c9, s9, v9)
    scr_label := scr_label + f_buildLabel(c10, s10, v10)
    scr_label := scr_label + f_buildLabel(c11, s11, v11)
    scr_label := scr_label + f_buildLabel(c12, s12, v12)
    scr_label := scr_label + f_buildLabel(c13, s13, v13)
    scr_label := scr_label + f_buildLabel(c14, s14, v14)
    scr_label := scr_label + f_buildLabel(c15, s15, v15)
    scr_label := scr_label + f_buildLabel(c16, s16, v16)
    scr_label := scr_label + f_buildLabel(c17, s17, v17)
    scr_label := scr_label + f_buildLabel(c18, s18, v18)
    scr_label := scr_label + f_buildLabel(c19, s19, v19)
    scr_label := scr_label + f_buildLabel(c20, s20, v20)
    scr_label := scr_label + f_buildLabel(c21, s21, v21)
    scr_label := scr_label + f_buildLabel(c22, s22, v22)
    scr_label := scr_label + f_buildLabel(c23, s23, v23)
    scr_label := scr_label + f_buildLabel(c24, s24, v24)
    scr_label := scr_label + f_buildLabel(c25, s25, v25)
    scr_label := scr_label + f_buildLabel(c26, s26, v26)
    scr_label := scr_label + f_buildLabel(c27, s27, v27)
    scr_label := scr_label + f_buildLabel(c28, s28, v28)
    scr_label := scr_label + f_buildLabel(c29, s29, v29)
    scr_label := scr_label + f_buildLabel(c30, s30, v30)
    scr_label := scr_label + f_buildLabel(c31, s31, v31)
    scr_label := scr_label + f_buildLabel(c32, s32, v32)
    scr_label := scr_label + f_buildLabel(c33, s33, v33)
    scr_label := scr_label + f_buildLabel(c34, s34, v34)
    scr_label := scr_label + f_buildLabel(c35, s35, v35)
    scr_label := scr_label + f_buildLabel(c36, s36, v36)
    scr_label := scr_label + f_buildLabel(c37, s37, v37)
    scr_label := scr_label + f_buildLabel(c38, s38, v38)
    scr_label := scr_label + f_buildLabel(c39, s39, v39)
    scr_label := scr_label + f_buildLabel(c40, s40, v40)

    
    
    scr_label := scr_label + "" 
    
   
    
    // Plot Label
    lab_l = label.new(
              bar_index, 0, scr_label, 
              color=color.green, 
              textcolor=color.white, 
              style =  label.style_labeldown,
              yloc = yloc.price)

但它并不像我想要的那样工作,因为我希望只接收图表最新蜡烛中具有黄色形状的股票。箭头向下(买入)和石灰箭头。 (目前,screneer返回黄色形状的股票。arrowdown(买入)和一个石灰箭头 同样在10支或更多支蜡烛之前)。如何执行此操作?

推荐答案

海肯阿西蜡烛的脚本版本。还修复了函数screenerFunc

重要!脚本的运行时间可能超过设置的限制。

//@version=4
study("Help (Screener) for HA", overlay=false)

// blocco 2
s1 = input('MIL:ITW', type=input.symbol)
s2 = input('MIL:BST', type=input.symbol)
s3 = input('MIL:MONC', type=input.symbol)
s4 = input('MIL:AMP', type=input.symbol)
s5 = input('MIL:TGYM', type=input.symbol)
s6 = input('MIL:BZU', type=input.symbol)
s7 = input('MIL:LR', type=input.symbol)
s8 = input('MIL:CVAL', type=input.symbol)
s9 = input('MIL:PRO', type=input.symbol)
s10 = input('MIL:RM', type=input.symbol)
s11 = input('MIL:CASS', type=input.symbol)
s12 = input('MIL:LIT', type=input.symbol)
s13 = input('MIL:BRE', type=input.symbol)
s14 = input('MIL:TFI', type=input.symbol)
s15 = input('MIL:PRL', type=input.symbol)
s16 = input('MIL:EXO', type=input.symbol)
s17 = input('MIL:GAB', type=input.symbol)
s18 = input('MIL:IKG', type=input.symbol)
s19 = input('MIL:PRT', type=input.symbol)
s20 = input('MIL:IMS', type=input.symbol)
s21 = input('MIL:IGD', type=input.symbol)
s22 = input('MIL:BGN', type=input.symbol)
s23 = input('MIL:MTV', type=input.symbol)
s24 = input('MIL:UNIR', type=input.symbol)
s25 = input('MIL:CAI', type=input.symbol)
s26 = input('MIL:SCK', type=input.symbol)
s27 = input('MIL:AEF', type=input.symbol)
s28 = input('MIL:MN', type=input.symbol)
s29 = input('MIL:IP', type=input.symbol)
s30 = input('MIL:CE', type=input.symbol)
s31 = input('MIL:FNM', type=input.symbol)
s32 = input('MIL:RWAY', type=input.symbol)
s33 = input('MIL:RCS', type=input.symbol)
s34 = input('MIL:BEST', type=input.symbol)
s35 = input('MIL:ERG', type=input.symbol)
s36 = input('MIL:EM', type=input.symbol)
s37 = input('MIL:TNXT', type=input.symbol)
s38 = input('MIL:BFE', type=input.symbol)
s39 = input('MIL:MARR', type=input.symbol)
s40 = input('MIL:GVS', type=input.symbol)




///////////////
// FUNCTIONS //


var Factor=input(1, minval=1, maxval = 9, title="Trend Transition Signal")
var Pd=input(1, minval=1, maxval = 9)

// Screener Function
screenerFunc() => 
    
    slow = 8
    fast = 5
    vh1 = ema(highest(avg(low, close), fast), 5)
    vl1 = ema(lowest(avg(high, close), slow), 8)
    e_ema1 = ema(close, 1)
    e_ema2 = ema(e_ema1, 1)
    e_ema3 = ema(e_ema2, 1)
    tema = 1 * (e_ema1 - e_ema2) + e_ema3
    //
    e_e1 = ema(close, 8)
    e_e2 = ema(e_e1, 5)
    dema = 2 * e_e1 - e_e2
    signal = tema > dema ? max(vh1, vl1) : min(vh1, vl1)
    is_call = tema > dema and signal > low and (signal-signal[1] > signal[1]-signal[2])
    is_put = tema < dema and signal < high and (signal[1]-signal > signal[2]-signal[1])

    Up=hl2-(Factor*atr(Pd))
    Dn=hl2+(Factor*atr(Pd))    

    TrendUp = 0.0
    TrendDown = 0.0
    Trend = 0

    TrendUp :=close[1]>TrendUp[1]? max(Up,TrendUp[1]) : Up
    TrendDown :=close[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn
    Trend := close > TrendDown[1] ? 1: close< TrendUp[1]? -1: nz(Trend[1],0)
    cond = Trend == 1 and Trend[1] == -1 and is_call
    [Trend, cond]
    
    
// Rounding Function
roundn(x, n) => 
    mult_local = 1 
    if n != 0
        for i = 1 to abs(n)
            mult_local := mult_local * 10
    
    n >= 0 ? round(x * mult_local) / mult_local : round(x / mult_local) * mult_local 

///////////////////////////////////////
// Running Functions for all sybmols //

[v1, c1] = security(heikinashi(s1), timeframe.period, screenerFunc())
[v2, c2] = security(heikinashi(s2), timeframe.period, screenerFunc())
[v3, c3] = security(heikinashi(s3), timeframe.period, screenerFunc())
[v4, c4] = security(heikinashi(s4), timeframe.period, screenerFunc())
[v5, c5] = security(heikinashi(s5), timeframe.period, screenerFunc())
[v6, c6] = security(heikinashi(s6), timeframe.period, screenerFunc())
[v7, c7] = security(heikinashi(s7), timeframe.period, screenerFunc())
[v8, c8] = security(heikinashi(s8), timeframe.period, screenerFunc())
[v9, c9] = security(heikinashi(s9), timeframe.period, screenerFunc())
[v10, c10] = security(heikinashi(s10), timeframe.period, screenerFunc())
[v11, c11] = security(heikinashi(s11), timeframe.period, screenerFunc())
[v12, c12] = security(heikinashi(s12), timeframe.period, screenerFunc())
[v13, c13] = security(heikinashi(s13), timeframe.period, screenerFunc())
[v14, c14] = security(heikinashi(s14), timeframe.period, screenerFunc())
[v15, c15] = security(heikinashi(s15), timeframe.period, screenerFunc())
[v16, c16] = security(heikinashi(s16), timeframe.period, screenerFunc())
[v17, c17] = security(heikinashi(s17), timeframe.period, screenerFunc())
[v18, c18] = security(heikinashi(s18), timeframe.period, screenerFunc())
[v19, c19] = security(heikinashi(s19), timeframe.period, screenerFunc())
[v20, c20] = security(heikinashi(s20), timeframe.period, screenerFunc())
[v21, c21] = security(heikinashi(s21), timeframe.period, screenerFunc())
[v22, c22] = security(heikinashi(s22), timeframe.period, screenerFunc())
[v23, c23] = security(heikinashi(s23), timeframe.period, screenerFunc())
[v24, c24] = security(heikinashi(s24), timeframe.period, screenerFunc())
[v25, c25] = security(heikinashi(s25), timeframe.period, screenerFunc())
[v26, c26] = security(heikinashi(s26), timeframe.period, screenerFunc())
[v27, c27] = security(heikinashi(s27), timeframe.period, screenerFunc())
[v28, c28] = security(heikinashi(s28), timeframe.period, screenerFunc())
[v29, c29] = security(heikinashi(s29), timeframe.period, screenerFunc())
[v30, c30] = security(heikinashi(s30), timeframe.period, screenerFunc())
[v31, c31] = security(heikinashi(s31), timeframe.period, screenerFunc())
[v32, c32] = security(heikinashi(s32), timeframe.period, screenerFunc())
[v33, c33] = security(heikinashi(s33), timeframe.period, screenerFunc())
[v34, c34] = security(heikinashi(s34), timeframe.period, screenerFunc())
[v35, c35] = security(heikinashi(s35), timeframe.period, screenerFunc())
[v36, c36] = security(heikinashi(s36), timeframe.period, screenerFunc())
[v37, c37] = security(heikinashi(s37), timeframe.period, screenerFunc())
[v38, c38] = security(heikinashi(s38), timeframe.period, screenerFunc())
[v39, c39] = security(heikinashi(s39), timeframe.period, screenerFunc())
[v40, c40] = security(heikinashi(s40), timeframe.period, screenerFunc())

////////////////////
// Screener label //

f_buildLabel(_c, _s, _v) =>
    _c ? _s + ' ' + tostring(roundn(_v, 3)) + ' :: ' : ''
    
if barstate.islast
    scr_label = ''
    scr_label := scr_label + f_buildLabel(c1, s1, v1)
    scr_label := scr_label + f_buildLabel(c2, s2, v2)
    scr_label := scr_label + f_buildLabel(c3, s3, v3)
    scr_label := scr_label + f_buildLabel(c4, s4, v4)
    scr_label := scr_label + f_buildLabel(c5, s5, v5)
    scr_label := scr_label + f_buildLabel(c6, s6, v6)
    scr_label := scr_label + f_buildLabel(c7, s7, v7)
    scr_label := scr_label + f_buildLabel(c8, s8, v8)
    scr_label := scr_label + f_buildLabel(c9, s9, v9)
    scr_label := scr_label + f_buildLabel(c10, s10, v10)
    scr_label := scr_label + f_buildLabel(c11, s11, v11)
    scr_label := scr_label + f_buildLabel(c12, s12, v12)
    scr_label := scr_label + f_buildLabel(c13, s13, v13)
    scr_label := scr_label + f_buildLabel(c14, s14, v14)
    scr_label := scr_label + f_buildLabel(c15, s15, v15)
    scr_label := scr_label + f_buildLabel(c16, s16, v16)
    scr_label := scr_label + f_buildLabel(c17, s17, v17)
    scr_label := scr_label + f_buildLabel(c18, s18, v18)
    scr_label := scr_label + f_buildLabel(c19, s19, v19)
    scr_label := scr_label + f_buildLabel(c20, s20, v20)
    scr_label := scr_label + f_buildLabel(c21, s21, v21)
    scr_label := scr_label + f_buildLabel(c22, s22, v22)
    scr_label := scr_label + f_buildLabel(c23, s23, v23)
    scr_label := scr_label + f_buildLabel(c24, s24, v24)
    scr_label := scr_label + f_buildLabel(c25, s25, v25)
    scr_label := scr_label + f_buildLabel(c26, s26, v26)
    scr_label := scr_label + f_buildLabel(c27, s27, v27)
    scr_label := scr_label + f_buildLabel(c28, s28, v28)
    scr_label := scr_label + f_buildLabel(c29, s29, v29)
    scr_label := scr_label + f_buildLabel(c30, s30, v30)
    scr_label := scr_label + f_buildLabel(c31, s31, v31)
    scr_label := scr_label + f_buildLabel(c32, s32, v32)
    scr_label := scr_label + f_buildLabel(c33, s33, v33)
    scr_label := scr_label + f_buildLabel(c34, s34, v34)
    scr_label := scr_label + f_buildLabel(c35, s35, v35)
    scr_label := scr_label + f_buildLabel(c36, s36, v36)
    scr_label := scr_label + f_buildLabel(c37, s37, v37)
    scr_label := scr_label + f_buildLabel(c38, s38, v38)
    scr_label := scr_label + f_buildLabel(c39, s39, v39)
    scr_label := scr_label + f_buildLabel(c40, s40, v40)

    
    
    scr_label := scr_label + "" 
    
   
    
    // Plot Label
    lab_l = label.new(
              bar_index, 0, scr_label, 
              color=color.green, 
              textcolor=color.white, 
              style =  label.style_labeldown,
              yloc = yloc.price)

这篇关于如何只计算屏幕脚本上的最新烛光的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆