I'm trying to create a simple volatility indicator in Indie but keep getting an error when trying to import the standard deviation algorithm. I'm new to Indie language after coming from Pine.
I'm getting this error:
Error: 3:39 package indie.algorithms does not contain symbol Stdev
Here's my code:
# indie:lang_version = 5
from indie import indicator, param, plot, color, source, MainContext
from indie.algorithms import Stdev, Ema
@indicator("StdDev Volatility Indicator")
@param.int("length", default=20, min=1, title="StdDev Period")
@param.int("smooth_length", default=10, min=1, title="Smoothing Period")
@param.float("threshold_high", default=2.0, title="High Volatility Threshold")
@param.float("threshold_medium", default=1.0, title="Medium Volatility Threshold")
@param.source("source", default=source.CLOSE, title="Price Source")
@plot.line(title="StdDev", color=color.BLUE)
@plot.line(title="Smoothed StdDev", color=color.RED)
@plot.line(title="High Threshold", color=color.RED(0.5))
@plot.line(title="Medium Threshold", color=color.YELLOW(0.5))
class Main(MainContext):
def calc(self, length, smooth_length, threshold_high, threshold_medium, source):
stddev = Stdev.new(source, length)
smoothed_stddev = Ema.new(stddev, smooth_length)
avg_stddev = Ema.new(stddev, length * 3)[0]
high_threshold = avg_stddev * threshold_high
medium_threshold = avg_stddev * threshold_medium
return (
stddev[0], # Raw standard deviation
smoothed_stddev[0], # Smoothed standard deviation
high_threshold, # High volatility threshold line
medium_threshold # Medium volatility threshold line
)
Has anyone encountered this before? Is there a different way to calculate standard deviation in Indie?
I know in Pine Script I could just use ta.stdev()
but I'm not sure what the equivalent is here.
I'm trying to create a simple volatility indicator in Indie but keep getting an error when trying to import the standard deviation algorithm. I'm new to Indie language after coming from Pine.
I'm getting this error:
Error: 3:39 package indie.algorithms does not contain symbol Stdev
Here's my code:
# indie:lang_version = 5
from indie import indicator, param, plot, color, source, MainContext
from indie.algorithms import Stdev, Ema
@indicator("StdDev Volatility Indicator")
@param.int("length", default=20, min=1, title="StdDev Period")
@param.int("smooth_length", default=10, min=1, title="Smoothing Period")
@param.float("threshold_high", default=2.0, title="High Volatility Threshold")
@param.float("threshold_medium", default=1.0, title="Medium Volatility Threshold")
@param.source("source", default=source.CLOSE, title="Price Source")
@plot.line(title="StdDev", color=color.BLUE)
@plot.line(title="Smoothed StdDev", color=color.RED)
@plot.line(title="High Threshold", color=color.RED(0.5))
@plot.line(title="Medium Threshold", color=color.YELLOW(0.5))
class Main(MainContext):
def calc(self, length, smooth_length, threshold_high, threshold_medium, source):
stddev = Stdev.new(source, length)
smoothed_stddev = Ema.new(stddev, smooth_length)
avg_stddev = Ema.new(stddev, length * 3)[0]
high_threshold = avg_stddev * threshold_high
medium_threshold = avg_stddev * threshold_medium
return (
stddev[0], # Raw standard deviation
smoothed_stddev[0], # Smoothed standard deviation
high_threshold, # High volatility threshold line
medium_threshold # Medium volatility threshold line
)
Has anyone encountered this before? Is there a different way to calculate standard deviation in Indie?
I know in Pine Script I could just use ta.stdev()
but I'm not sure what the equivalent is here.
1 Answer
Reset to default 1In Indie, it's called StdDev
. You can import it this way from indie.algorithms import StdDev
You can read StdDev docs and use built-in indicators as examples.
So your code will be:
# indie:lang_version = 5
from indie import indicator, param, plot, color, source, MainContext
from indie.algorithms import StdDev, Ema
@indicator("StdDev Volatility Indicator")
@param.int("length", default=20, min=1, title="StdDev Period")
@param.int("smooth_length", default=10, min=1, title="Smoothing Period")
@param.float("threshold_high", default=2.0, title="High Volatility Threshold")
@param.float("threshold_medium", default=1.0, title="Medium Volatility Threshold")
@param.source("source", default=source.CLOSE, title="Price Source")
@plot.line(title="StdDev", color=color.BLUE)
@plot.line(title="Smoothed StdDev", color=color.RED)
@plot.line(title="High Threshold", color=color.RED(0.5))
@plot.line(title="Medium Threshold", color=color.YELLOW(0.5))
class Main(MainContext):
def calc(self, length, smooth_length, threshold_high, threshold_medium, source):
stddev = StdDev.new(source, length)
smoothed_stddev = Ema.new(stddev, smooth_length)
avg_stddev = Ema.new(stddev, length * 3)[0]
high_threshold = avg_stddev * threshold_high
medium_threshold = avg_stddev * threshold_medium
return (
stddev[0], # Raw standard deviation
smoothed_stddev[0], # Smoothed standard deviation
high_threshold, # High volatility threshold line
medium_threshold # Medium volatility threshold line
)