[Python] What is the Indie's equivalent to Pinescript's StDev algorithm?

Discussão em 'Python' iniciado por Stack, Abril 29, 2025.

  1. Stack

    Stack Membro Participativo

    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 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 PineScript I could just use ta.stdev() but I'm not sure what the equivalent is here.

    Continue reading...

Compartilhe esta Página