The function is:
def mmadas(tp,sma,timeP){
return moving(def(x,y)->avg(abs(x - y.last())), [tp, sma], timeP)
}
def cci(high,low,close,timeP){
tp=rowAvg(high,low,close)
sma=mavg(tp,timeP)
dev=mmadas(tp,sma,timeP)
return (tp-sma)/(0.015* dev)
}
Testing script is :
login(`admin,`123456)
dataFilePath = "D:/data/cs-cci.csv"
tmpTB = loadText(dataFilePath)
a = select Date, rowAvg(high,low,close) as tp,mavg(rowAvg(high,low,close),20) as sma from tmpTB
def mmadas(tp,sma,timeP){
return moving(def(x,y)->avg(abs(x - y.last())), [tp, sma], timeP)
}
select Date, mmadas(tp,sma,20) as dev from
The test data is in the attachment.