ema - andyjk

andy_j_k · study · 50 行 · 点赞 22 · TradingView 原页

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

Pine Script

//@version=6 
indicator("XAUUSD Traffic Lights + VWAP + 60 Pips", overlay=true, max_lines_count=2)
 
// SETTINGS 
pips = input.int(60, "Distance in Pips", minval=1) 
pipSize = input.float(0.10, "Value of 1 Pip", minval=0.01, step=0.01)
 
// LIVE PRICE 
livePrice = close 
distance = pips * pipSize 
upperPrice = livePrice + distance 
lowerPrice = livePrice - distance
 
// EMA CALCULATIONS 
ema50 = ta.ema(close, 50) 
ema100 = ta.ema(close, 100) 
ema200 = ta.ema(close, 200)
 
// VWAP CALCULATION 
vwapValue = ta.vwap(hlc3)
 
// DISPLAY EMA TRAFFIC LIGHTS 
plot(ema50, title="50 EMA - Green", color=color.lime, linewidth=2) 
plot(ema100, title="100 EMA - Orange", color=color.orange, linewidth=2) 
plot(ema200, title="200 EMA - Red", color=color.red, linewidth=2)
 
// DISPLAY PURPLE VWAP 
plot(vwapValue, title="VWAP - Purple", color=color.purple, linewidth=2)
 
// EMA TREND CONDITIONS 
bullish = ema50 > ema100 and ema100 > ema200 
bearish = ema50 < ema100 and ema100 < ema200
 
// DYNAMIC COLOURS 
topColor = bullish ? color.lime : bearish ? color.red : color.gray 
bottomColor = bearish ? color.lime : bullish ? color.red : color.gray
 
// CREATE LIVE HORIZONTAL LINES 
var line topLine = line.new(bar_index, close, bar_index + 1, close, extend=extend.right, color=color.gray, width=3) 
var line bottomLine = line.new(bar_index, close, bar_index + 1, close, extend=extend.right, color=color.gray, width=3)
 
// UPDATE TOP LINE WITH LIVE PRICE 
line.set_xy1(topLine, bar_index, upperPrice) 
line.set_xy2(topLine, bar_index + 1, upperPrice) 
line.set_color(topLine, topColor)
 
// UPDATE BOTTOM LINE WITH LIVE PRICE 
line.set_xy1(bottomLine, bar_index, lowerPrice) 
line.set_xy2(bottomLine, bar_index + 1, lowerPrice) 
line.set_color(bottomLine, bottomColor)

← 返回列表