declare lower;
input smaLength = 10;
def limit = 30;
def AbsHighClose = AbsValue(high - close[1]);
def AbsLowClose = AbsValue(low - close[1]);
def AbsCloseOpen = AbsValue(close[1] - open[1]);
def K = If(AbsHighClose >= AbsLowClose, AbsHighClose, AbsLowClose);
def R = If(AbsHighClose >= AbsLowClose,
If(AbsHighClose >= (high - low), AbsHighClose - 0.5 * AbsLowClose + 0.25 * AbsCloseOpen, (high - low) + 0.25 * AbsCloseOpen),
If(AbsLowClose >= (high - low), AbsLowClose - 0.5 * AbsHighClose + 0.25 * AbsCloseOpen, (high - low) + 0.25 * AbsCloseOpen));
def nRes = If(R != 0,
(50 * (((close - close[1]) + 0.50 * (close - open) + 0.25 * (close[1] - open[1])) / R ) * K / limit) + if !IsNaN(nRes[1]) then nRes[1] else 0,
0 + if !IsNaN(nRes[1]) then nRes[1] else 0);
def asi = nRes;
def sma = SimpleMovingAvg(asi,smaLength);
plot as = asi;
as.SetLineWeight(1);
as.AssignValueColor(if asi>sma then Color.Green else Color.RED);
plot s = sma;
s.SetLineWeight(1);
s.AssignValueColor(Color.VIOLET);