Accumulation Swing index Indicator?

rive7579

New member
Does anyone know hot to write a code to pick up large volatile spikes in this indicator in relation with recent activity. (Daily chart)
 

BenTen

Administrative
Staff
VIP
ThinkorSwim already have a built-in indicator called AccumulationSwingIndex. Take a look at the code below.

Code:
#
# TD Ameritrade IP Company, Inc. (c) 2007-2019
#

declare lower;

input limit_move = 3;

plot ASI = TotalSum(SwingIndex(limit_move));
plot ZeroLine = 0;

ASI.SetDefaultColor(GetColor(1));
ZeroLine.SetDefaultColor(GetColor(5));
 

rive7579

New member
Right, but I am trying to set an alert for when there is a large spike on any given "Daily candle". A 300- 800 point jump in the indicator.
 
Does anyone know hot to write a code to pick up large volatile spikes in this indicator in relation with recent activity. (Daily chart)
I don't know about spikes but the original idea I think was to use it to find swings and combine it with a sort of trailing stop line wherever the swings occur. I'm not sure if this will help but I grabbed some of HPotter and LazyBear's codes and sort of blended them together. I tried grabbing the code from thinkorswim but for some reason theirs seemed to cut off sometimes so I had to grab a more completed looking version from HPotter. LazyBear had the idea of putting in a simple moving average. The original idea of putting a trailing stop seems like a difficult task but I think a simple moving average can do the job just as good.
Code:
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);
 

Similar threads

Top