Sigma Spikes Indicator

BenTen

Administrative
Staff
VIP
Here you go:

Code:
# SigmaSpikes(R) per Adam H. Grimes
# Assembled by BenTen at UseThinkScript.com
# Converted from https://www.tradingview.com/script/s8Wz3GbK-SigmaSpikes-R-per-Adam-H-Grimes/

declare lower;

input length = 20;
def change = close/close[1] - 1;
def stdev = stdev(change, length);
def sigma = change / stdev[1];
plot UpperTreshold = 2;
plot LowerTreshold = -2;
plot ZeroLine = 0;
plot r = sigma;
r.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 

madeinnyc

Member
Sometime ago my trading partner wrote a variation of the code above. It was used primarily for options trading:

Code:
#Standard Deviation Spike Indicator by Corvus Xander

declare lower;
input length = 20;
def closeLog = Log(close[1]/ close[2]);
def SDev = stdev(closeLog, length)*Sqrt(length / (length - 1));
def m= SDev * close[1];
plot spike = (close[0]- close[1]) / m;
spike.setPaintingStrategy(PaintingStrategy.HISTOGRAM);
spike.AssignValueColor(if close > close[1] then Color.UPTICK else if close < close[1] then Color.DOWNTICK else GetColor(1));
 

Lone Wolf

New member
@BenTen is there anyway you can add criteria to only show bars on the histogram that are "greater than or equal to X sigma value" (same on the opposite side) and have that on the user input tab instead of having to go in to modify the code?
 

codydog

Active member
@Lone Wolf - I started to write something but guessed your question has been answered by much smarter and more eloquent people than me.

There are lots of comments on google ranging from intro level to Einsteins writing to impress other Einsteins.

Good question though
 

Pensar

Active member
VIP
@Lone Wolf Try this. You can adjust the Upper/Lower Thresholds like @BenTen mentioned. It will only show the bars that extend past the threshold levels.

Code:
# SigmaSpikes(R) per Adam H. Grimes
# Assembled by BenTen at UseThinkScript.com
# Converted from https://www.tradingview.com/script/s8Wz3GbK-SigmaSpikes-R-per-Adam-H-Grimes/
# simple modification by Pensar to only show spikes above/below threshold levels

declare lower;

input length = 20;
def change = close/close[1] - 1;
def stdev = stdev(change, length);
def sigma = change / stdev[1];
plot UpperTreshold = 3;
plot LowerTreshold = -3;
plot ZeroLine = 0;
plot r = if sigma > UpperTreshold
         or sigma < LowerTreshold
         then sigma
         else double.nan;
r.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
 

Lone Wolf

New member
@Lone Wolf Try this. You can adjust the Upper/Lower Thresholds like @BenTen mentioned. It will only show the bars that extend past the threshold levels.

Code:
# SigmaSpikes(R) per Adam H. Grimes
# Assembled by BenTen at UseThinkScript.com
# Converted from https://www.tradingview.com/script/s8Wz3GbK-SigmaSpikes-R-per-Adam-H-Grimes/
# simple modification by Pensar to only show spikes above/below threshold levels

declare lower;

input length = 20;
def change = close/close[1] - 1;
def stdev = stdev(change, length);
def sigma = change / stdev[1];
plot UpperTreshold = 3;
plot LowerTreshold = -3;
plot ZeroLine = 0;
plot r = if sigma > UpperTreshold
         or sigma < LowerTreshold
         then sigma
         else double.nan;
r.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
I really appreciate this, thank you so much!
 

Similar threads

Top