Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //author=[Cyrus c|:D]
- study(title="Accumulation/Distribution Money Flow [c|:D]", shorttitle="[ADMF]", precision=0)
- // inputs
- mas = input(title="Aggregation", defval="EMA", options=["SMA", "EMA", "Sum"])
- len = input(27, minval=1, title="Moving Average Length") // EMA27 = SMMA/RMA14 ~ lunar month
- pEnable = input(true, title="Factor price (money flow)")
- src = input(close, title="Source")
- norm = input(title="Normalize by", defval="Spread", options=["Disable", "Spread", "Previous Bar Price"])
- ve = input(5.0, minval=0, title="Volume Exponent (10+ increases and 10- decreases volume factor)")
- weight = input(0.0, minval=0, maxval=10.0, title="Wick Weight")
- tvf = input(false, title="Enable Volume Aggregation (in Sum mode, gray line shows OBV)")
- // calculations
- eps = 0.00000001
- trl = min(low,close[1]), trh = max(high,close[1]) // 'True Range' fixes issues caused by gaps in price
- adr = weight*(2*close-(trh+trl))/10.0 + (1-weight/10.0)*change(src)
- adr := norm=="Disable" ? adr : adr/(norm=="Spread" ? nz(tr(true),eps) : nz(src[1],eps))
- v = pow(volume,ve/10)*(pEnable ? src : 1)
- spv = sign(adr)*v
- sad = adr*v
- // aggregation
- maSV = not tvf ? na : mas=="SMA" ? sma(spv,len) : mas=="EMA" ? ema(spv,len) : cum(spv)
- maSAD = mas=="SMA" ? sma(sad,len) : mas=="EMA" ? ema(sad,len) : cum(sad)
- // plot
- plot(maSAD, style=line, color=#4477ffff, title="Accumulation/Distribution")
- plot(maSV, style=line , color=#888888ff, title="Volume")
- plot(mas!="Sum" ? 0 : na, color=#88888866, title="Middle Line")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement