本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// =============================================================================
// WVPO VAH Break + Spring AVWAP at the VAH
//
// Purpose : Draws the VAH of your own range profile as a zone in ATR units and
// follows a break of that zone through the steps of setups 3a and
// 3b: the M5 close above the zone with volume against the
// time-of-day average (setup 3a), the daily close that confirms the
// break, the first pullback into the zone with its volume switch
// (setup 3b), and the lower edge of the zone as the one stop line of
// both. The distance of the Spring AVWAP to the VAH is shown, never
// tested.
// Reference : The Composite-Man Code, Volume II, chapter 22 (setups 3a and 3b,
// VAH breakout and BUEC): the two ten-field cards in 22.1, the
// consensus matrix in 22.2, the case studies in 22.4, the threshold
// box in 22.5, the traps and the five hallmarks of a genuine setup 3
// in 22.7. Zone rule from Volume I, chapter 12.5; volume threshold
// from Volume I, chapter 11.5; volume switch from Volume II,
// chapter 21.
// Licence : Mozilla Public License 2.0 - WVPO
//
// It gives no entries, no exits, no targets and no win rates.
//
// -----------------------------------------------------------------------------
// INPUTS AND DEFAULTS
// Nothing is set per instrument. The defaults are the starting values of the
// threshold box in 22.5; calibrate them over your own breaks.
// VAH, profile end ........... read off your own volume profile (inputs)
// ATR 20, Wilder ............. of the range timeframe, held at the profile end
// zone 0.3 x ATR ............. VAH +/- 0.3 x ATR(20)
// 3a trigger 1.8 x ........... volume against the time-of-day average of
// the ten sessions before
// confirmation 0.5 x ATR ..... daily close at or above VAH + 0.5 x ATR(20),
// following session above the zone
// first pullback ............. the first one after the confirmation (3b)
// volume switch 1.0 x ........ mean of the two M5 bars into the zone
// stop line .................. lower edge of the zone, on the tick grid
// Spring AVWAP at the VAH .... display only
// Not built in, because not checkable here: the closing distance of the
// micro-BOS (the micro-BOS is an entry) and the news blackout (Pine has no
// calendar).
//
// -----------------------------------------------------------------------------
// WHAT IT READS
// The VAH is not a line but a zone: VAH +/- 0.3 x ATR(20) of the range
// timeframe, Wilder's ATR read at the close of the last profile day - the
// day before the break - and then held, so the stop line does not wander
// with the market. Closes inside the zone are tests. Only an M5 close above
// its upper edge is a breakout. The first M5 close above the zone that trades
// at least 1.8 times the average volume of the same time of day over the ten
// sessions before meets the 3a trigger condition; it need not be the bar
// that crossed. Without that adjustment every 8:30 New York bar beats every
// bar of the night. A close that crosses above the zone without the volume
// gets a grey cross: a symptom of the trap, not a trigger.
//
// A break the market has accepted needs a daily close at least 0.5 x ATR(20)
// above the VAH and a following session whose low stays above the zone.
// Before that there is no 3b, even if price dips into the zone on the day of
// the break; a dip inside the breakout candle of the daily chart belongs to
// the break. After it the script reads the first pullback whose low reaches
// into the zone. The two M5 bars with which price runs into the zone set the
// volume switch: their mean at or below 1.0 x the time-of-day average allows
// mode A (a limit order at the upper edge of the zone), above it only mode B
// is left (the buy after the micro-BOS). The switch decides the mode, not the
// trade. The pullback is read to the end of the session in which it touched
// the zone; its low must stay above the lower edge.
//
// A low below the lower edge of the zone ends the reading. Before the
// confirmation it means the break has failed, during the first pullback that
// the pullback went too deep (trap 2), later that the stop line was hit. A
// daily close below the VAH ends it as well (trap 1). Only a daily close
// below the VAH re-arms the script for a new break of the same level: a new
// break needs price to come out of the value area again.
//
// The Spring AVWAP (without a spring: the SC AVWAP) is drawn and its distance
// to the VAH stated in ATR, at the trigger, at the low of the pullback and
// now. Inside the zone it is the convergence column of the matrix in 22.2, a
// question of size for 3a and a finding for the journal for 3b. It is never
// a condition: in none of the three real cases of the chapter did the line
// sit in the zone, and all three breaks ran.
//
// WHAT IT CANNOT CHECK
// - The range and its anchors. The profile runs from the selling climax (in
// a re-accumulation the automatic reaction) to the day before the break,
// on hourly bars with a 70 % value area. Pine cannot compute that profile
// cheaply, so the VAH and the profile end are inputs read off your own
// profile. A VAH typed in for one structure says nothing about another.
// - The phase: whether phase A is documented and the break is, or follows,
// the sign of strength. That is a reading of the range timeframe.
// - The consensus. It reads four windows together at the break bar and at
// the low of the pullback: footprint, delta, CVD and the heatmap of
// resting orders. No script sees that heatmap, so the consensus stays
// your judgement.
// - The news blackout. The script does not know the calendar. If a trigger
// falls inside a blackout (high impact 30 minutes before and after, medium
// 15 minutes), it counts only if the first bar after the blackout still
// closes above the zone. Check that yourself: the star marks the bar the
// rule describes, not a bar you were allowed to trade.
// - Card 3a, fields 2 and 3: whether the weekly AVWAP is not falling, and
// whether the Spring AVWAP rises below price. The script draws the Spring
// AVWAP and states its distance to the VAH; it does not test its slope.
// - The regime traffic light, the micro-BOS of mode B and every price you
// would trade at. The micro-BOS is an entry, and this script gives none.
// The table lists these as "not checked" instead of substituting something
// that looks similar.
//
// ON THE TIME-OF-DAY AVERAGE
// Bars are matched by clock time in the exchange time zone. A session is a
// TradingView daily bar. Where TradingView merges a holiday session into the
// next daily bar, the second part counts as a session of its own as soon as
// a clock time repeats, so the count follows exchange trading days as the
// book does. If a clock time is missing in some of the ten sessions, only
// the bars that exist count; with fewer than five the factor reads n/a.
// Symbols without volume read n/a throughout.
//
// ON TIMEFRAMES
// Chart: 5-minute bars, full electronic session. The thresholds describe M5
// bars against an M5 average; on another chart timeframe the script still
// runs, says so in the table, and its factors mean something else.
// Range timeframe: D (default) or H4. The zone and the confirmation distance
// use the ATR(20) of that timeframe. The confirmation itself always reads the
// daily close and the following session, as the book states it.
//
// -----------------------------------------------------------------------------
// WORKED EXAMPLE - the two cases of chapter 22.4, to reproduce on your own
// chart. Chart settings for both cases: 5-minute bars, electronic session,
// table time zone America/New_York (all times ET). The daily close must be the
// last trade, not the settlement: switch off "Use settlement as close on
// daily interval" in the chart settings, or the daily ATR can move outside
// the tolerance. The
// 5-minute history must reach back to the anchor (about 12,500 bars for NQ,
// 18,000 for SI) and ten sessions before the profile end; if the anchor is
// missing, the AVWAP row says so. In bar replay the same holds for the history
// before the replay start: if your plan loads fewer bars, open the chart at the
// case date before starting the replay.
//
// A) Setup 3a, topology A (direct markup) - NQ, 15 May 2024 (chapter 22.4).
// Symbol CME_MINI:NQM2024. Inputs: VAH 18370.75, profile end 14 May 2024
// 12:00 ET (any bar of that session before 17:00; a bar after 18:00 ET
// already belongs to the session of 15 May), range timeframe D, Spring
// AVWAP anchor on the 5-minute bar of the selling climax low, 19 Apr 2024
// 15:45 ET (low 17113.25; this structure has no spring).
// a) ATR(20) D at the profile end 269.8164. Zone 18289.81 to 18451.69,
// confirmation level 18505.66, stop line 18289.75.
// b) Nothing is marked before 15 May 08:30. The highest close since the
// profile end is 18431.50, inside the zone; the first close above the
// VAH, 14 May 14:10 at 18375.75 (2.18x), lies before the profile end
// and inside the zone too. A test, not a break.
// c) 15 May 08:30: label "★ 3a 2.88×". Close 18518.00, volume
// 15490 against a time-of-day average of 5382.3 (10 values). This is
// the CPI bar inside the blackout 08:00-09:00; the script must mark it
// anyway, because it cannot know the calendar. The bars after it stay
// above the zone; the 09:00 bar closes at 18499.50, the entry of the
// chapter.
// d) Spring (SC) AVWAP at the trigger 17825.77 = -2.02 ATR to the VAH:
// outside the zone, no convergence. At the entry bar (the 09:00 bar,
// filled at its close at 09:05) it stands at 17828.54 = -2.01 ATR,
// the value in 22.5.
// e) "confirmed +1.20 ATR" on the first bar of the 17 May session
// (16 May 18:00): daily close 15 May 18694.50, low 16 May 18633.25
// above the zone.
// f) First pullback 31 May 10:20 (low 18415.00). Volume switch 10:15
// 2.26x and 10:20 2.67x, mean 2.47: label "3b pullback · mode B only".
// At 12:00 the low 18288.00 falls below the lower edge: label "too
// deep", state "ended: first pullback too deep (trap 2)". The pullback
// low, 18241.25 at 12:20, reads -0.48 ATR. The daily close 18570.75
// stays above the VAH, so the script does not re-arm, and at the end
// of the contract the table still shows this episode.
//
// B) Setup 3b, pullback held - SI, 3 Feb 2025 (chapter 22.4, silver).
// Symbol COMEX:SIH2025. Inputs: VAH 31.530, profile end 29 Jan 2025
// 12:00 ET (a click after 18:00 ET lies in the session of 30 Jan), range
// timeframe D, anchor on the selling climax bar 19 Dec 2024 10:35 ET
// (low 29.145).
// a) ATR(20) D 0.8066. Zone 31.288 to 31.772, confirmation level 31.933,
// stop line 31.285.
// b) 30 Jan 02:10: label "★ 3a 9.07×" (682 against 75.2). Spring AVWAP
// 30.695 = -1.03 ATR (-1.0348, so -1.04 is still within tolerance).
// c) "confirmed +1.54 ATR" on the first bar after 31 Jan, Sunday 2 Feb
// 18:00: close 30 Jan 32.770, low 31 Jan 32.115.
// d) First pullback Sunday 2 Feb 21:05 (low 31.755). Switch 21:00 7.04x
// and 21:05 3.93x, mean 5.49: mode B only.
// e) Pullback low 31.610 at 21:40 = +0.10 ATR, 0.322 above the lower
// edge. "held +0.10 ATR" appears at that low when the session has
// ended (3 Feb 18:00); Spring AVWAP at the low 30.878 = -0.81 ATR.
// f) Later events belong to the mechanics, not to the example: on 28 Feb
// 03:15 the low 31.280 falls below the lower edge ("stop line"), the
// day closes below the VAH (31.430), and the script re-arms. After the
// roll the contract is a back month: a new close above the zone on
// 3 Mar 06:55 shows a grey cross (volume short), and a confirmation
// follows on 5 Mar. That is the old VAH applied to a new market, which
// is why the profile end and the VAH are yours to move. Read the table
// of this case in bar replay on 4 Feb 2025, or hover the labels.
//
// Tolerance: feeds get revised. ATR within 0.3 points (NQ) or 0.001 (SI),
// zone edges accordingly, volume factors within 0.05, AVWAP within 0.5
// points (NQ) or 0.005 (SI). A value far outside means a different
// contract, session or time zone, not rounding.
//
// On the ATR: ta.atr is Wilder's ATR over the whole history of the contract.
// A daily series that starts later (for example on 1 Jan 2024) has not yet
// converged by May and gives a slightly higher value for the NQ case.
// =============================================================================
indicator(title = "WVPO VAH Break + Spring AVWAP at the VAH", shorttitle = "WVPO VAH",
overlay = true, max_bars_back = 1000, max_labels_count = 200)
// ---------------------------------------------------- the range, from your profile
gL = "Range (from your own profile)"
vah = input.price(0.0, "VAH of the range", group = gL, confirm = true,
tooltip = "The VAH of your own volume profile, from the selling climax (re-accumulation: automatic reaction) to the day before the break, hourly bars, value area 70 % (Volume II, 22.1). Pine cannot compute that profile cheaply, and a guess dressed up as a measurement would be worse than an input field.")
profEnd = input.time(timestamp("2024-05-14T16:00:00+00:00"), "Profile end (the day before the break)", group = gL, confirm = true,
tooltip = "Any bar of the last session in your profile (for CME futures a bar before the 17:00 ET close; a bar after the evening reopen already belongs to the next session). The VAH applies from the next session on, and the zone takes the ATR at the close of this session and keeps it. When your profile moves, move this date and the VAH with it.")
rangeTf = input.timeframe("D", "Range timeframe", group = gL, options = ["D", "240"],
tooltip = "The zone and the confirmation distance use the ATR(20) of the range timeframe, D1 or H4 (card 3a, field 2, Volume II 22.1). The confirmation always reads the daily close and the following session.")
// ------------------------------------------------------------ the thresholds
gT = "Thresholds (starting values, Volume II 22.5)"
atrLen = input.int(20, "ATR length (Wilder)", minval = 1, group = gT,
tooltip = "ATR(20) after Wilder (ta.atr), the unit of the zone and of the confirmation distance (Volume II, 22.5).")
zoneMult = input.float(0.3, "Zone half-width (x ATR)", minval = 0.0, step = 0.05, group = gT,
tooltip = "VAH +/- 0.3 x ATR(20) of the range timeframe (Volume I, chapter 12.5). The lower edge is the stop line, one stop rule for 3a and 3b.")
confMult = input.float(0.5, "Confirmation distance (x ATR)", minval = 0.0, step = 0.05, group = gT,
tooltip = "The break is confirmed by a daily close at or above VAH + 0.5 x ATR(20) and a following session that stays above the zone (Volume II, 22.5).")
volMult = input.float(1.8, "3a trigger: volume (x time-of-day average)", minval = 0.1, step = 0.1, group = gT,
tooltip = "M5 close above the zone on at least 1.8 x the volume of the same time of day over the ten sessions before (Volume I, chapter 11.5). One value for every instrument.")
swMult = input.float(1.0, "3b volume switch: mode A up to (x)", minval = 0.1, step = 0.1, group = gT,
tooltip = "Mean of the two M5 bars into the zone at or below 1.0 x their time-of-day average allows mode A, above it mode B only (Volume II, chapter 21). A switch, not a filter.")
todSess = input.int(10, "Time-of-day average: sessions", minval = 2, maxval = 60, group = gT,
tooltip = "The ten sessions before the bar, as for the 3a trigger.")
todMin = input.int(5, "Time-of-day average: minimum values", minval = 1, maxval = 60, group = gT,
tooltip = "With fewer values the factor reads n/a.")
// ----------------------------------------------------------------- the anchor
gA = "Spring AVWAP (display only)"
spTs = input.time(timestamp("2024-04-19T19:45:00+00:00"), "Anchor: spring low (no spring: selling climax)", group = gA, confirm = true,
tooltip = "The line inside the VAH zone is the convergence column for the size of 3a (Volume II, 22.2), never a condition. Click the bar of the low.")
src = input.source(hlc3, "Source", group = gA,
tooltip = "HLC3, as in the figures published in Volume I, chapter 12, and Volume II, chapter 22.")
spCol = input.color(color.rgb(27, 94, 32), "Colour", group = gA)
// -------------------------------------------------------------------- display
gD = "Display"
showTable = input.bool(true, "Show table", group = gD)
showMarks = input.bool(true, "Mark events", group = gD)
showLabels = input.bool(true, "Label events with their figures", group = gD,
tooltip = "Labels carry the measured values and a tooltip. Off: plain markers.")
tblPos = input.string("top_right", "Table position", group = gD,
options = ["top_right", "top_left", "bottom_right", "bottom_left"])
tblTz = input.string("America/New_York", "Time zone for table and labels", group = gD,
tooltip = "The book gives every time in New York time (ET). The exchange time zone of CME symbols is Chicago.")
// -------------------------------------------------- journal webhook, optional
gJ = "Journal webhook (optional)"
whSecret = input.string("", "Webhook secret", group = gJ,
tooltip = "Leave empty to keep alerts as plain text. Filled in, the trigger alert sends the JSON payload of the WVPO journal with setup_typ 3a, the pullback alert with 3b.")
whEntry = input.price(0.0, "Entry (your plan)", group = gJ)
whStop = input.price(0.0, "Stop (your plan)", group = gJ)
whTarget = input.price(0.0, "Target (your plan)", group = gJ)
// =============================================================================
// Time of day. One slot per clock time in exchange time, holding the volumes
// and session numbers of the bars seen at that time. A value enters only when
// its bar has closed, and the current bar is measured before it is stored.
// =============================================================================
type TodSlot
array<float> vols
array<int> sess
var map<int, TodSlot> todMap = map.new<int, TodSlot>()
var int sessNo = 0
newDay = timeframe.change("D")
todKey = hour(time, syminfo.timezone) * 60 + minute(time, syminfo.timezone)
TodSlot slot = na
if todMap.contains(todKey)
slot := todMap.get(todKey)
// A new daily bar starts a session. So does a clock time seen twice in one
// daily bar: that is a holiday session TradingView has merged into the next day.
if newDay and bar_index > 0
sessNo += 1
else if not na(slot)
if slot.sess.size() > 0
if slot.sess.last() == sessNo
sessNo += 1
f_todSum(TodSlot s, int cur) =>
float sum = 0.0
int n = 0
if not na(s)
for [i, sid] in s.sess
if sid >= cur - todSess and sid < cur
sum += s.vols.get(i)
n += 1
[n, sum]
[todN, todSum] = f_todSum(slot, sessNo)
todAvg = todN >= todMin and todSum > 0 ? todSum / todN : na
volX = na(volume) or na(todAvg) ? na : volume / todAvg
if barstate.isconfirmed and not na(volume)
if na(slot)
slot := TodSlot.new(array.new<float>(), array.new<int>())
todMap.put(todKey, slot)
slot.vols.push(volume)
slot.sess.push(sessNo)
while slot.sess.size() > 0 and slot.sess.first() < sessNo - todSess
slot.sess.shift()
slot.vols.shift()
// =============================================================================
// ATR(20) of the range timeframe, taken only from completed range bars.
// On historical bars the request already hands over the last completed bar
// (its open time lies before the open of the current range bar). On realtime
// bars it hands over the developing bar; then the value the previous chart bar
// left behind at its close is the completed one. No lookahead in either case.
// =============================================================================
[atrReq, tReq] = request.security(syminfo.tickerid, rangeTf, [ta.atr(atrLen), time], lookahead = barmerge.lookahead_off)
rangeOpen = time(rangeTf)
rangeNew = timeframe.change(rangeTf)
var float atrDone = na
if not na(tReq) and not na(rangeOpen) and tReq < rangeOpen
atrDone := atrReq
else if rangeNew and not na(atrReq[1])
atrDone := atrReq[1]
// =============================================================================
// Profile end, activation and the fixed zone
// =============================================================================
var int firstTime = na
if bar_index == 0
firstTime := time
dayOpen = time("D")
var int endDay = na
if time <= profEnd
endDay := dayOpen
vahSet = vah > 0
profLoaded = not na(firstTime) and profEnd >= firstTime
active = vahSet and not na(endDay) and dayOpen > endDay
activeStart = active and not active[1]
var float atrZ = na
if activeStart
atrZ := atrDone
zoneOk = active and not na(atrZ)
zTop = zoneOk ? vah + zoneMult * atrZ : na
zBot = zoneOk ? vah - zoneMult * atrZ : na
zConf = zoneOk ? vah + confMult * atrZ : na
// Card field 6: the lower edge, rounded down to the tick grid.
stopLine = zoneOk ? math.floor(zBot / syminfo.mintick + 1e-6) * syminfo.mintick : na
// =============================================================================
// Spring AVWAP, accumulated by hand so that a symbol without volume degrades to
// an empty line and an n/a row rather than answering a different question.
// =============================================================================
anchorLoaded = not na(firstTime) and spTs >= firstTime
var float pv = 0.0
var float vv = 0.0
if anchorLoaded and time >= spTs and not na(volume)
pv += src * volume
vv += volume
vSpring = anchorLoaded and vv > 0 ? pv / vv : na
gapAtr = zoneOk and not na(vSpring) ? (vSpring - vah) / atrZ : na
conv = not na(gapAtr) and math.abs(gapAtr) <= zoneMult
// =============================================================================
// The session that has just ended, read on the first bar of the next one.
// =============================================================================
var float runLow = na
var float runClose = na
float doneLow = na
float doneClose = na
bool dayDone = false
if newDay
if not na(runClose)
doneLow := runLow
doneClose := runClose
dayDone := true
runLow := low
else
runLow := na(runLow) ? low : math.min(runLow, low)
runClose := close
doneWasActive = active[1]
aboveZ = zoneOk and close > zTop
crossUp = aboveZ and close[1] <= zTop
// =============================================================================
// The episode: break, 3a trigger, confirmation, first pullback, end.
// st 0 = waiting for a close above the zone, 1 = break live,
// st 2 = ended, waiting for a daily close below the VAH before it re-arms.
// =============================================================================
var int st = 0
var string endWhy = ""
var int brkBar = na
var int brkTime = na
var bool trig = false
var int trgTime = na
var float trgX = na
var float trgClose = na
var float trgGap = na
var float lastX = na
var bool cand = false
var float candClose = na
var int candTime = na
var bool conf = false
var float confAtr = na
var bool pb = false
var bool pbOpen = false
var bool pbDeep = false
var bool pbHeld = false
var int pbTime = na
var float pbX1 = na
var float pbX2 = na
var float pbSwitch = na
var float pbLow = na
var int pbLowBar = na
var float pbGap = na
bool evNoVol = false
bool evTrigger = false
bool evConfirm = false
bool evPull = false
bool evHeld = false
bool evBelowZ = false
bool evDayBelow = false
if barstate.isconfirmed and zoneOk
// ---- the session that has just ended
if dayDone and doneWasActive
dayBelow = doneClose < vah
if pbOpen
pbOpen := false
if st == 1 and not pbDeep and not dayBelow
pbHeld := true
evHeld := true
if st == 1
if dayBelow
st := 0
endWhy := "daily close below the VAH (trap 1)"
evDayBelow := true
else if not conf
if cand
if doneLow > zTop
conf := true
confAtr := (candClose - vah) / atrZ
evConfirm := true
else
cand := false
if not conf and doneClose >= zConf
cand := true
candClose := doneClose
candTime := time[1]
else if st == 2 and dayBelow
st := 0
evDayBelow := true
// ---- this bar
if st == 0 and aboveZ
st := 1
endWhy := ""
brkBar := bar_index
brkTime := time
trig := false
trgTime := na
trgX := na
trgClose := na
trgGap := na
lastX := na
cand := false
candClose := na
candTime := na
conf := false
confAtr := na
pb := false
pbOpen := false
pbDeep := false
pbHeld := false
pbTime := na
pbX1 := na
pbX2 := na
pbSwitch := na
pbLow := na
pbLowBar := na
pbGap := na
if st == 1
// 3a: the first M5 close above the zone with the volume, before the
// confirmation (card 3a, field 4). Only the crossing close without the
// volume is marked; later closes above the zone wait silently.
if aboveZ and not conf and not trig
if not na(volX) and volX >= volMult
trig := true
trgTime := time
trgX := volX
trgClose := close
trgGap := gapAtr
evTrigger := true
else if crossUp
lastX := volX
evNoVol := true
// 3b: the first pullback after the confirmation whose low reaches the zone.
if conf and not pb and low <= zTop
pb := true
pbOpen := true
pbTime := time
pbX1 := volX[1]
pbX2 := volX
pbSwitch := na(pbX1) or na(pbX2) ? na : (pbX1 + pbX2) / 2
pbLow := low
pbLowBar := bar_index
pbGap := gapAtr
evPull := true
else if pbOpen and low < pbLow
pbLow := low
pbLowBar := bar_index
pbGap := gapAtr
// Through the whole zone: the edge has not become a floor.
if bar_index > brkBar and low < zBot
st := 2
evBelowZ := true
if pbOpen
pbDeep := true
endWhy := "first pullback too deep (trap 2)"
else if not conf
endWhy := "fell back through the zone"
else
endWhy := "low below the lower zone edge (stop line)"
else if st == 2 and pbOpen and low < pbLow
// a pullback that went too deep is still read to the end of its session
pbLow := low
pbLowBar := bar_index
pbGap := gapAtr
pbLowAtr = na(pbLow) or na(atrZ) ? na : (pbLow - vah) / atrZ
// =============================================================================
// Formatting
// =============================================================================
priceDec = math.max(2, math.ceil(-math.log10(syminfo.mintick)))
f_z(float x) => na(x) ? "n/a" : str.tostring(math.round(x, priceDec))
f_p(float x) => na(x) ? "n/a" : str.tostring(x, format.mintick)
f_x(float x) => na(x) ? "n/a" : str.tostring(x, "0.00") + "×"
f_a(float x) => na(x) ? "n/a" : (x >= 0 ? "+" : "") + str.tostring(x, "0.00") + " ATR"
f_t(int ts) => na(ts) ? "n/a" : str.format_time(ts, "yyyy-MM-dd HH:mm", tblTz)
f_d(int ts) => na(ts) ? "n/a" : str.format_time(ts, "yyyy-MM-dd", tblTz)
f_mode(float x) => na(x) ? "n/a" : x <= swMult ? "mode A allowed" : "mode B only"
colOk = color.rgb(27, 94, 32)
colNo = color.rgb(183, 28, 28)
colMid = color.rgb(120, 120, 120)
colGold = color.rgb(212, 160, 23)
colZone = color.rgb(21, 101, 192)
// =============================================================================
// Plots
// =============================================================================
plot(active ? vah : na, "VAH", color = colZone, linewidth = 1, style = plot.style_linebr)
pTop = plot(zTop, "Zone upper edge", color = color.new(colZone, 50), linewidth = 1, style = plot.style_linebr)
pBot = plot(zBot, "Zone lower edge", color = color.new(colZone, 50), linewidth = 1, style = plot.style_linebr)
fill(pTop, pBot, color = color.new(colZone, 90), title = "VAH zone")
plot(zConf, "Confirmation level (VAH + 0.5 ATR)", color = color.new(colOk, 40), linewidth = 1, style = plot.style_circles)
plot(stopLine, "Stop line (lower zone edge, tick grid)", color = color.new(colNo, 30), linewidth = 1, style = plot.style_linebr)
plot(vSpring, "Spring AVWAP", color = spCol, linewidth = 2)
// Markers. With labels switched on, the labels carry the events and their
// figures; the grey cross for a close without the volume always shows.
markOn = showMarks and not showLabels
plotchar(markOn and evTrigger, "3a trigger condition", "★", location.abovebar, colGold, size = size.small)
plotshape(showMarks and evNoVol, "Close above the zone, volume short", style = shape.xcross,
location = location.abovebar, color = colMid, size = size.tiny)
plotshape(markOn and evConfirm, "Break confirmed", style = shape.flag,
location = location.abovebar, color = colOk, size = size.tiny)
plotshape(markOn and evPull, "First pullback into the zone", style = shape.triangleup,
location = location.belowbar, color = colOk, size = size.tiny)
plotshape(markOn and evBelowZ, "Below the lower zone edge", style = shape.xcross,
location = location.belowbar, color = colNo, size = size.tiny)
plotshape(markOn and evDayBelow, "Daily close below the VAH", style = shape.xcross,
location = location.belowbar, color = colNo, size = size.tiny)
f_lbl(int x, float y, bool above, string txt, string tip, color c) =>
label.new(x, y, txt, xloc = xloc.bar_index, yloc = above ? yloc.abovebar : yloc.belowbar,
style = above ? label.style_label_down : label.style_label_up, color = color.new(c, 80),
textcolor = c, size = size.small, tooltip = tip)
if showLabels and evTrigger
f_lbl(bar_index, high, true, "★ 3a " + f_x(trgX),
"3a trigger condition: close " + f_p(trgClose) + " above the zone, volume " + f_x(trgX) +
" of the time-of-day average (" + str.tostring(todN) + " values). Spring AVWAP " + f_a(trgGap) +
" to the VAH. Not checked: news blackout, consensus, range.", colGold)
if showLabels and evConfirm
f_lbl(bar_index, high, true, "confirmed " + f_a(confAtr),
"Daily close " + f_d(candTime) + " " + f_p(candClose) + " at or above VAH + " + str.tostring(confMult) +
" ATR, and the following session stayed above the zone.", colOk)
if showLabels and evPull
f_lbl(bar_index, low, false, "3b pullback · " + f_mode(pbSwitch),
"First pullback into the zone after the confirmation. Volume switch: " + f_x(pbX1) + " and " + f_x(pbX2) +
" of the time-of-day average, mean " + f_x(pbSwitch) + ".", colMid)
if showLabels and evHeld
f_lbl(pbLowBar, pbLow, false, "held " + f_a(pbLowAtr),
"The first pullback held in the zone: low " + f_p(pbLow) + ", " + f_a(pbLowAtr) +
" to the VAH. Spring AVWAP at the low " + f_a(pbGap) + ". Consensus and micro-BOS not checked.", colOk)
if showLabels and evBelowZ
f_lbl(bar_index, low, false, endWhy == "first pullback too deep (trap 2)" ? "too deep" :
endWhy == "fell back through the zone" ? "fell back" : "stop line",
"Low " + f_p(low) + " below the lower zone edge " + f_z(zBot) + ": " + endWhy + ".", colNo)
if showLabels and evDayBelow
f_lbl(bar_index, low, false, "close < VAH",
"The daily close " + f_p(doneClose) + " lies below the VAH. The script re-arms for a new break.", colNo)
// =============================================================================
// Table
// =============================================================================
f_pos() =>
tblPos == "top_left" ? position.top_left : tblPos == "bottom_right" ? position.bottom_right :
tblPos == "bottom_left" ? position.bottom_left : position.top_right
var table t = table.new(f_pos(), 2, 13, border_width = 1)
// "label" would shadow the built-in type of the same name, hence "caption".
f_row(int r, string caption, string value, color vc, string tip = "") =>
bg = color.new(color.gray, 90)
table.cell(t, 0, r, caption, text_size = size.small, text_halign = text.align_left, bgcolor = bg, text_color = color.new(color.gray, 0), tooltip = tip)
table.cell(t, 1, r, value, text_size = size.small, text_halign = text.align_right, bgcolor = bg, text_color = vc, tooltip = tip)
isM5 = timeframe.isminutes and timeframe.multiplier == 5
stage = not vahSet ? "VAH not set" :
not profLoaded ? "profile end before the loaded history" :
not active ? "waiting for the profile end" :
na(atrZ) ? "ATR not available" :
st == 2 ? "ended: " + endWhy :
st == 0 ? (endWhy == "" ? "waiting for a close above the zone" : "re-armed · last: " + endWhy) :
pbOpen ? "first pullback in progress" :
pbHeld ? "first pullback held in the zone" :
conf ? "confirmed · waiting for the first pullback" :
cand ? "daily close confirms · next session open" :
trig ? "3a trigger seen · not yet confirmed" : "above the zone · trigger volume missing"
stageCol = st == 2 ? colNo : pbHeld or conf ? colOk : trig ? colGold : colMid
if showTable and barstate.islast
txt = color.new(color.gray, 0)
hdr = color.new(color.gray, 80)
table.cell(t, 0, 0, "WVPO VAH break · 3a/3b", text_size = size.small, text_halign = text.align_left, bgcolor = hdr, text_color = txt)
table.cell(t, 1, 0, stage + (isM5 ? "" : " · chart is not M5"), text_size = size.small, text_halign = text.align_right, bgcolor = hdr, text_color = stageCol)
f_row(1, "VAH zone", zoneOk ? f_z(zBot) + " – " + f_z(zTop) : vahSet ? "n/a" : "VAH not set", txt,
"VAH " + f_p(vah) + " +/- " + str.tostring(zoneMult) + " x ATR(" + str.tostring(atrLen) + ") " + rangeTf + ". Closes inside the zone are tests.")
f_row(2, "ATR(" + str.tostring(atrLen) + ") " + rangeTf + " · profile end",
na(atrZ) ? "n/a" : str.tostring(atrZ, "0.0000") + " · " + f_d(profEnd), txt)
f_row(3, "Close above the zone", na(brkTime) ? "none since the profile end" : f_t(brkTime), na(brkTime) ? colMid : txt)
f_row(4, "3a volume (time of day)", trig ? f_t(trgTime) + " · " + f_x(trgX) :
na(brkTime) ? "n/a" : "short: " + f_x(lastX) + " (needs " + str.tostring(volMult, "0.0") + "×)",
trig ? colGold : na(brkTime) ? colMid : colNo,
"Volume of the bar against the same time of day over " + str.tostring(todSess) + " sessions; the 3a condition needs " + str.tostring(volMult, "0.0") + "x.")
f_row(5, "News blackout", "not known to the script", colMid,
"If the trigger fell inside a blackout (high impact 30 minutes before and after, medium 15), it counts only if the first bar after the blackout still closes above the zone. Check the calendar yourself.")
f_row(6, "Confirmation", conf ? f_d(candTime) + " close " + f_a(confAtr) + " · next session held" :
cand ? f_d(candTime) + " close " + f_a((candClose - vah) / atrZ) + " · next session open" :
zoneOk ? "needs a daily close ≥ " + f_z(zConf) : "n/a", conf ? colOk : colMid,
"Daily close at or above VAH + " + str.tostring(confMult) + " ATR, then a following session whose low stays above the zone. Before that there is no 3b.")
f_row(7, "First pullback (3b)", pb ? f_t(pbTime) + " · low " + f_a(pbLowAtr) + " · " +
(pbDeep ? "too deep" : pbHeld ? "held" : pbOpen ? "in progress" : "day closed below the VAH") :
conf ? "none yet" : "only after the confirmation", pbHeld ? colOk : pbDeep ? colNo : colMid)
f_row(8, "Volume switch", pb ? "mean " + f_x(pbSwitch) + " · " + f_mode(pbSwitch) : "n/a", colMid,
pb ? "The two M5 bars into the zone: " + f_x(pbX1) + " and " + f_x(pbX2) + " of their time-of-day average. The switch decides the mode, not the trade." : "")
f_row(9, "Spring AVWAP to VAH", na(gapAtr) ? (anchorLoaded ? "n/a" : "anchor before the loaded history") :
f_a(gapAtr) + (conv ? " · in the zone" : " · outside") + (na(trgGap) ? "" : " · trigger " + f_a(trgGap)),
conv ? colOk : colMid,
"Display only. Inside the zone it is the convergence column for the size of 3a (22.2), for 3b a finding for the journal." + (na(pbGap) ? "" : " At the low of the pullback: " + f_a(pbGap) + "."))
f_row(10, "Stop line (lower zone edge)", f_p(stopLine), zoneOk ? colNo : colMid,
"VAH - " + str.tostring(zoneMult) + " x ATR, rounded down to the tick grid. One stop rule for 3a and 3b.")
f_row(11, "Volume now", f_x(volX) + " of time of day (" + str.tostring(todN) + " values)", txt)
f_row(12, "not checked", "range · phase · consensus · news", color.new(color.gray, 30),
"Range and anchors, phase A and the sign of strength, the four-window consensus, the news blackout, the regime light and the micro-BOS of mode B are not in this script.")
// =============================================================================
// Alerts, all on bar close. Nothing repaints: the levels are inputs, the ATR
// comes from completed range bars, every reading is taken from closed bars,
// and a verdict about a session is made on the first bar after it.
// =============================================================================
alertcondition(evTrigger, "3a trigger condition", "WVPO: M5 close above the VAH zone with volume at or above the time-of-day threshold. Not checked: news blackout, consensus, range.")
alertcondition(evNoVol, "Close above the zone, volume short", "WVPO: M5 close above the VAH zone without the volume")
alertcondition(evConfirm, "Break confirmed", "WVPO: daily close >= VAH + 0.5 ATR and the following session held above the zone")
alertcondition(evPull, "First pullback into the zone", "WVPO: first pullback into the VAH zone after the confirmation")
alertcondition(evBelowZ, "Below the lower zone edge", "WVPO: low below the lower edge of the VAH zone")
alertcondition(evDayBelow, "Daily close below the VAH", "WVPO: daily close below the VAH")
f_plain(string what) =>
what + " | " + syminfo.ticker + " | zone " + f_z(zBot) + "-" + f_z(zTop) +
" | volume " + f_x(volX) + " of time of day | Spring AVWAP " + f_a(gapAtr)
f_json(string setupTyp) =>
e = na(whEntry) ? 0.0 : whEntry
s = na(whStop) ? 0.0 : whStop
tg = na(whTarget) ? 0.0 : whTarget
'{"secret":"' + whSecret +
'","instrument":"' + syminfo.ticker +
'","richtung":"long","entry":' + str.tostring(e) +
',"stop":' + str.tostring(s) +
',"target":' + str.tostring(tg) +
',"setup_typ":"' + setupTyp +
'","ts":"' + str.format_time(time, "yyyy-MM-dd'T'HH:mm:ss'Z'", "UTC") + '"}'
useJson = str.length(whSecret) > 0
if barstate.isconfirmed and evTrigger
alert(useJson ? f_json("3a") : f_plain("WVPO 3a trigger condition: close above the VAH zone with volume (news blackout not checked)"), alert.freq_once_per_bar_close)
if barstate.isconfirmed and evNoVol
alert(f_plain("WVPO close above the VAH zone WITHOUT the volume"), alert.freq_once_per_bar_close)
if barstate.isconfirmed and evConfirm
alert(f_plain("WVPO daily close ≥ VAH + 0.5 ATR and the following session held above the zone"), alert.freq_once_per_bar_close)
if barstate.isconfirmed and evPull
alert(useJson ? f_json("3b") : f_plain("WVPO first pullback into the VAH zone, volume switch: " + f_mode(pbSwitch)), alert.freq_once_per_bar_close)
if barstate.isconfirmed and evBelowZ
alert(f_plain("WVPO low below the lower zone edge: " + endWhy), alert.freq_once_per_bar_close)
if barstate.isconfirmed and evDayBelow
alert(f_plain("WVPO daily close below the VAH"), alert.freq_once_per_bar_close)