FVMA

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.8 kB
8
Indexable
Never
//@version=5
indicator(title='Bixord: FantailVMA', shorttitle='FVMA', overlay=true)

ADX_Length = input.int(2, minval=1, title='ADX Length')
Weighting = input.float(10.0, minval=1, title='Weighting')
MA_Length = input.int(6, minval=1, title='MA Length')
emalen = input.int(2, title="EMA Length")

VMA = close
VarMA = close
MA = close
STR = high - low
sPDI = 0.0
sMDI = 0.0
ADX = 0.0
ADXR = 0.0

Hi = high
Hi1 = high[1]
Lo = low
Lo1 = low[1]
Close1 = close[1]

Bulls1 = 0.5 * (math.abs(Hi - Hi1) + Hi - Hi1)
Bears1 = 0.5 * (math.abs(Lo1 - Lo) + Lo1 - Lo)

Bears = Bulls1 > Bears1 ? 0 : Bulls1 == Bears1 ? 0 : Bears1
Bulls = Bulls1 < Bears1 ? 0 : Bulls1 == Bears1 ? 0 : Bulls1

if bar_index > 0
    sPDI := (Weighting * sPDI[1] + Bulls) / (Weighting + 1)  //ma weighting 
    sMDI := (Weighting * sMDI[1] + Bears) / (Weighting + 1)  //ma weighting 
    sMDI


TR = math.max(Hi - Lo, Hi - Close1)
if bar_index > 0
    STR := (Weighting * STR[1] + TR) / (Weighting + 1)
    STR



PDI = STR > 0 ? sPDI / STR : 0
MDI = STR > 0 ? sMDI / STR : 0
DX = PDI + MDI > 0 ? math.abs(PDI - MDI) / (PDI + MDI) : 0
if bar_index > 0
    ADX := (Weighting * ADX[1] + DX) / (Weighting + 1)
    ADX
vADX = ADX

adxlow = ta.lowest(ADX, ADX_Length)
adxmax = ta.highest(ADX, ADX_Length)
ADXmin = math.min(1000000.0, adxlow)
ADXmax = math.max(-1.0, adxmax)
Diff = ADXmax - ADXmin

Const = Diff > 0 ? (vADX - ADXmin) / Diff : 0

if bar_index > 0
    VarMA := ((2 - Const) * VarMA[1] + Const * close) / 2
    VarMA

MA := ta.sma(VarMA, MA_Length)

ema=ta.ema(close,emalen)
plot(MA, color=color.new(color.white, 0), title='Bixord FVMA ')
plot(ema,color=color.blue, title="Ema")

alertcondition(ta.crossover(ema,MA),"Crossover","EMA crossing over FVMA")
alertcondition(ta.crossunder(ema,MA),"Crossunder","EMA crossing under FVMA")