本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator(
"UK BoE Policy Pressure - GB02Y vs Bank Rate",
shorttitle="BoE Policy Pressure",
overlay=false,
max_labels_count=500,
max_bars_back=1500)
//=====================================================================
// 1. INPUTS
//=====================================================================
yieldSymbol = input.symbol(
"TVC:GB02Y",
"UK 2-Year Government Bond Yield",
group="Data")
boeSymbol = input.symbol(
"ECONOMICS:GBINTR",
"Bank of England Bank Rate",
group="Data")
startYear = input.int(
2000,
"Historical test start year",
minval=1980,
maxval=2035,
group="Historical Test")
resetBandBp = input.int(
15,
"Episode reset distance (bp)",
minval=5,
maxval=40,
step=5,
group="Historical Test")
spreadEmaLen = input.int(
20,
"Spread persistence EMA",
minval=2,
group="Signal")
zLookback = input.int(
252,
"Z-score lookback",
minval=60,
group="Signal")
signalThresholdBp = input.int(
50,
"Minimum gap for live signal (bp)",
options=[25, 50, 75, 100],
group="Signal")
zThreshold = input.float(
1.0,
"Minimum absolute Z-score",
minval=0.0,
step=0.1,
group="Signal")
persistenceDays = input.int(
10,
"Required persistence (trading days)",
minval=1,
maxval=60,
group="Signal")
//---------------------------------------------------------------------
// DISPLAY
//---------------------------------------------------------------------
showMainRates = input.bool(
true,
"Show GB02Y + BoE on top chart",
group="Display")
showMainDashboard = input.bool(
true,
"Show Policy Pressure table on TOP chart",
group="Display")
showHowToRead = input.bool(
false,
"Show How To Read / Cheat Sheet",
group="Display")
showSpreadEMA = input.bool(
true,
"Show 20-day spread average",
group="Display")
showThresholds = input.bool(
true,
"Show +/-50 and +/-100bp levels",
group="Display")
showActualMoves = input.bool(
true,
"Show actual BoE hikes/cuts",
group="Display")
showSignals = input.bool(
true,
"Show UP/DOWN pressure signals",
group="Display")
//=====================================================================
// 2. COLOUR PALETTE
//=====================================================================
// Structural colours
headerBg = color.rgb(27, 48, 66)
sectionBg = color.rgb(33, 75, 105)
neutralBg = color.rgb(55, 55, 55)
neutralSoft = color.rgb(72, 72, 72)
// Upward / hike pressure
upSoft = color.rgb(145, 62, 62)
upStrong = color.rgb(110, 24, 24)
// Downward / cut pressure
downSoft = color.rgb(45, 105, 65)
downStrong = color.rgb(17, 82, 38)
// Caution
amberBg = color.rgb(150, 108, 32)
amberStrong = color.rgb(120, 78, 18)
textCol = color.white
//=====================================================================
// 3. DAILY DATA
//=====================================================================
gb02y = request.security(
yieldSymbol,
"D",
close,
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_off)
boe = request.security(
boeSymbol,
"D",
close,
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_off)
//=====================================================================
// 4. RAW RATE LINES ON TOP PRICE CHART
//=====================================================================
plot(
showMainRates ? gb02y : na,
title="UK 2Y Gilt Yield",
color=color.orange,
linewidth=2,
force_overlay=true)
plot(
showMainRates ? boe : na,
title="BoE Bank Rate",
color=color.black,
linewidth=2,
style=plot.style_stepline,
force_overlay=true)
//=====================================================================
// 5. CORE POLICY GAP
//
// Positive:
// GB02Y > BoE Bank Rate
//
// Negative:
// GB02Y < BoE Bank Rate
//=====================================================================
spread = gb02y - boe
spreadEMA = ta.ema(
spread,
spreadEmaLen)
//=====================================================================
// 6. Z-SCORE
//
// Measures how unusual the CURRENT gap is relative to the
// previous approximately one trading year.
//=====================================================================
spreadMean = ta.sma(
spread,
zLookback)
spreadSD = ta.stdev(
spread,
zLookback)
float zScore = na
if not na(spreadSD) and spreadSD > 0
zScore := (
spread - spreadMean
) / spreadSD
//=====================================================================
// 7. ACTUAL BOE MOVES
//=====================================================================
rateChange = boe - boe[1]
actualHike =
rateChange > 0
actualCut =
rateChange < 0
inSample =
year >= startYear
//=====================================================================
// 8. HISTORICAL EPISODE LOGIC
//
// We retain two meaningful gap regimes:
//
// +/-50bp
// +/-100bp
//
// Hysteresis stops repeated threshold wiggles being counted as
// multiple independent episodes.
//=====================================================================
resetBand =
resetBandBp / 100.0
var bool up50Armed = true
var bool up100Armed = true
var bool dn50Armed = true
var bool dn100Armed = true
//---------------------------------------------------------------------
// REARM POSITIVE
//---------------------------------------------------------------------
if spread <= 0.50 - resetBand
up50Armed := true
if spread <= 1.00 - resetBand
up100Armed := true
//---------------------------------------------------------------------
// REARM NEGATIVE
//---------------------------------------------------------------------
if spread >= -0.50 + resetBand
dn50Armed := true
if spread >= -1.00 + resetBand
dn100Armed := true
//---------------------------------------------------------------------
// +50BP EPISODE
//---------------------------------------------------------------------
up50Episode =
inSample and
up50Armed and
spread >= 0.50
if up50Episode
up50Armed := false
//---------------------------------------------------------------------
// +100BP EPISODE
//---------------------------------------------------------------------
up100Episode =
inSample and
up100Armed and
spread >= 1.00
if up100Episode
up100Armed := false
//---------------------------------------------------------------------
// -50BP EPISODE
//---------------------------------------------------------------------
dn50Episode =
inSample and
dn50Armed and
spread <= -0.50
if dn50Episode
dn50Armed := false
//---------------------------------------------------------------------
// -100BP EPISODE
//---------------------------------------------------------------------
dn100Episode =
inSample and
dn100Armed and
spread <= -1.00
if dn100Episode
dn100Armed := false
//=====================================================================
// 9. HISTORICAL FORWARD WINDOWS
//
// Every comparable episode receives a full 60-trading-day
// observation window.
//=====================================================================
boeHigh20 =
ta.highest(
boe,
20)
boeHigh60 =
ta.highest(
boe,
60)
boeLow20 =
ta.lowest(
boe,
20)
boeLow60 =
ta.lowest(
boe,
60)
// BoE rate when the episode began 60 bars ago
signalBoE =
boe[60]
// First 20 trading days following episode
futureHigh20 =
boeHigh20[40]
futureLow20 =
boeLow20[40]
// Full 60-day period following episode
futureHigh60 =
boeHigh60
futureLow60 =
boeLow60
// Exact change after 60 trading days
change60 =
boe - signalBoE
//=====================================================================
// 10. HISTORICAL STORAGE
//=====================================================================
//---------------------------------------------------------------------
// +50
//---------------------------------------------------------------------
var int up50N = 0
var int up50Hit20 = 0
var int up50Hit60 = 0
var float[] up50Changes60 =
array.new_float()
//---------------------------------------------------------------------
// +100
//---------------------------------------------------------------------
var int up100N = 0
var int up100Hit20 = 0
var int up100Hit60 = 0
var float[] up100Changes60 =
array.new_float()
//---------------------------------------------------------------------
// -50
//---------------------------------------------------------------------
var int dn50N = 0
var int dn50Hit20 = 0
var int dn50Hit60 = 0
var float[] dn50Changes60 =
array.new_float()
//---------------------------------------------------------------------
// -100
//---------------------------------------------------------------------
var int dn100N = 0
var int dn100Hit20 = 0
var int dn100Hit60 = 0
var float[] dn100Changes60 =
array.new_float()
//=====================================================================
// 11. MATURE HISTORICAL EPISODES
//=====================================================================
matureUp50 =
up50Episode[60]
matureUp100 =
up100Episode[60]
matureDn50 =
dn50Episode[60]
matureDn100 =
dn100Episode[60]
//=====================================================================
// 12. UPDATE +50 STATISTICS
//=====================================================================
if matureUp50 and not na(signalBoE)
up50N += 1
if futureHigh20 > signalBoE
up50Hit20 += 1
if futureHigh60 > signalBoE
up50Hit60 += 1
if not na(change60)
array.push(
up50Changes60,
change60)
//=====================================================================
// 13. UPDATE +100 STATISTICS
//=====================================================================
if matureUp100 and not na(signalBoE)
up100N += 1
if futureHigh20 > signalBoE
up100Hit20 += 1
if futureHigh60 > signalBoE
up100Hit60 += 1
if not na(change60)
array.push(
up100Changes60,
change60)
//=====================================================================
// 14. UPDATE -50 STATISTICS
//=====================================================================
if matureDn50 and not na(signalBoE)
dn50N += 1
if futureLow20 < signalBoE
dn50Hit20 += 1
if futureLow60 < signalBoE
dn50Hit60 += 1
if not na(change60)
array.push(
dn50Changes60,
change60)
//=====================================================================
// 15. UPDATE -100 STATISTICS
//=====================================================================
if matureDn100 and not na(signalBoE)
dn100N += 1
if futureLow20 < signalBoE
dn100Hit20 += 1
if futureLow60 < signalBoE
dn100Hit60 += 1
if not na(change60)
array.push(
dn100Changes60,
change60)
//=====================================================================
// 16. HELPER FUNCTIONS
//=====================================================================
f_pct(int hits, int n) =>
n > 0
? 100.0 * hits / n
: na
f_median(float[] data) =>
array.size(data) > 0
? array.median(data)
: na
f_pctText(float v) =>
na(v)
? "n/a"
: str.tostring(v, "#") + "%"
f_bpText(float v) =>
na(v)
? "n/a"
: str.tostring(
v * 100.0,
"#") + " bp"
f_rateText(float v) =>
na(v)
? "n/a"
: str.tostring(
v,
"#.##") + "%"
//=====================================================================
// 17. HISTORICAL RESULTS
//=====================================================================
//---------------------------------------------------------------------
// +50
//---------------------------------------------------------------------
up50Pct20 =
f_pct(
up50Hit20,
up50N)
up50Pct60 =
f_pct(
up50Hit60,
up50N)
up50Median60 =
f_median(
up50Changes60)
//---------------------------------------------------------------------
// +100
//---------------------------------------------------------------------
up100Pct20 =
f_pct(
up100Hit20,
up100N)
up100Pct60 =
f_pct(
up100Hit60,
up100N)
up100Median60 =
f_median(
up100Changes60)
//---------------------------------------------------------------------
// -50
//---------------------------------------------------------------------
dn50Pct20 =
f_pct(
dn50Hit20,
dn50N)
dn50Pct60 =
f_pct(
dn50Hit60,
dn50N)
dn50Median60 =
f_median(
dn50Changes60)
//---------------------------------------------------------------------
// -100
//---------------------------------------------------------------------
dn100Pct20 =
f_pct(
dn100Hit20,
dn100N)
dn100Pct60 =
f_pct(
dn100Hit60,
dn100N)
dn100Median60 =
f_median(
dn100Changes60)
//=====================================================================
// 18. CURRENT COMPARABLE HISTORICAL REGIME
//=====================================================================
string activeRegime =
"NEUTRAL"
int activeN =
0
float activeHit20 =
na
float activeHit60 =
na
float activeMedian60 =
na
//---------------------------------------------------------------------
// STRONG UP
//---------------------------------------------------------------------
if spread >= 1.00
activeRegime :=
"+100bp"
activeN :=
up100N
activeHit20 :=
up100Pct20
activeHit60 :=
up100Pct60
activeMedian60 :=
up100Median60
//---------------------------------------------------------------------
// MODERATE UP
//---------------------------------------------------------------------
else if spread >= 0.50
activeRegime :=
"+50bp"
activeN :=
up50N
activeHit20 :=
up50Pct20
activeHit60 :=
up50Pct60
activeMedian60 :=
up50Median60
//---------------------------------------------------------------------
// STRONG DOWN
//---------------------------------------------------------------------
else if spread <= -1.00
activeRegime :=
"-100bp"
activeN :=
dn100N
activeHit20 :=
dn100Pct20
activeHit60 :=
dn100Pct60
activeMedian60 :=
dn100Median60
//---------------------------------------------------------------------
// MODERATE DOWN
//---------------------------------------------------------------------
else if spread <= -0.50
activeRegime :=
"-50bp"
activeN :=
dn50N
activeHit20 :=
dn50Pct20
activeHit60 :=
dn50Pct60
activeMedian60 :=
dn50Median60
//=====================================================================
// 19. LIVE SIGNAL
//
// A signal requires:
//
// 1. Sufficient spread
// 2. Sufficient Z-score
// 3. Spread moving beyond its 20-day average
// 4. Persistence for X trading days
//=====================================================================
liveThreshold =
signalThresholdBp / 100.0
rawUp =
spread >= liveThreshold and
not na(zScore) and
zScore >= zThreshold and
spread > spreadEMA
rawDown =
spread <= -liveThreshold and
not na(zScore) and
zScore <= -zThreshold and
spread < spreadEMA
//=====================================================================
// 20. PERSISTENCE COUNTERS
//=====================================================================
var int upDays = 0
var int downDays = 0
if rawUp
upDays += 1
else
upDays := 0
if rawDown
downDays += 1
else
downDays := 0
upPressure =
upDays >= persistenceDays
downPressure =
downDays >= persistenceDays
newUpPressure =
upPressure and
not upPressure[1]
newDownPressure =
downPressure and
not downPressure[1]
//=====================================================================
// 21. STATE
//
// STATE tells us what the raw market divergence looks like NOW.
//=====================================================================
string stateText =
"BALANCED"
if spread >= 1.00
stateText :=
"STRONG UPWARD DIVERGENCE"
else if spread >= 0.50
stateText :=
"UPWARD DIVERGENCE"
else if spread <= -1.00
stateText :=
"STRONG DOWNWARD DIVERGENCE"
else if spread <= -0.50
stateText :=
"DOWNWARD DIVERGENCE"
//=====================================================================
// 22. SIGNAL
//
// SIGNAL tells us whether all confirmation conditions have completed.
//=====================================================================
string signalText =
"WAITING"
if upPressure
signalText :=
"UP PRESSURE"
else if downPressure
signalText :=
"DOWN PRESSURE"
//=====================================================================
// 23. MEDIAN HISTORICAL RESPONSE
//=====================================================================
float medianModel60 =
na
if not na(activeMedian60)
medianModel60 :=
boe + activeMedian60
nearest25 =
not na(medianModel60)
? math.round(
medianModel60 * 4.0
) / 4.0
: na
//=====================================================================
// 24. PLAIN-ENGLISH GAP INTERPRETATION
//=====================================================================
string gapMeaning =
"Close to Bank Rate"
if spread >= 1.00
gapMeaning :=
"Large upward separation"
else if spread >= 0.50
gapMeaning :=
"Meaningful upward separation"
else if spread <= -1.00
gapMeaning :=
"Large downward separation"
else if spread <= -0.50
gapMeaning :=
"Meaningful downward separation"
//=====================================================================
// 25. PLAIN-ENGLISH Z-SCORE INTERPRETATION
//=====================================================================
string zMeaning =
"Normal"
if not na(zScore)
if zScore >= 2.0
zMeaning :=
"Very unusual HIGH"
else if zScore >= 1.0
zMeaning :=
"Notable HIGH"
else if zScore <= -2.0
zMeaning :=
"Very unusual LOW"
else if zScore <= -1.0
zMeaning :=
"Notable LOW"
//=====================================================================
// 26. SAMPLE QUALITY
//=====================================================================
string sampleText =
"Very small"
if activeN >= 10
sampleText :=
"Better"
else if activeN >= 5
sampleText :=
"Small"
//=====================================================================
// 27. PERSISTENCE TEXT
//=====================================================================
string persistenceText =
"-"
if upPressure
persistenceText :=
str.tostring(
upDays
) + "d"
else if downPressure
persistenceText :=
str.tostring(
downDays
) + "d"
else if rawUp
persistenceText :=
str.tostring(
upDays
) + "/" +
str.tostring(
persistenceDays
)
else if rawDown
persistenceText :=
str.tostring(
downDays
) + "/" +
str.tostring(
persistenceDays
)
//=====================================================================
// 28. COLOUR LOGIC
//=====================================================================
//---------------------------------------------------------------------
// GAP
//---------------------------------------------------------------------
gapBg =
spread >= 1.00
? upStrong
: spread >= 0.50
? upSoft
: spread <= -1.00
? downStrong
: spread <= -0.50
? downSoft
: neutralBg
//---------------------------------------------------------------------
// Z
//---------------------------------------------------------------------
zBg =
not na(zScore) and zScore >= 2.0
? upStrong
: not na(zScore) and zScore >= 1.0
? amberBg
: not na(zScore) and zScore <= -2.0
? downStrong
: not na(zScore) and zScore <= -1.0
? amberBg
: neutralBg
//---------------------------------------------------------------------
// STATE
//---------------------------------------------------------------------
stateBg =
spread >= 1.00
? upStrong
: spread >= 0.50
? upSoft
: spread <= -1.00
? downStrong
: spread <= -0.50
? downSoft
: neutralBg
//---------------------------------------------------------------------
// SIGNAL
//---------------------------------------------------------------------
signalBg =
upPressure
? upStrong
: downPressure
? downStrong
: rawUp or rawDown
? amberStrong
: neutralBg
//---------------------------------------------------------------------
// SAMPLE SIZE
//---------------------------------------------------------------------
sampleBg =
activeN >= 10
? downSoft
: activeN >= 5
? amberBg
: upSoft
//---------------------------------------------------------------------
// HIT RATE
//---------------------------------------------------------------------
hit20Bg =
na(activeHit20)
? neutralBg
: activeHit20 >= 75
? (
spread >= 0
? upSoft
: downSoft
)
: activeHit20 >= 50
? amberBg
: neutralBg
hit60Bg =
na(activeHit60)
? neutralBg
: activeHit60 >= 75
? (
spread >= 0
? upStrong
: downStrong
)
: activeHit60 >= 50
? amberBg
: neutralBg
//---------------------------------------------------------------------
// MEDIAN HISTORICAL MOVE
//---------------------------------------------------------------------
medianMoveBg =
na(activeMedian60)
? neutralBg
: activeMedian60 > 0
? upSoft
: activeMedian60 < 0
? downSoft
: neutralBg
//=====================================================================
// 29. LOWER PANE - CORE INDICATOR
//=====================================================================
plot(
spread,
title="GB02Y minus BoE Bank Rate",
color=color.blue,
linewidth=2)
plot(
showSpreadEMA
? spreadEMA
: na,
title="20-Day Spread Average",
color=color.orange,
linewidth=2)
hline(
0,
title="GB02Y = BoE",
color=color.gray,
linestyle=hline.style_dashed)
//=====================================================================
// 30. THRESHOLD LINES
//=====================================================================
plot(
showThresholds
? 0.50
: na,
title="+50bp",
color=color.new(
color.red,
60),
linewidth=1)
plot(
showThresholds
? 1.00
: na,
title="+100bp",
color=color.red,
linewidth=2)
plot(
showThresholds
? -0.50
: na,
title="-50bp",
color=color.new(
color.green,
60),
linewidth=1)
plot(
showThresholds
? -1.00
: na,
title="-100bp",
color=color.green,
linewidth=2)
//=====================================================================
// 31. ACTUAL BOE MOVES
//=====================================================================
plotshape(
showActualMoves and actualHike,
title="Actual BoE Hike",
style=shape.circle,
location=location.bottom,
color=color.red,
size=size.tiny,
text="H")
plotshape(
showActualMoves and actualCut,
title="Actual BoE Cut",
style=shape.circle,
location=location.top,
color=color.green,
size=size.tiny,
text="C")
//=====================================================================
// 32. LIVE SIGNAL MARKERS
//=====================================================================
plotshape(
showSignals and newUpPressure,
title="New Up Pressure",
style=shape.labelup,
location=location.bottom,
color=color.red,
textcolor=color.white,
size=size.small,
text="UP")
plotshape(
showSignals and newDownPressure,
title="New Down Pressure",
style=shape.labeldown,
location=location.top,
color=color.green,
textcolor=color.white,
size=size.small,
text="DOWN")
//=====================================================================
// 33. LOWER-PANE BACKGROUND
//=====================================================================
bgcolor(
upPressure
? color.new(
color.red,
94)
: downPressure
? color.new(
color.green,
94)
: na)
//=====================================================================
// 34. ALERTS
//=====================================================================
alertcondition(
newUpPressure,
title="BoE Upward Policy Pressure",
message=
"GB02Y-BoE spread entered a persistent upward policy-pressure regime.")
alertcondition(
newDownPressure,
title="BoE Downward Policy Pressure",
message=
"GB02Y-BoE spread entered a persistent downward policy-pressure regime.")
//=====================================================================
// 35. DATA WINDOW
//=====================================================================
plot(
zScore,
title="Spread Z-Score",
display=display.data_window)
plot(
activeMedian60,
title="Historical Median 60D BoE Change",
display=display.data_window)
plot(
medianModel60,
title="Median Historical 60D Model Rate",
display=display.data_window)
//=====================================================================
// 36. MAIN POLICY TABLE
//
// IMPORTANT:
//
// force_overlay=true
//
// This moves THIS table to the TOP PRICE CHART even though the
// indicator itself lives in the lower pane.
//=====================================================================
var table dash =
table.new(
position.top_right,
5,
12,
bgcolor=color.new(
color.black,
5),
frame_color=color.gray,
frame_width=1,
border_color=color.rgb(
90,
90,
90),
border_width=1,
force_overlay=true)
//=====================================================================
// 37. CLEAR MAIN TABLE
//=====================================================================
if barstate.islast
table.clear(
dash,
0,
0,
4,
11)
//=====================================================================
// 38. MAIN TABLE CONTENT
//=====================================================================
if barstate.islast and showMainDashboard
//-------------------------------------------------------------
// TITLE
//-------------------------------------------------------------
table.cell(
dash,
0,
0,
"BOE POLICY PRESSURE",
bgcolor=headerBg,
text_color=textCol)
table.cell(
dash,
1,
0,
"",
bgcolor=headerBg)
table.cell(
dash,
2,
0,
"",
bgcolor=headerBg)
table.cell(
dash,
3,
0,
"",
bgcolor=headerBg)
table.cell(
dash,
4,
0,
"",
bgcolor=headerBg)
//-------------------------------------------------------------
// CURRENT MARKET SECTION
//-------------------------------------------------------------
table.cell(
dash,
0,
1,
"CURRENT MARKET",
bgcolor=sectionBg,
text_color=textCol)
table.cell(
dash,
1,
1,
"",
bgcolor=sectionBg)
table.cell(
dash,
2,
1,
"",
bgcolor=sectionBg)
table.cell(
dash,
3,
1,
"",
bgcolor=sectionBg)
table.cell(
dash,
4,
1,
"",
bgcolor=sectionBg)
//-------------------------------------------------------------
// RATES
//-------------------------------------------------------------
table.cell(
dash,
0,
2,
"GB02Y",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
2,
f_rateText(
gb02y),
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
2,
2,
"BoE Rate",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
2,
f_rateText(
boe),
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
4,
2,
"",
bgcolor=neutralBg)
//-------------------------------------------------------------
// GAP
//-------------------------------------------------------------
table.cell(
dash,
0,
3,
"Gap",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
3,
f_bpText(
spread),
bgcolor=gapBg,
text_color=textCol)
table.cell(
dash,
2,
3,
"Meaning",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
3,
gapMeaning,
bgcolor=gapBg,
text_color=textCol)
table.cell(
dash,
4,
3,
"",
bgcolor=gapBg)
//-------------------------------------------------------------
// Z-SCORE
//-------------------------------------------------------------
table.cell(
dash,
0,
4,
"Z-score",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
4,
na(zScore)
? "n/a"
: str.tostring(
zScore,
"#.##"),
bgcolor=zBg,
text_color=textCol)
table.cell(
dash,
2,
4,
"Meaning",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
4,
zMeaning,
bgcolor=zBg,
text_color=textCol)
table.cell(
dash,
4,
4,
"",
bgcolor=zBg)
//-------------------------------------------------------------
// STATE / SIGNAL
//-------------------------------------------------------------
table.cell(
dash,
0,
5,
"STATE",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
5,
stateText,
bgcolor=stateBg,
text_color=textCol)
table.cell(
dash,
2,
5,
"SIGNAL",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
5,
signalText,
bgcolor=signalBg,
text_color=textCol)
table.cell(
dash,
4,
5,
persistenceText,
bgcolor=signalBg,
text_color=textCol)
//-------------------------------------------------------------
// HISTORICAL EVIDENCE HEADER
//-------------------------------------------------------------
table.cell(
dash,
0,
7,
"HISTORICAL EVIDENCE",
bgcolor=sectionBg,
text_color=textCol)
table.cell(
dash,
1,
7,
"",
bgcolor=sectionBg)
table.cell(
dash,
2,
7,
"",
bgcolor=sectionBg)
table.cell(
dash,
3,
7,
"",
bgcolor=sectionBg)
table.cell(
dash,
4,
7,
"",
bgcolor=sectionBg)
//-------------------------------------------------------------
// COMPARABLE EPISODES
//-------------------------------------------------------------
table.cell(
dash,
0,
8,
"Comparable",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
8,
activeRegime,
bgcolor=stateBg,
text_color=textCol)
table.cell(
dash,
2,
8,
"Episodes",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
8,
str.tostring(
activeN),
bgcolor=sampleBg,
text_color=textCol)
table.cell(
dash,
4,
8,
sampleText,
bgcolor=sampleBg,
text_color=textCol)
//-------------------------------------------------------------
// HISTORICAL DIRECTIONAL HITS
//-------------------------------------------------------------
table.cell(
dash,
0,
9,
"Move within 20d",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
9,
f_pctText(
activeHit20),
bgcolor=hit20Bg,
text_color=textCol)
table.cell(
dash,
2,
9,
"Move within 60d",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
9,
f_pctText(
activeHit60),
bgcolor=hit60Bg,
text_color=textCol)
table.cell(
dash,
4,
9,
"Historical",
bgcolor=neutralBg,
text_color=textCol)
//-------------------------------------------------------------
// MEDIAN RESPONSE
//-------------------------------------------------------------
table.cell(
dash,
0,
10,
"Median 60d change",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
1,
10,
f_bpText(
activeMedian60),
bgcolor=medianMoveBg,
text_color=textCol)
table.cell(
dash,
2,
10,
"Median 60d level",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
dash,
3,
10,
f_rateText(
medianModel60),
bgcolor=medianMoveBg,
text_color=textCol)
table.cell(
dash,
4,
10,
"Hist. estimate",
bgcolor=neutralBg,
text_color=textCol)
//-------------------------------------------------------------
// SETTINGS
//-------------------------------------------------------------
table.cell(
dash,
0,
11,
"Trigger",
bgcolor=headerBg,
text_color=textCol)
table.cell(
dash,
1,
11,
str.tostring(
signalThresholdBp
) + "bp",
bgcolor=headerBg,
text_color=textCol)
table.cell(
dash,
2,
11,
"Required Z",
bgcolor=headerBg,
text_color=textCol)
table.cell(
dash,
3,
11,
str.tostring(
zThreshold,
"#.0"),
bgcolor=headerBg,
text_color=textCol)
table.cell(
dash,
4,
11,
"1D",
bgcolor=headerBg,
text_color=textCol)
//=====================================================================
// 39. OPTIONAL "HOW TO READ" TABLE
//
// This stays in the LOWER indicator pane.
//
// Default setting is OFF.
//
// Settings -> Display -> Show How To Read / Cheat Sheet
//=====================================================================
var table cheat =
table.new(
position.bottom_right,
4,
12,
bgcolor=color.new(
color.black,
5),
frame_color=color.gray,
frame_width=1,
border_color=color.rgb(
90,
90,
90),
border_width=1)
//=====================================================================
// 40. CLEAR CHEAT SHEET
//=====================================================================
if barstate.islast
table.clear(
cheat,
0,
0,
3,
11)
//=====================================================================
// 41. OPTIONAL CHEAT SHEET CONTENT
//=====================================================================
if barstate.islast and showHowToRead
//-------------------------------------------------------------
// HEADER
//-------------------------------------------------------------
table.cell(
cheat,
0,
0,
"HOW TO READ",
bgcolor=headerBg,
text_color=textCol)
table.cell(
cheat,
1,
0,
"MEANING",
bgcolor=headerBg,
text_color=textCol)
table.cell(
cheat,
2,
0,
"FOCUS",
bgcolor=headerBg,
text_color=textCol)
table.cell(
cheat,
3,
0,
"READ",
bgcolor=headerBg,
text_color=textCol)
//-------------------------------------------------------------
// GAP
//-------------------------------------------------------------
table.cell(
cheat,
0,
1,
"Gap",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
cheat,
1,
1,
"GB02Y - BoE",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
cheat,
2,
1,
"Direction",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
cheat,
3,
1,
"+ up / - down",
bgcolor=neutralBg,
text_color=textCol)
//-------------------------------------------------------------
// +/-50
//-------------------------------------------------------------
table.cell(
cheat,
0,
2,
"+/-50bp",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
1,
2,
"Meaningful gap",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
2,
2,
"WATCH",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
3,
2,
"Gap matters",
bgcolor=amberBg,
text_color=textCol)
//-------------------------------------------------------------
// +100
//-------------------------------------------------------------
table.cell(
cheat,
0,
3,
"+100bp",
bgcolor=upStrong,
text_color=textCol)
table.cell(
cheat,
1,
3,
"Large upward gap",
bgcolor=upStrong,
text_color=textCol)
table.cell(
cheat,
2,
3,
"HIGH FOCUS",
bgcolor=upStrong,
text_color=textCol)
table.cell(
cheat,
3,
3,
"Upward pressure",
bgcolor=upStrong,
text_color=textCol)
//-------------------------------------------------------------
// -100
//-------------------------------------------------------------
table.cell(
cheat,
0,
4,
"-100bp",
bgcolor=downStrong,
text_color=textCol)
table.cell(
cheat,
1,
4,
"Large downward gap",
bgcolor=downStrong,
text_color=textCol)
table.cell(
cheat,
2,
4,
"HIGH FOCUS",
bgcolor=downStrong,
text_color=textCol)
table.cell(
cheat,
3,
4,
"Downward pressure",
bgcolor=downStrong,
text_color=textCol)
//-------------------------------------------------------------
// NORMAL Z
//-------------------------------------------------------------
table.cell(
cheat,
0,
5,
"|Z| < 1",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
cheat,
1,
5,
"Normal",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
cheat,
2,
5,
"LOW",
bgcolor=neutralBg,
text_color=textCol)
table.cell(
cheat,
3,
5,
"Common",
bgcolor=neutralBg,
text_color=textCol)
//-------------------------------------------------------------
// NOTABLE Z
//-------------------------------------------------------------
table.cell(
cheat,
0,
6,
"|Z| 1-2",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
1,
6,
"Notable",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
2,
6,
"WATCH",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
3,
6,
"Unusual",
bgcolor=amberBg,
text_color=textCol)
//-------------------------------------------------------------
// EXTREME Z
//-------------------------------------------------------------
table.cell(
cheat,
0,
7,
"|Z| > 2",
bgcolor=upStrong,
text_color=textCol)
table.cell(
cheat,
1,
7,
"Very unusual",
bgcolor=upStrong,
text_color=textCol)
table.cell(
cheat,
2,
7,
"HIGH FOCUS",
bgcolor=upStrong,
text_color=textCol)
table.cell(
cheat,
3,
7,
"Extreme gap",
bgcolor=upStrong,
text_color=textCol)
//-------------------------------------------------------------
// SAMPLE <5
//-------------------------------------------------------------
table.cell(
cheat,
0,
8,
"Episodes <5",
bgcolor=upSoft,
text_color=textCol)
table.cell(
cheat,
1,
8,
"Very small sample",
bgcolor=upSoft,
text_color=textCol)
table.cell(
cheat,
2,
8,
"CAUTION",
bgcolor=upSoft,
text_color=textCol)
table.cell(
cheat,
3,
8,
"Weak evidence",
bgcolor=upSoft,
text_color=textCol)
//-------------------------------------------------------------
// SAMPLE 5-9
//-------------------------------------------------------------
table.cell(
cheat,
0,
9,
"Episodes 5-9",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
1,
9,
"Small sample",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
2,
9,
"CARE",
bgcolor=amberBg,
text_color=textCol)
table.cell(
cheat,
3,
9,
"Useful context",
bgcolor=amberBg,
text_color=textCol)
//-------------------------------------------------------------
// SAMPLE 10+
//-------------------------------------------------------------
table.cell(
cheat,
0,
10,
"Episodes 10+",
bgcolor=downSoft,
text_color=textCol)
table.cell(
cheat,
1,
10,
"Better sample",
bgcolor=downSoft,
text_color=textCol)
table.cell(
cheat,
2,
10,
"MORE USEFUL",
bgcolor=downSoft,
text_color=textCol)
table.cell(
cheat,
3,
10,
"More evidence",
bgcolor=downSoft,
text_color=textCol)
//-------------------------------------------------------------
// HISTORICAL HIT RATE
//-------------------------------------------------------------
table.cell(
cheat,
0,
11,
"20d / 60d",
bgcolor=sectionBg,
text_color=textCol)
table.cell(
cheat,
1,
11,
"Past same-way move",
bgcolor=sectionBg,
text_color=textCol)
table.cell(
cheat,
2,
11,
"HISTORICAL",
bgcolor=sectionBg,
text_color=textCol)
table.cell(
cheat,
3,
11,
"NOT probability",
bgcolor=sectionBg,
text_color=textCol)