Noise Area Formula with Gap Adjustments

moisesdeandrade · study · 33 行 · 点赞 55 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © moisesdeandrade
 
//@version=5
indicator("Noise Area Formula with Gap Adjustments", overlay=true)
 
// Defining the calculation period
length = 14
 
// Determining daily opening and previous close prices correctly for intraday timeframes
var float dailyOpen = na
var float previousClose = na
if (dayofweek != dayofweek[1]) // Checks if a new trading day has started
    dailyOpen := open
    previousClose := close[1] // Capture the closing price of the last candle of the previous day
 
// Function to calculate absolute movement based on the last 14 opening prices
var float[] movements = array.new_float(length, na)
if (not na(dailyOpen))
    array.unshift(movements, math.abs(close - dailyOpen) / dailyOpen)
    if array.size(movements) > length
        array.pop(movements)
 
// Average of the movements
avgMovements = array.avg(movements)
 
// Defining the Noise Area boundaries with gap adjustment
upperBound = math.max(dailyOpen, previousClose) * (1 + avgMovements)
lowerBound = math.min(dailyOpen, previousClose) * (1 - avgMovements)
 
// Plotting the boundaries on the chart
plot(upperBound, "Upper Bound", color=color.green)
plot(lowerBound, "Lower Bound", color=color.green)

← 返回列表