Williams %R + Keltner chanells - indicator (AS)

Adam-Szafranski · study · 64 行 · 点赞 413 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator("Williams %R + Keltner chanells - indicator (AS)", shorttitle="KC+%R",overlay = true)
//, initial_capital = 10000,default_qty_type = strategy.percent_of_equity,default_qty_value = 100)
MA(FF_SRC, FF_LEN, FF_TYP) =>
    switch FF_TYP
        'EMA'     => ta.ema     (FF_SRC, FF_LEN)
        'HMA'     => ta.hma     (FF_SRC, FF_LEN)
        'RMA'     => ta.rma     (FF_SRC, FF_LEN)
        'SMA'     => ta.sma     (FF_SRC, FF_LEN)
        'WMA'     => ta.wma     (FF_SRC, FF_LEN)
TT_LEVEL_OVB_OVS = 'OVB=lower=more signals/OVS=higher=more signals'
TT_PERCENT_RANGE = 'recomeded bigger period and big smoothing np 200/36 or 140/55'
TT_DEBUG_OVERLAY = 'turn off if you want to see Williams %R.'
TT_MOVAVG_FILTER = 'MA is a filter if you want to transform it into a strategy'
////////////////INPUTS/////////////////////////////INPUTS/////////////
var PR      = '----------Williams %R settings-------------------------'
PR_WPR      = input.int     (140   ,'WPR-LEN/SMT/TYP'   , group =PR ,inline='R1')
SM_WPR      = input.int     (36    ,'/'                 , group =PR ,inline='R1')
SM_TYP      = input.string  ('SMA' ,'/'                 , group =PR ,inline='R1',options=['EMA','HMA','RMA','SMA','WMA'],tooltip = TT_PERCENT_RANGE)
PR_OVS      = input.int     (-80   ,'WPR-OVS/MID/OVB'   , group =PR ,inline='R2')
PR_MID      = input.int     (-50   ,'/'                 , group =PR ,inline='R2')
PR_OVB      = input.int     (-20   ,'/'                 , group =PR ,inline='R2',tooltip = TT_LEVEL_OVB_OVS)
var KC      = '----------Keltner channels settings---------------------'
KC_LEN      = input.int     (81    ,'KC-LEN', group =KC ,inline='K1')
KC_TYP      = input.string  ('SMA' ,'KC-TYP', group =KC ,inline='K1',options=['EMA','HMA','RMA','SMA','WMA'])
KC_TRX      = input.float   (2.0   ,'KC-TRX', group =KC ,inline='K2')
KC_ATR      = input.int     (81    ,'KC-ATR', group =KC ,inline='K2')
var OT      = '----------Other settings--------------------------------'
//MA_LEN      = input.int     (200   ,'MA-LEN', group =OT ,inline='O1') 
//MA_TYP      = input.string  ('SMA' ,'MA-TYP', group =OT ,inline='O1',options=['EMA','HMA','RMA','SMA','WMA'],tooltip = TT_MOVAVG_FILTER)
OT_SRC      = input         (ohlc4 ,'SOURCE', group =OT ,inline='O2')
OV_TRU      = input.bool    (true  ,'OVELAY', group =OT ,inline='O2',tooltip = TT_DEBUG_OVERLAY)
/////////////CALC - KELTNER - WPR% - EMA///////////////
WPRA    = ta.wpr(PR_WPR)                , PRSM    = MA(WPRA,SM_WPR,SM_TYP)
KCMA    = MA(OT_SRC,KC_LEN,KC_TYP)      , KCTR    = (ta.atr(KC_ATR)*KC_TRX)
KCUP    = KCMA+KCTR                     , KCDN    = KCMA-KCTR
//AVGM    = MA(OT_SRC,MA_LEN,MA_TYP)      , COLR    = AVGM<OT_SRC?color.green:AVGM>OT_SRC?color.red:na
///////////OVERLAY=TRUE///////////////
plot(OV_TRU?KCMA:na   ,'KCMA'   ,color.rgb(151, 13, 86, 10)   ,2)
plot(OV_TRU?KCDN:na   ,'KCDN'   ,color.rgb(78, 162, 252)      ,2)
plot(OV_TRU?KCUP:na   ,'KCUP'   ,color.rgb(78, 162, 252)      ,2)
//plot(OV_TRU?AVGM:na   ,'AVGM'   ,COLR                           ,2)
///////////OVERLAY=FALSE//////////////
plot(OV_TRU?na:WPRA   ,'%RAW'   ,color.rgb(114, 152, 2, 40)   ,1)
plot(OV_TRU?na:PRSM   ,'%SMT'   ,color.rgb(51, 165, 227, 12)  ,1)
plot(OV_TRU?na:PR_OVB ,'BUYY'   ,color.rgb(60, 215, 145)      ,1)
plot(OV_TRU?na:PR_OVS ,'SELL'   ,color.rgb(239, 111, 32, 6)   ,1)
plot(OV_TRU?na:PR_MID ,'MIDL'   ,color.rgb(169, 173, 191, 16) ,1)
////////BGCOLOR///////////////////
bgcolor(PRSM<PR_OVS and KCUP>OT_SRC?color.rgb(238, 113, 113, 70):PRSM>PR_OVB and KCDN<OT_SRC?color.rgb(98, 223, 148, 70):na,title = 'WPR')
 
//LONG    = PRSM>PR_OVB and KCUP<OT_SRC and AVGM<OT_SRC
//SHRT    = PRSM<PR_OVS and KCDN>OT_SRC and AVGM>OT_SRC
//BG      = OT_SRC>KCUP or OT_SRC<KCDN 
//bgcolor(BG and LONG ?color.rgb(98, 221, 147, 55):BG and SHRT ?color.rgb(214, 79, 104, 56):na,title = 'L/S')
//bgcolor(strategy.position_size<0?color.rgb(246, 91, 91, 57):strategy.position_size>0?color.rgb(76, 175, 79, 50):na)
//if LONG
//    strategy.entry('L',strategy.long)
//if strategy.position_size>0 and ta.cross(ohlc4,KCMA)
//    strategy.close('L','ExL')
//if SHRT
//    strategy.entry('S',strategy.short)
//if strategy.position_size<0 and ta.cross(ohlc4,KCMA)
//    strategy.close('S','ExS')

← 返回列表