OPEN-SOURCE SCRIPT

VWAP 8:30 AM Backtest

149
// Pine Script for TradingView to Backtest Anchored VWAP on EUR/USD (5-min Chart)
//version=5
indicator("VWAP 8:30 AM Backtest", overlay=true)

// Define session time for 8:30 AM CST
startHour = 8
startMinute = 30
endHour = 12
endMinute = 30

// Get VWAP
vwapValue = ta.vwap

// Identify if price is below VWAP at 8:30 AM CST
is830CST = (hour == startHour and minute == startMinute)
belowVWAP_830 = is830CST ? close < vwapValue : na

// Track price for the next 4 hours
timeWithinRange = (hour * 60 + minute) >= (startHour * 60 + startMinute) and (hour * 60 + minute) <= (endHour * 60 + endMinute)
stayedBelow = timeWithinRange and close < vwapValue

// Count occurrences
var float countBelowVWAP = 0
var float totalOccurrences = 0
if is830CST
totalOccurrences := totalOccurrences + 1
if belowVWAP_830
countBelowVWAP := countBelowVWAP + 1

// Win rate calculation
winRate = totalOccurrences > 0 ? (countBelowVWAP / totalOccurrences) * 100 : 0

// Display results
plotshape(is830CST and belowVWAP_830, location=location.belowbar, color=color.red, title="Below VWAP at 8:30 AM CST")
plotshape(stayedBelow, location=location.abovebar, color=color.blue, title="Stayed Below VWAP 4hrs")
label = "Win Rate: " + str.tostring(winRate, "#.##") + "%"
label_position = close + 0.001
label.new(time, label_position, label, color=color.white, textcolor=color.black)

Declinazione di responsabilità

Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.