Momentum adjusted Moving Average by DGT

dgtrd · study · 41 行 · 点赞 4,907 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dgtrd
 
// Moving Average, calculated using Momentum, Acceleration and Probability (Psychological Effect)
//
//@version=4
study(title="Momentum adjusted Moving Average by DGT", shorttitle="MaMA by DGT", overlay=true)
 
// -Input ======================================================================================= //
 
length=input(55, minval=1, title="Moving Average Length")
exponential = input(true)
mLength=input(34, minval=0, title="Momentum Length")
accelerationFactor = input(true) 
pLength=input(13, minval=1, title="Probability Length")
displayMa = input(false, title="Display Regular Moving Average")
source = input(close, title="Source", type=input.source)
offset=input(1, minval=-5, maxval=5, title="offset")
 
// -Calculation ================================================================================= //
 
momentum = source - source[mLength]
 
bullOutcome = source > source[1] ? 1 : 0
sumOfBullOutcome = sum(bullOutcome, pLength)
probability = sumOfBullOutcome/pLength
 
var adjustedSource = 0.0
if accelerationFactor
    acceleration = momentum - momentum[mLength]
    adjustedSource := source + (momentum + .5 * acceleration) * probability
else
    adjustedSource := source + momentum * probability
 
adjustedMa = exponential ? ema(adjustedSource,length) : sma(adjustedSource,length)
regularMa = displayMa ? exponential ? ema(source,length) : sma(source,length) : na
 
// -Plot ======================================================================================== //
 
plot(adjustedMa, color = (source > adjustedMa ? color.green : color.red), offset = offset, title = "Momentum adjusted Moving Average")
plot(regularMa, title = "Regular Moving Average")

← 返回列表