最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Standard Deviation Indicator in Indie - Import Error - Stack Overflow

programmeradmin1浏览0评论

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.

Share Improve this question edited Mar 29 at 0:01 Gu5tavo71 1,2181 gold badge7 silver badges17 bronze badges asked Mar 28 at 5:01 turfiraturfira 616 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

In 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
        )
发布评论

评论列表(0)

  1. 暂无评论