PineScript16 EMA Golden Cross Basic

voonology · study · 35 行 · 点赞 6 · 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/
// © Voonology
// PineScript16 — Developed by Voonology
// Version: 1.0.0
//@version=6
indicator("EMA Golden Cross Basic", overlay=true)
 
// User inputs
fastLen = input.int(50, "Fast EMA Length")
slowLen = input.int(200, "Slow EMA Length")
 
// EMAs
fastEMA = ta.ema(close, fastLen)
slowEMA = ta.ema(close, slowLen)
 
// Cross conditions
crossUp   = ta.crossover(fastEMA, slowEMA)   // Fast crosses above Slow
crossDown = ta.crossunder(fastEMA, slowEMA)  // Fast crosses below Slow
 
// Midpoint between EMAs
midPoint = (fastEMA + slowEMA) / 2
 
// Plot EMAs
plot(fastEMA, color=color.blue, linewidth=1, title="Fast EMA")
plot(slowEMA, color=color.red, linewidth=2, title="Slow EMA")
 
// Plot circles exactly at the midpoint between EMAs when cross happens
plot(crossUp   ? midPoint : na, title="Cross Up Circle",
     style=plot.style_circles, color=color.teal, linewidth=5)
plot(crossDown ? midPoint : na, title="Cross Down Circle",
     style=plot.style_circles, color=color.maroon, linewidth=5)
 
// Alerts
alertcondition(crossUp,   title="EMA Bullish Cross", message="Fast EMA crossed ABOVE Slow EMA")
alertcondition(crossDown, title="EMA Bearish Cross", message="Fast EMA crossed BELOW Slow EMA")

← 返回列表