ATR with Standard Deviation and Average for ThinkorSwim

S

skynetgen

Well-known member
ITs quite revealing about certain market behavior.

thinkScript Code

Code:
#skynetgen
#atr with stdev

declare lower;

input length = 14;
input averageType = AverageType.WILDERS;
input avglength=20;

 
def tr = TrueRange(high, close, low);


plot ATR = MovingAverage(averageType, tr, length);
ATR.SetDefaultColor(GetColor(8));
plot avg=expAverage(atr,avglength);
addcloud(atr,avg,color.green,color.red);

#stdev code. put in relvalue which you want measure
input RelDevLength=20;
input numDev = 1.0;
input ExtraDev = 2.3;
input MegaDev=4;
input MinDev=-1.3;
def relvalue=tr;
def rawRelDev = (relvalue - Average(relvalue , RelDevLength)) / StDev(relvalue, RelDevLength);
def base=lowest(relvalue,20); def cutoff=relvalue;
plot relstdev=if rawreldev+base>=cutoff then cutoff else base+rawreldev;

relstdev.setpaintingStrategy(paintingStrategy.SQUARED_HISTOGRAM);
relstdev.assignValueColor(
    if rawreldev>=MegaDev then color.cyan
    else if rawreldev>ExtraDev then color.green
    else if rawreldev>NumDev then color.dark_green
    else if RawRelDev<MinDev then  color.DARK_GRAY
    else color.current
    );

https://tos.mx/O9llhgT
 
Last edited by a moderator:

Similar threads

Top