ZGfinance on Nostr: // 定义数据长度 data_length = 100 // 定义短期和长期移动平均线长度 ...
// 定义数据长度
data_length = 100
// 定义短期和长期移动平均线长度
short_length = 12
long_length = 26
// 定义快速线和慢速线的加权参数
fast_weight = 2.0 / (short_length + 1)
slow_weight = 2.0 / (long_length + 1)
// 初始化DIF和DEA线
dif = 0.0
dea = 0.0
// 根据个股特性,动态调整参数
if (stock_volatility > 0.5):
short_length = 10
long_length = 30
elif (stock_volatility < 0.2):
short_length = 5
long_length = 15
// 计算移动平均线和MACD指标
ema_short = ema(data, short_length, fast_weight)
ema_long = ema(data, long_length, slow_weight)
dif = ema_short - ema_long
dea = ema(dif, 9, 2.0 / (9 + 1))
macd = (dif - dea) * 2
Published at
2023-03-01 02:38:31Event JSON
{
"id": "e461df17ae5f46106e7f19201e815ffc376b03de273875e16b8236bf785bacd8",
"pubkey": "97788561567c1f3add68a106791d2a90155d5d140318183d2f9793ee95e2e53b",
"created_at": 1677638311,
"kind": 1,
"tags": [],
"content": "// 定义数据长度\ndata_length = 100\n\n// 定义短期和长期移动平均线长度\nshort_length = 12\nlong_length = 26\n\n// 定义快速线和慢速线的加权参数\nfast_weight = 2.0 / (short_length + 1)\nslow_weight = 2.0 / (long_length + 1)\n\n// 初始化DIF和DEA线\ndif = 0.0\ndea = 0.0\n\n// 根据个股特性,动态调整参数\nif (stock_volatility \u003e 0.5):\n short_length = 10\n long_length = 30\nelif (stock_volatility \u003c 0.2):\n short_length = 5\n long_length = 15\n\n// 计算移动平均线和MACD指标\nema_short = ema(data, short_length, fast_weight)\nema_long = ema(data, long_length, slow_weight)\n\ndif = ema_short - ema_long\ndea = ema(dif, 9, 2.0 / (9 + 1))\nmacd = (dif - dea) * 2\n",
"sig": "8a9e86c434856cc50d4a7e9945ed00f6052e4bf6e36b98ab2f9d017daa31574953c2a1b12c95cf792789bf96b75d77a7fae3f35dea01f0681071a2695bca9973"
}