首页 > 解决方案 > Pine Script:脚本 SMA 与主图表上的等价物不匹配

问题描述

我编写了一个简单的 Pine Script 图表,它只是模仿了我已经在 TradingView 中使用的图表。

但是,当我叠加我的时,我注意到 Pine Script SMA 的行为与现有图表上的相同 SMA 不同。

它们的创建方式相同:

松脚本:

sma250 = sma(close,250)
plot(sma250, color=color.red)

TVK线走势图:sma250采用收盘来源,时间范围与图表相同。

但是当我叠加它的时候,我的SMA在一个完全不同的地方,角度也和现有的SMA不同。它们似乎都更具反应性。我错过了什么吗?

谢谢。

标签: pine-script

解决方案


晚上好,先生,

下面是内置平滑移动平均线脚本和您的代码行。正如你所看到的,它们是不同的,所以输出也会不同。在右侧添加内置脚本时,会出现一个 (?),它将进一步解释该脚本。

在此处输入图像描述

//@version=4
study(title="Smoothed Moving Average", shorttitle="SMMA", overlay=true, resolution="")

////Trading View In-Built code
len = input(250, minval=1, title="Length")
src = input(close, title="Source")
smma = 0.0
smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
plot(smma, color=color.red)
//Link from Trading View Code -> The (?) to the right when you add the script to your chart
//https://uk.tradingview.com/chart/?solution=43000591343

///Your Code
sma250 = sma(close,250)
plot(sma250, color=color.blue)

推荐阅读