本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("NAS100 Pullback", overlay=true, max_labels_count=200)
risk = input.float(50, "Risk per trade ($)")
ptVal = input.float(1, "$ per point for 1 lot")
rr = input.float(2, "Target (x stop)")
sess = input.session("0945-1130", "Trading window (New York time)")
maxSig = input.int(3, "Max signals per day")
e20 = ta.ema(close, 20)
e50 = ta.ema(close, 50)
vw = ta.vwap(hlc3)
atr = ta.atr(14)
inWindow = not na(time(timeframe.period, sess, "America/New_York"))
var int count = 0
if timeframe.change("D")
count := 0
buy = barstate.isconfirmed and inWindow and count < maxSig and e20 > e50 and close > vw and low <= e20 and close > e20 and close > open
sell = barstate.isconfirmed and inWindow and count < maxSig and e20 < e50 and close < vw and high >= e20 and close < e20 and close < open
buyStop = ta.lowest(low, 5) - atr * 0.25
sellStop = ta.highest(high, 5) + atr * 0.25
if buy or sell
count += 1
stop = buy ? buyStop : sellStop
dist = math.abs(close - stop)
target = buy ? close + dist * rr : close - dist * rr
lots = risk / (dist * ptVal)
txt = (buy ? "BUY" : "SELL") + "\nStop " + str.tostring(stop, "#.0") + "\nTarget " + str.tostring(target, "#.0") + "\nLots " + str.tostring(lots, "#.00")
label.new(bar_index, buy ? low : high, txt, style=buy ? label.style_label_up : label.style_label_down, color=buy ? color.green : color.red, textcolor=color.white)
plot(e20, "EMA 20", color.aqua)
plot(e50, "EMA 50", color.orange)
plot(vw, "VWAP", color.white)
alertcondition(buy, "Buy signal", "NAS100 buy signal")
alertcondition(sell, "Sell signal", "NAS100 sell signal")