Edge-Preserving Filter


Edge-preserving smoothing is often used in image processing in order to preserve edge information while filtering the remaining signal. I introduce two concepts in this indicator, edge preservation and an adaptive cumulative average allowing for fast edge-signal transition with period increase over time. This filter have nothing to do with classic filters for image processing, those filters use kernels convolution and are most of the time in a spatial domain.

Edge Detection Method

We want to minimize smoothing when an edge is detected, so our first goal is to detect an edge. An edge will be considered as being a peak or a valley, if you recall there is one of my indicator who aim to detect peaks and valley (reference at the bottom of the post), since this estimation return binary outputs we will use it to tell our filter when to stop filtering.

Filtering Increase By Using Multi Steps Cumulative Average

The edge detection is a binary output, using a exponential smoothing could be possible and certainly more efficient but i wanted instead to try using a cumulative average approach because it smooth more and is a bit more original to use an adaptive architecture using something else than exponential averaging. A cumulative average is defined as the sum of the price and the previous value of the cumulative average and then this result is divided by n with n = number of data points. You could say that a cumulative average is a moving average with a linear increasing period.

So lets call CMA our cumulative average and n our divisor. When an edge is detected CMA = close price and n = 1 , else n is equal to previous n+1 and the CMA act as a normal cumulative average by summing its previous values with the price and dividing the sum by n until a new edge is detected, so there is a "no filtering state" and a "filtering state" with linear period increase transition, this is why its multi-steps.

The Filter

The filter have two parameters, a length parameter and a smooth parameter, length refer to the edge detection sensitivity, small values will detect short terms edges while higher values will detect more long terms edges. Smooth is directly related to the edge detection method, high values of smooth can avoid the detection of some edges.

smooth = 200

smooth = 50

smooth = 3


Preserving the price edges can be useful when it come to allow for reactivity during important price points, such filter can help with moving average crossover methods or can be used as a source for other indicators making those directly dependent of the edge detection.

Rsi with a period of 200 and our filter as source, will cross triggers line when an edge is detected

Feel free to share suggestions ! Thanks for reading !


Peak/Valley estimator used for the detection of edges in price.
从常用的脚本中删除 添加到常用的脚本
Great work! Would love to see a linear regression/Bollinger Band script.
+1 回复
alexgrover AmariMars
@AmariMars, Thanks for the support, i will consider working on what you mentioned :)
Thank you again for a great code and imagination
+2 回复
alexgrover aaahopper
@aaahopper, Glad you like it :) Thanks for the support
Looks amazing, I love the simplicity!
+2 回复
alexgrover jaggedsoft
@jaggedsoft, I'm delighted to hear that :) Feel free to modify the code and publish your findings
jaggedsoft alexgrover
@alexgrover, I haven't tested it extensively but it looks very good for usage as a screener or confirmation for other indicators. The only criteria I tested so far is if c > c
+1 回复
MasterPiece!!!!!!!!!!!Thanks for sharing!!!!
+2 回复
alexgrover sudhir.mehta
@sudhir.mehta, Am i really worthy of such praise :D ? Thanks for your support, i'm really glad you like the script :)
jaggedsoft alexgrover
@alexgrover, yes. Innovation is rare in this industry & it's nice to see people being creative. Keep doing what you're doing and you will get whatever you want out of life
+2 回复
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 剧集 如何运作 图表功能 价格 网站规则 版主 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 帮助中心 推荐朋友 功能请求 博客 & 新闻 Twitter
概述 个人资料设置 账号和账单 推荐朋友 我的客服工单 帮助中心 已发表观点 粉丝 正在关注 私人消息 聊天 退出