Standard deviation measures how far price disperses from its N-bar mean — the raw statistical building block behind volatility bands. Rising values warn of expanding volatility (bigger risk, smaller position sizing); low, contracting readings often precede breakouts. Copy the version for your platform.
//@version=5
indicator("Standard Deviation", overlay=false)
length = input.int(20, "Length")
dev = ta.stdev(close, length)
plot(dev, title="StdDev", color=color.navy, linewidth=2)#property indicator_separate_window
#property indicator_buffers 1
extern int Dev_Period = 20;
double DevBuffer[];
int OnInit() {
SetIndexBuffer(0, DevBuffer);
return 0;
}
int OnCalculate(const int rates_total, const int prev_calculated, const double &close[]) {
for (int i = prev_calculated; i < rates_total; i++)
DevBuffer[i] = iStdDev(NULL, 0, Dev_Period, 0, MODE_SMA, PRICE_CLOSE, i);
return rates_total;
}#property indicator_separate_window
#property indicator_buffers 1
input int Dev_Period = 20;
double DevBuffer[];
int OnInit() {
SetIndexBuffer(0, DevBuffer);
return INIT_SUCCEEDED;
}
int OnCalculate(const int rates_total, const int prev_calculated,
const datetime &time[], const double &open[], const double &high[],
const double &low[], const double &close[], const long &tick_volume[],
const long &volume[], const int &spread[]) {
for (int i = prev_calculated; i < rates_total; i++)
DevBuffer[i] = iStdDev(NULL, 0, Dev_Period, 0, MODE_SMA, PRICE_CLOSE, i);
return rates_total;
}inputs: Length(20);
variables: Dev(0);
Dev = StandardDev(Close, Length, 1);
Plot1(Dev, "Standard Deviation");To use it inside dtcharts, paste any version into the Script Converter and it becomes a native indicator on your chart.