Mr_Wheeler
Active member
I have a study where if you don't manually change the AggregationPeriod's setting in the study's setttings it often leads to a blank study output because the AggregationPeriod & time frame are not correctly synced to each other.
If you for instance set the aggregation perion to the 3 minute chart and have your chart set to 10 minutes then the study becomes blank.
If you for instance set the aggregation perion to the 3 minute chart and have your chart set to 10 minutes then the study becomes blank.
Code:
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(0));
# TOS MTF AccumulationSwingIndex
#global variables
input agg = AggregationPeriod.TEN_MIN;
def cclose = close(period = agg);
def oopen = open(period = agg);
def hhigh = high(period = agg);
def llow = low(period = agg);
# ########################################################
input smaLength = 10;
def limit = 30;
def AbsHighClose = AbsValue(hhigh - cclose[1]);
def AbsLowClose = AbsValue(llow - cclose[1]);
def AbsCloseOpen = AbsValue(cclose[1] - oopen[1]);
def K = If(AbsHighClose >= AbsLowClose, AbsHighClose, AbsLowClose);
def R = If(AbsHighClose >= AbsLowClose,
If(AbsHighClose >= (hhigh - llow), AbsHighClose - 0.5 * AbsLowClose + 0.25 * AbsCloseOpen, (hhigh - llow) + 0.25 * AbsCloseOpen),
If(AbsLowClose >= (hhigh - llow), AbsLowClose - 0.5 * AbsHighClose + 0.25 * AbsCloseOpen, (hhigh - llow) + 0.25 * AbsCloseOpen));
def nRes = If(R != 0,
(50 * (((cclose - cclose[1]) + 0.50 * (cclose - oopen) + 0.25 * (cclose[1] - oopen[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);
# ########################################################
# charting and formatting
plot pASI = ASI;
pASI.SetLineWeight(3);
pASI.AssignValueColor(if asi>sma then Color.Green else Color.RED);
plot pSMA = sma;
pSMA.SetPaintingStrategy(PaintingStrategy.DASHES);
pSMA.SetLineWeight(1);
pSMA.AssignValueColor(Color.VIOLET);
DefineGlobalColor("bear", CreateColor(225, 0, 0)) ;
DefineGlobalColor("bull", CreateColor(0, 165, 0)) ;
AddCloud(pASI, pSMA, GlobalColor("bull"), GlobalColor("bear"));
#AddLabel(yes, if asi > sma then "MTF - Blue area & green dots" else "stand by - Red Area & red dots", if asi < sma then (Color.white) else (color.light_green));
###########################dual
plot Numbers = ASI;
NumberS.AssignValueColor(if asi>sma then Color.Green else Color.white);
Last edited: