本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator('TrendVote: trend, pullbacks and Smart Money in plain words', shorttitle = 'TrendVote', overlay = true, max_labels_count = 500, max_boxes_count = 100, max_lines_count = 200, max_bars_back = 500)
grpS = 'Signal'
minVotes = input.int(5, 'Entry: minimum vote lead (out of 7)', minval = 1, maxval = 7, group = grpS, tooltip = 'How many indicators must outweigh the others in one direction. 5 means six of seven agree.')
adxLen = input.int(14, 'ADX length', group = grpS)
adxThr = input.float(20.0, 'ADX: trend threshold', group = grpS, tooltip = 'ADX measures how strong the move is. Below the threshold the market is going nowhere and there are no signals.')
useHtf = input.bool(true, 'Check the higher timeframe', group = grpS, tooltip = 'Do not trade against the next higher timeframe.')
htfIn = input.timeframe('', 'Higher timeframe (empty = auto)', group = grpS)
sigH4 = input.bool(true, 'Below H4, take the signal from H4', group = grpS, tooltip = 'History test with spread: on H1 and below the rule loses, on H4 and daily it is close to zero on currencies and positive on gold. So on small charts the arrows, the trade and the trend color are calculated from closed H4 bars. The small chart is there to see the entry price more precisely.')
grpT = 'Trade'
atrLen = input.int(14, 'ATR length', group = grpT)
atrMult = input.float(1.5, 'Stop = ATR x', group = grpT, tooltip = 'ATR is how far price usually moves in one bar. The stop sits 1.5 such moves away from the bar, so normal noise does not hit it.')
rr = input.float(2.0, 'Target = risk x', minval = 0.5, step = 0.5, group = grpT, tooltip = 'The target is twice as far as the stop: risk 1 to make 2.')
tradeMode = input.string('Simple', 'Trade mode', options = ['Simple', 'Breakeven'], group = grpT, tooltip = 'Simple: one stop and one target. Breakeven: at the first target close half and move the stop to the entry price. The history test showed no improvement.')
usePull = input.bool(false, 'Wait for a pullback before entry (experiment)', group = grpT, tooltip = 'The history test showed no improvement.')
maxStretch = input.float(1.0, 'Pullback: price no farther from EMA 50 than ATR x', minval = 0.1, step = 0.1, group = grpT)
costPips = input.float(1.0, 'Cost per trade, pips (spread)', minval = 0, group = grpT)
grpM = 'Money'
balance = input.float(100.0, 'Account balance, $', minval = 1, group = grpM)
riskPct = input.float(1.0, 'Risk per trade, %', minval = 0.1, step = 0.1, group = grpM)
grpMy = 'My trade'
myDirS = input.string('none', 'My trade', options = ['none', 'buy', 'sell'], group = grpMy, tooltip = 'The indicator cannot see the broker account. Choose the direction and pick the entry price on the chart with the crosshair icon next to the field; the line can then be dragged. Trade closed: enter the exit price and the row shows the result.')
myEntry = input.price(0.0, 'Entry price', group = grpMy)
myExit = input.price(0.0, 'Exit price, 0 = trade is open', group = grpMy)
newsS = input.string('none', 'Main news today', options = ['none', 'Fed rate', 'ECB rate', 'US jobs', 'inflation', 'politician spoke', 'other big one'], group = grpMy, tooltip = 'The indicator cannot read the news. Pick today\'s main event here and the table tells you how to behave.')
nbTxt = input.text_area('', 'Notebook: trade results in $ separated by spaces', group = grpMy)
nbShow = input.bool(true, 'Show the notebook as a separate window', group = grpMy)
myLots = input.float(0.01, 'Size, lots', minval = 0.01, step = 0.01, group = grpMy)
grpV = 'View'
tblPosS = input.string('top right', 'Table position', options = ['top right', 'bottom right', 'top left', 'bottom left'], group = grpV)
tblSizeS = input.string('normal', 'Table size', options = ['small', 'normal', 'large'], group = grpV)
lblSizeS = input.string('normal', 'Chart label size', options = ['small', 'normal', 'large'], group = grpV)
showPat = input.bool(true, 'Candlestick pattern marks on the chart', group = grpV)
showRibbon = input.bool(true, 'Trend cloud along the line', group = grpV)
colorBars = input.bool(true, 'Trend candles: bright with the trend, pale on pullbacks', group = grpV)
showZones = input.bool(true, 'Risk and profit zones of the open trade', group = grpV)
maxRes = input.int(8, 'How many past results to show', minval = 0, maxval = 100, group = grpV)
resMode = input.string('pips and $', 'Show trade result as', options = ['pips and $', 'pips', 'R'], group = grpV, tooltip = 'Pips: how many pips the trade made or lost. Dollars are for a 0.01 lot. R: the result as a multiple of the risk (+2R = made two stops).')
showLevels = input.bool(true, 'Levels: yesterday, week, month, breakout and reversal', group = grpV)
funny = input.bool(true, 'Labels with humor', group = grpV)
showSMC = input.bool(true, 'Structure: continuation and reversal (BOS, CHoCH), double tops', group = grpV)
smcKeep = input.int(6, 'How many recent structure marks to show', minval = 2, maxval = 40, group = grpV)
showFVG = input.bool(false, 'Price gaps (FVG)', group = grpV)
showOB = input.bool(true, 'Buyer and seller zones (order blocks)', group = grpV)
zoneKeep = input.int(2, 'How many zones of each kind to keep on the chart', minval = 1, maxval = 10, group = grpV)
showPD = input.bool(true, 'Zones: expensive, middle, cheap (premium, equilibrium, discount)', group = grpV)
pdLen = input.int(100, 'Zones: how many bars define the range', minval = 20, maxval = 500, group = grpV)
tzS = input.string('Jerusalem', 'Your city for the table clock', options = ['Jerusalem', 'Moscow', 'Athens, Kyiv', 'Rome, Berlin, Paris', 'London', 'New York', 'Chicago', 'Los Angeles', 'Dubai', 'Delhi', 'Singapore', 'Tokyo', 'Sydney', 'UTC'], group = grpV, tooltip = 'The clock and the session hours in the table use this city. New York time is always shown next to it.')
tzIn = tzS == 'Jerusalem' ? 'Asia/Jerusalem' : tzS == 'Moscow' ? 'Europe/Moscow' : tzS == 'Athens, Kyiv' ? 'Europe/Athens' : tzS == 'Rome, Berlin, Paris' ? 'Europe/Berlin' : tzS == 'London' ? 'Europe/London' : tzS == 'New York' ? 'America/New_York' : tzS == 'Chicago' ? 'America/Chicago' : tzS == 'Los Angeles' ? 'America/Los_Angeles' : tzS == 'Dubai' ? 'Asia/Dubai' : tzS == 'Delhi' ? 'Asia/Kolkata' : tzS == 'Singapore' ? 'Asia/Singapore' : tzS == 'Tokyo' ? 'Asia/Tokyo' : tzS == 'Sydney' ? 'Australia/Sydney' : 'UTC'
isEn = true
L(string ru, string eng) =>
isEn ? eng : ru
f_pick(int k, string a, string b, string c) =>
k == 0 ? a : k == 1 ? b : c
f_pips(float v) =>
n = math.round(math.abs(nz(v)))
n10 = n % 10
n100 = n % 100
w = n == 1 ? ' pip' : ' pips'
str.tostring(v, '0') + w
txtSize = tblSizeS == 'small' ? size.small : tblSizeS == 'large' ? size.large : size.normal
tblPos = tblPosS == 'top right' ? position.top_right : tblPosS == 'bottom right' ? position.bottom_right : tblPosS == 'top left' ? position.top_left : position.bottom_left
useBE = tradeMode == 'Breakeven'
hdSize = tblSizeS == 'small' ? size.normal : tblSizeS == 'large' ? size.huge : size.large
lblBig = lblSizeS == 'small' ? size.small : lblSizeS == 'large' ? size.large : size.normal
lblSmall = lblSizeS == 'small' ? size.tiny : lblSizeS == 'large' ? size.normal : size.small
cUp = #26A69A
cDn = #EF5350
cNeu = #B0BEC5
cAcc = #42A5F5
cWarn = #FFA726
cRev = #BA68C8
cGood = #66BB6A
f_votes() =>
e50 = ta.ema(close, 50)
e200 = ta.ema(close, 200)
[macdLine, sigLine, hist] = ta.macd(close, 12, 26, 9)
r14 = ta.rsi(close, 14)
mom = ta.mom(close, 8)
k = ta.sma(ta.stoch(close, high, low, 8), 3)
d = ta.sma(k, 3)
r3 = ta.rsi(close, 3)
r13 = ta.rsi(close, 13)
v1 = close > e200 ? 1 : -1
v2 = e50 > e200 ? 1 : -1
v3 = hist > 0 ? 1 : -1
v4 = r14 > 50 ? 1 : -1 // RSI 14
v5 = mom > 0 ? 1 : -1 // Momentum 8
v6 = k > d ? 1 : -1 // Stochastic 8,3,3
v7 = r3 > r13 ? 1 : -1
[v1, v2, v3, v4, v5, v6, v7]
f_score() =>
[a, b, c, d, e, f, g] = f_votes()
a + b + c + d + e + f + g
[v1, v2, v3, v4, v5, v6, v7] = f_votes()
score = v1 + v2 + v3 + v4 + v5 + v6 + v7
tfSec = timeframe.in_seconds()
autoHtf = tfSec < 300 ? '15' : tfSec < 900 ? '60' : tfSec < 3600 ? '240' : tfSec <= 14400 ? 'D' : tfSec <= 86400 ? 'W' : 'M'
htf = htfIn == '' ? autoHtf : htfIn
htfScoreRaw = request.security(syminfo.tickerid, htf, f_score()[1], lookahead = barmerge.lookahead_on)
htfScore = nz(htfScoreRaw)
s15Raw = request.security(syminfo.tickerid, '15', f_score()[1], lookahead = barmerge.lookahead_on)
s60Raw = request.security(syminfo.tickerid, '60', f_score()[1], lookahead = barmerge.lookahead_on)
s240Raw = request.security(syminfo.tickerid, '240', f_score()[1], lookahead = barmerge.lookahead_on)
sDRaw = request.security(syminfo.tickerid, 'D', f_score()[1], lookahead = barmerge.lookahead_on)
s15 = timeframe.period == '15' ? score : nz(s15Raw)
s60 = timeframe.period == '60' ? score : nz(s60Raw)
s240 = timeframe.period == '240' ? score : nz(s240Raw)
sD = timeframe.period == 'D' ? score : nz(sDRaw)
[_, _, adx] = ta.dmi(adxLen, adxLen)
atr = ta.atr(atrLen)
e50p = ta.ema(close, 50)
e200p = ta.ema(close, 200)
f_adx() =>
[dp, dm, ax] = ta.dmi(adxLen, adxLen)
ax
useSigTf = sigH4 and tfSec < 14400
[gScore, gAdx, gAtr, gHigh, gLow, gClose, gTime] = request.security(syminfo.tickerid, '240', [f_score()[1], f_adx()[1], ta.atr(atrLen)[1], high[1], low[1], close[1], time[1]], lookahead = barmerge.lookahead_on)
scoreS = useSigTf ? nz(gScore) : score
adxS = useSigTf ? gAdx : adx
atrS = useSigTf ? gAtr : atr
highS = useSigTf ? gHigh : high
lowS = useSigTf ? gLow : low
closeS = useSigTf ? gClose : close
filtS = useSigTf ? sD : htfScore
sigStep = useSigTf ? not na(gTime) and gTime != nz(gTime[1]) : true
sigConf = useSigTf ? true : barstate.isconfirmed
sigPx = useSigTf and sigStep ? closeS : close
htfUp = not useHtf or filtS > 0
htfDn = not useHtf or filtS < 0
entryUp = scoreS >= minVotes and adxS > adxThr and htfUp
entryDn = scoreS <= -minVotes and adxS > adxThr and htfDn
var int dir = 0
if sigStep
if entryUp
dir := 1
dir
else if entryDn
dir := -1
dir
else if dir == 1 and scoreS < 0 or dir == -1 and scoreS > 0
dir := 0
dir
colUp = cUp
colDn = cDn
colFlat = cNeu
dirCol = dir == 1 ? colUp : dir == -1 ? colDn : colFlat
buySig = dir == 1 and dir[1] != 1 and sigConf
sellSig = dir == -1 and dir[1] != -1 and sigConf
exitSig = dir == 0 and dir[1] != 0 and sigConf
var bool pendL = false
var bool pendS = false
if dir != 1
pendL := false
pendL
else if buySig
pendL := true
pendL
if dir != -1
pendS := false
pendS
else if sellSig
pendS := true
pendS
pip = syminfo.mintick * (syminfo.type == 'forex' ? 10 : 1)
cost = costPips * pip
newLong = lowS - atrS * atrMult
newShort = highS + atrS * atrMult
var int tDir = 0
var int tOpenBar = 0
var float tEntry = na
var float tStop = na
var float tT1 = na
var float tTarget = na
var float tRisk = na
var bool t1Done = false
var float bank = 0.0
var array<label> resLabels = array.new_label()
usdPerUnit = syminfo.type == 'forex' ? syminfo.currency == 'USD' ? 100000.0 : syminfo.basecurrency == 'USD' ? 100000.0 / close : na : na
float res = na
if tDir == 1
if low <= tStop
res := bank + (t1Done ? 0.5 : 1.0) * (math.min(open, tStop) - tEntry) / tRisk - cost / tRisk
res
else
if useBE and not t1Done and high >= tT1
t1Done := true
bank := 0.5
tStop := math.max(tStop, tEntry)
tStop
fracL = t1Done ? 0.5 : 1.0
if high >= tTarget
res := bank + fracL * rr - cost / tRisk
res
else if dir != 1 and sigConf
res := bank + fracL * (sigPx - tEntry) / tRisk - cost / tRisk
res
else
tStop := math.max(tStop, nz(newLong, tStop))
tStop
else if tDir == -1
if high >= tStop
res := bank + (t1Done ? 0.5 : 1.0) * (tEntry - math.max(open, tStop)) / tRisk - cost / tRisk
res
else
if useBE and not t1Done and low <= tT1
t1Done := true
bank := 0.5
tStop := math.min(tStop, tEntry)
tStop
fracS = t1Done ? 0.5 : 1.0
if low <= tTarget
res := bank + fracS * rr - cost / tRisk
res
else if dir != -1 and sigConf
res := bank + fracS * (tEntry - sigPx) / tRisk - cost / tRisk
res
else
tStop := math.min(tStop, nz(newShort, tStop))
tStop
closedNow = not na(res)
closedDir = tDir
if closedNow
resPips = res * tRisk / pip
resUsd = res * tRisk * usdPerUnit * 0.01
resTxt = resMode == 'R' ? (res > 0 ? '+' : '') + str.tostring(res, '0.0') + 'R' : (resPips > 0 ? '+' : '') + str.tostring(resPips, '0') + ' p' + (resMode == 'pips and $' and not na(resUsd) ? ' ' + (resUsd >= 0 ? '+$' : '-$') + str.tostring(math.abs(resUsd), '0.00') : '')
if maxRes > 0
lbRes = label.new(bar_index, close, resTxt, yloc = closedDir == 1 ? yloc.abovebar : yloc.belowbar, style = closedDir == 1 ? label.style_label_down : label.style_label_up, color = color.new(res > 0 ? cUp : cDn, 25), textcolor = color.white, size = lblSmall, tooltip = 'Result of the practice trade for this arrow: how many pips it made or lost. Dollars are for a 0.01 lot.')
array.push(resLabels, lbRes)
if array.size(resLabels) > maxRes
label.delete(array.shift(resLabels))
tDir := 0
tDir
nearEma = math.abs(close - e50p) <= maxStretch * atr
okEntry = not usePull or nearEma
openL = tDir == 0 and pendL and okEntry and sigConf and not na(atrS) and sigPx > newLong
openS = tDir == 0 and pendS and okEntry and sigConf and not na(atrS) and sigPx < newShort
if openL
tDir := 1
tOpenBar := bar_index
tEntry := sigPx
tStop := newLong
tRisk := math.max(sigPx - newLong, syminfo.mintick)
tT1 := sigPx + tRisk
tTarget := sigPx + rr * tRisk
t1Done := false
bank := 0.0
pendL := false
pendL
else if openS
tDir := -1
tOpenBar := bar_index
tEntry := sigPx
tStop := newShort
tRisk := math.max(newShort - sigPx, syminfo.mintick)
tT1 := sigPx - tRisk
tTarget := sigPx - rr * tRisk
t1Done := false
bank := 0.0
pendS := false
pendS
trendCol = dir == 1 ? cUp : dir == -1 ? cDn : cNeu
bandUp = e50p + atr * 1.6
bandDn = e50p - atr * 1.6
plot(e50p, 'Trend line: glow', color = color.new(trendCol, 86), linewidth = 8, editable = false, display = display.pane)
plot(e50p, 'Trend line: halo', color = color.new(trendCol, 68), linewidth = 4, editable = false, display = display.pane)
pBase = plot(e50p, 'Trend line (EMA 50)', color = trendCol, linewidth = 2)
plot(e200p, 'Long average (EMA 200)', color = color.new(color.white, 62), linewidth = 1)
pUpB = plot(bandUp, 'Cloud upper edge', color = color.new(color.white, 100), editable = false, display = display.pane)
pLoB = plot(bandDn, 'Cloud lower edge', color = color.new(color.white, 100), editable = false, display = display.pane)
fill(pBase, pLoB, e50p, bandDn, showRibbon and dir == 1 ? color.new(cUp, 68) : na, showRibbon and dir == 1 ? color.new(cUp, 100) : na, title = 'Uptrend cloud')
fill(pUpB, pBase, bandUp, e50p, showRibbon and dir == -1 ? color.new(cDn, 100) : na, showRibbon and dir == -1 ? color.new(cDn, 68) : na, title = 'Downtrend cloud')
color candleCol = not colorBars or dir == 0 ? na : dir == 1 ? close >= open ? color.new(cUp, 0) : color.new(cUp, 62) : close <= open ? color.new(cDn, 0) : color.new(cDn, 62)
barcolor(candleCol, title = 'Trend candles')
var array<label> sigLabels = array.new_label()
if buySig or sellSig
array.push(sigLabels, label.new(bar_index, buySig ? low : high, buySig ? 'UP' : 'DOWN', yloc = buySig ? yloc.belowbar : yloc.abovebar, style = buySig ? label.style_label_up : label.style_label_down, color = buySig ? cUp : cDn, textcolor = color.white, size = lblSmall, tooltip = 'Trend arrow.\nSix of seven indicators agree, the trend is strong and the higher timeframe points the same way.\nThe arrow comes late: it confirms the trend, it is not an entry point.'))
if array.size(sigLabels) > 40
label.delete(array.shift(sigLabels))
inTrade = tDir != 0
stopInProfit = tDir == 1 ? tStop >= tEntry : tDir == -1 ? tStop <= tEntry : false
stopDist = inTrade ? tRisk : atrS * atrMult
lots = balance * riskPct / 100 / (stopDist * usdPerUnit)
lotsR = math.floor(lots * 100) / 100
workLot = math.max(nz(lotsR), 0.01)
riskUsd = stopDist * usdPerUnit * workLot
f_money(float x) =>
(x >= 0 ? '+$' : '-$') + str.tostring(math.abs(x), '0.00')
[pdh, pdl] = request.security(syminfo.tickerid, 'D', [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pwh, pwl] = request.security(syminfo.tickerid, 'W', [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pmh, pml] = request.security(syminfo.tickerid, 'M', [high[1], low[1]], lookahead = barmerge.lookahead_on)
useD = timeframe.isintraday
useW = timeframe.isintraday or timeframe.isdaily
useM = not timeframe.ismonthly
pvH = ta.pivothigh(high, 5, 5)
pvL = ta.pivotlow(low, 5, 5)
var float lastPH = na
var float prevPH = na
var float lastPL = na
var float prevPL = na
var int lastPHbar = na
var int prevPHbar = na
var int lastPLbar = na
var int prevPLbar = na
var bool phBroken = true
var bool plBroken = true
var int ms = 0
newPH = not na(pvH)
newPL = not na(pvL)
if newPH
prevPH := lastPH
prevPHbar := lastPHbar
lastPH := pvH
lastPHbar := bar_index - 5
phBroken := false
phBroken
if newPL
prevPL := lastPL
prevPLbar := lastPLbar
lastPL := pvL
lastPLbar := bar_index - 5
plBroken := false
plBroken
var array<line> smcLines = array.new_line()
var array<label> smcLabels = array.new_label()
var int lastEv = 0
var float lastEvLvl = na
tipBosUp = 'BOS (Break of Structure).\nPrice closed ABOVE the previous swing high while the market was already rising. The rise continues.\nWhat to do: do not look for sells.'
tipBosDn = 'BOS (Break of Structure).\nPrice closed BELOW the previous swing low while the market was already falling. The fall continues.\nWhat to do: do not look for buys.'
tipChUp = 'CHoCH (Change of Character).\nThe market was falling, but price closed ABOVE the previous swing high for the first time. This is the first sign of a turn up, not a confirmation yet.\nWhat to do: hold off on sells and wait to see whether the rise is confirmed.'
tipChDn = 'CHoCH (Change of Character).\nThe market was rising, but price closed BELOW the previous swing low for the first time. This is the first sign of a turn down, not a confirmation yet.\nWhat to do: hold off on buys and wait to see whether the fall is confirmed.'
tipEqH = 'EQH (equal highs), a double top.\nPrice stopped twice at the same level. Sellers\' stops usually sit above such a top. Price often goes there, collects those stops and only then decides where to go.'
tipEqL = 'EQL (equal lows), a double bottom.\nPrice stopped twice at the same level. Buyers\' stops usually sit below such a bottom. Price often goes there, collects those stops and only then decides where to go.'
f_smcTrim() =>
if array.size(smcLines) > smcKeep
line.delete(array.shift(smcLines))
if array.size(smcLabels) > smcKeep
label.delete(array.shift(smcLabels))
f_smc(int x1, float y, bool up, bool isChoch) =>
c = up ? color.new(cUp, 0) : color.new(cDn, 0)
txt = isChoch ? up ? 'turning up? (CHoCH)' : 'turning down? (CHoCH)' : up ? 'rise continues (BOS)' : 'fall continues (BOS)'
tip = isChoch ? up ? tipChUp : tipChDn : up ? tipBosUp : tipBosDn
xa = math.max(x1, bar_index - 400)
array.push(smcLines, line.new(xa, y, bar_index, y, color = c, width = 1, style = isChoch ? line.style_solid : line.style_dashed))
array.push(smcLabels, label.new(math.round(math.avg(xa, bar_index)), y, txt, style = up ? label.style_label_down : label.style_label_up, color = color.new(color.black, 100), textcolor = c, size = lblSmall, tooltip = tip))
f_smcTrim()
brkStUp = showSMC and not phBroken and not na(lastPH) and close > lastPH and barstate.isconfirmed
brkStDn = showSMC and not plBroken and not na(lastPL) and close < lastPL and barstate.isconfirmed
if brkStUp
f_smc(lastPHbar, lastPH, true, ms == -1)
lastEv := ms == -1 ? 2 : 1
lastEvLvl := lastPH
ms := 1
phBroken := true
phBroken
if brkStDn
f_smc(lastPLbar, lastPL, false, ms == 1)
lastEv := ms == 1 ? -2 : -1
lastEvLvl := lastPL
ms := -1
plBroken := true
plBroken
if showSMC and newPH and not na(prevPH) and math.abs(lastPH - prevPH) <= 0.1 * atr
array.push(smcLines, line.new(math.max(prevPHbar, bar_index - 400), prevPH, math.max(lastPHbar, bar_index - 400), lastPH, color = color.new(cWarn, 0), width = 1, style = line.style_dotted))
array.push(smcLabels, label.new(math.max(prevPHbar, bar_index - 400), prevPH, 'double top', style = label.style_label_down, color = color.new(color.black, 100), textcolor = cWarn, size = lblSmall, tooltip = tipEqH))
f_smcTrim()
if showSMC and newPL and not na(prevPL) and math.abs(lastPL - prevPL) <= 0.1 * atr
array.push(smcLines, line.new(math.max(prevPLbar, bar_index - 400), prevPL, math.max(lastPLbar, bar_index - 400), lastPL, color = color.new(cWarn, 0), width = 1, style = line.style_dotted))
array.push(smcLabels, label.new(math.max(prevPLbar, bar_index - 400), prevPL, 'double bottom', style = label.style_label_up, color = color.new(color.black, 100), textcolor = cWarn, size = lblSmall, tooltip = tipEqL))
f_smcTrim()
tipFvg = 'FVG (Fair Value Gap), a price gap.\nPrice crossed this area in one burst and almost no trades happened here. The market often comes back to fill the gap and then often continues from it.\nWhat to do: with the trend, this is a zone where traders wait for a pullback to enter. The zone disappears once price passes through it.'
tipObUp = 'Order block, a buyer zone.\nThe last falling candle before a strong rise that broke structure. A large player is believed to have bought here.\nWhat to do: if price returns here in an uptrend, buyers often step in again. The zone disappears when a candle closes below it.'
tipObDn = 'Order block, a seller zone.\nThe last rising candle before a strong fall that broke structure. A large player is believed to have sold here.\nWhat to do: if price returns here in a downtrend, sellers often step in again. The zone disappears when a candle closes above it.'
var array<box> zBox = array.new_box()
var array<label> zLbl = array.new_label()
var array<float> zTop = array.new_float()
var array<float> zBot = array.new_float()
var array<int> zDir = array.new_int()
var array<int> zKind = array.new_int()
f_zoneDel(int i) =>
box.delete(array.get(zBox, i))
label.delete(array.get(zLbl, i))
array.remove(zBox, i)
array.remove(zLbl, i)
array.remove(zTop, i)
array.remove(zBot, i)
array.remove(zDir, i)
array.remove(zKind, i)
f_zoneAdd(int x1, float top, float bot, int zd, int kind) =>
isF = kind == 1
zc = zd == 1 ? cUp : cDn
ztxt = isF ? 'price gap (FVG)' : zd == 1 ? 'buyer zone (OB)' : 'seller zone (OB)'
ztip = isF ? tipFvg : zd == 1 ? tipObUp : tipObDn
array.push(zBox, box.new(x1, top, bar_index + 8, bot, border_color = color.new(zc, 55), bgcolor = color.new(zc, isF ? 90 : 84)))
array.push(zLbl, label.new(x1, (top + bot) / 2, ztxt, style = label.style_label_right, color = color.new(color.black, 100), textcolor = color.new(zc, 0), size = lblSmall, tooltip = ztip))
array.push(zTop, top)
array.push(zBot, bot)
array.push(zDir, zd)
array.push(zKind, kind)
int cnt = 0
for j = 0 to array.size(zKind) - 1 by 1
if array.get(zKind, j) == kind
cnt := cnt + 1
cnt
if cnt > zoneKeep
for j = 0 to array.size(zKind) - 1 by 1
if array.get(zKind, j) == kind
f_zoneDel(j)
break
if array.size(zBox) > 0
for zi = array.size(zBox) - 1 to 0 by 1
zdead = array.get(zDir, zi) == 1 ? close < array.get(zBot, zi) : close > array.get(zTop, zi)
if zdead and barstate.isconfirmed
f_zoneDel(zi)
else
box.set_right(array.get(zBox, zi), bar_index + 8)
fvgUp = showFVG and barstate.isconfirmed and low > high[2] and close[1] > open[1] and low - high[2] >= 0.3 * atr
fvgDn = showFVG and barstate.isconfirmed and high < low[2] and close[1] < open[1] and low[2] - high >= 0.3 * atr
if fvgUp
f_zoneAdd(bar_index - 2, low, high[2], 1, 1)
if fvgDn
f_zoneAdd(bar_index - 2, low[2], high, -1, 1)
if showOB and brkStUp
int obK = na
for oi = 1 to 30 by 1
if close[oi] < open[oi]
obK := oi
break
if not na(obK)
f_zoneAdd(bar_index - obK, high[obK], low[obK], 1, 2)
if showOB and brkStDn
int obK2 = na
for oi = 1 to 30 by 1
if close[oi] > open[oi]
obK2 := oi
break
if not na(obK2)
f_zoneAdd(bar_index - obK2, high[obK2], low[obK2], -1, 2)
rngHi = ta.highest(high, pdLen)
rngLo = ta.lowest(low, pdLen)
rngMid = (rngHi + rngLo) / 2
pdPos = rngHi > rngLo ? (close - rngLo) / (rngHi - rngLo) : 0.5
f_below(array<float> a, float p) =>
float best = na
for i = 0 to array.size(a) - 1 by 1
v = array.get(a, i)
if not na(v) and v < p and (na(best) or v > best)
best := v
best
best
f_above(array<float> a, float p) =>
float best = na
for i = 0 to array.size(a) - 1 by 1
v = array.get(a, i)
if not na(v) and v > p and (na(best) or v < best)
best := v
best
best
useRnd = syminfo.type == 'forex'
rndStep = pip * 100
lvGap = 0.25 * nz(atrS, nz(atr))
rndBelow = math.floor((close - lvGap) / rndStep - 0.000000001) * rndStep
rndAbove = math.floor((close + lvGap) / rndStep + 0.000000001) * rndStep + rndStep
lv = array.from(useD ? pdh : na, useD ? pdl : na, useW ? pwh : na, useW ? pwl : na, useM ? pmh : na, useM ? pml : na, lastPH, prevPH, lastPL, prevPL, useRnd ? rndBelow : na, useRnd ? rndAbove : na)
lvlBelow = f_below(lv, close - lvGap)
lvlAbove = f_above(lv, close + lvGap)
mainDir = s240 < 0 and sD < 0 ? -1 : s240 > 0 and sD > 0 ? 1 : 0
smHi = ta.highest(high, 20)[1]
smLo = ta.lowest(low, 20)[1]
smSwUp = high > smHi and close < smHi
smSwDn = low < smLo and close > smLo
smUpAgo = nz(ta.barssince(smSwUp), 999)
smDnAgo = nz(ta.barssince(smSwDn), 999)
crRsi = ta.rsi(close, 14)
vixNow = request.security('TVC:VIX', 'D', close, ignore_invalid_symbol = true)
pbUpRun = nz(ta.barssince(close <= open))
pbDnRun = nz(ta.barssince(close >= open))
pbEndDn = dir == -1 and pbUpRun[1] >= 2 and close < low[1]
pbEndUp = dir == 1 and pbDnRun[1] >= 2 and close > high[1]
pbAgo = nz(ta.barssince(dir == -1 ? pbEndDn : pbEndUp), 999)
brk = mainDir == -1 ? lvlBelow : mainDir == 1 ? lvlAbove : na
rev = mainDir == -1 ? lvlAbove : mainDir == 1 ? lvlBelow : na
brkPrev = brk[1]
brokeDn = mainDir == -1 and not na(brkPrev) and close < brkPrev and close[1] >= brkPrev and barstate.isconfirmed
brokeUp = mainDir == 1 and not na(brkPrev) and close > brkPrev and close[1] <= brkPrev and barstate.isconfirmed
nearBrk = mainDir != 0 and not na(brk) and math.abs(close - brk) <= 0.5 * atr
nearRev = mainDir != 0 and not na(rev) and math.abs(close - rev) <= 0.5 * atr
advTxt = mainDir == 0 ? funny ? 'H4 and daily disagree.\nBest entry right now: no entry' : 'H4 and daily point in different directions.\nWait' : nearBrk ? 'Price is at the breakout point.\nWaiting for the candle to close' : nearRev ? 'Price is at the reversal point.\nA close beyond it cancels the plan' : mainDir == -1 ? pdPos <= 0.25 ? 'Trend is down, but price is already cheap.\nToo late to sell, wait for a pullback up' : pdPos >= 0.5 ? 'Trend is down and price is high.\nThis is where sells are looked for' : 'Trend is down.\nBetter to sell after a pullback higher' : pdPos >= 0.75 ? 'Trend is up, but price is already expensive.\nToo late to buy, wait for a pullback down' : pdPos <= 0.5 ? 'Trend is up and price is low.\nThis is where buys are looked for' : 'Trend is up.\nBetter to buy after a pullback lower'
advKind = mainDir == 0 ? 0 : nearBrk or nearRev ? 3 : mainDir == -1 ? pdPos <= 0.25 ? 2 : pdPos >= 0.5 ? 1 : 0 : pdPos >= 0.75 ? 2 : pdPos <= 0.5 ? 1 : 0
advBg = advKind == 1 ? mainDir == 1 ? #0F3B36 : #4A1F1F : advKind == 2 ? #4A3414 : advKind == 3 ? #16324F : #2A2E39
var box bxPrem = na
var box bxDisc = na
var line lnEq = na
var line lnRngH = na
var line lnRngL = na
var label lbPrem = na
var label lbDisc = na
var label lbEq = na
var label lbRngH = na
var label lbRngL = na
if barstate.islast
box.delete(bxPrem)
box.delete(bxDisc)
line.delete(lnEq)
line.delete(lnRngH)
line.delete(lnRngL)
label.delete(lbPrem)
label.delete(lbDisc)
label.delete(lbEq)
label.delete(lbRngH)
label.delete(lbRngL)
if showPD and not na(rngHi) and not na(rngLo)
pdX0 = math.max(bar_index - pdLen + 1, 0)
pdXa = math.max(bar_index - 12, 0)
pdX1 = bar_index + 44
premLo = rngHi - 0.25 * (rngHi - rngLo)
discHi = rngLo + 0.25 * (rngHi - rngLo)
tipRng = 'The range is measured over the last ' + str.tostring(pdLen) + ' bars of this timeframe: from this point to the current bar.\nThe top and the bottom of the range define the expensive and cheap zones.\nOn a higher timeframe (H4, daily) the range is wider and more reliable. The number of bars is set in the settings.'
lnRngH := line.new(pdX0, rngHi, pdX1, rngHi, color = color.new(cDn, 60), width = 1, style = line.style_dotted)
lnRngL := line.new(pdX0, rngLo, pdX1, rngLo, color = color.new(cUp, 60), width = 1, style = line.style_dotted)
lbRngH := label.new(pdX0, rngHi, 'range top, counted from here', style = label.style_label_down, color = color.new(color.black, 100), textcolor = cNeu, size = lblSmall, tooltip = tipRng)
lbRngL := label.new(pdX0, rngLo, 'range bottom', style = label.style_label_up, color = color.new(color.black, 100), textcolor = cNeu, size = lblSmall, tooltip = tipRng)
bxPrem := box.new(pdXa, rngHi, pdX1, premLo, border_color = color.new(cDn, 100), bgcolor = color.new(cDn, 88))
bxDisc := box.new(pdXa, discHi, pdX1, rngLo, border_color = color.new(cUp, 100), bgcolor = color.new(cUp, 88))
lnEq := line.new(pdXa, rngMid, pdX1, rngMid, color = color.new(cNeu, 40), width = 1, style = line.style_dashed)
lbPrem := label.new(pdX1, (rngHi + premLo) / 2, 'EXPENSIVE', style = label.style_label_left, color = color.new(color.black, 100), textcolor = cDn, size = lblBig, tooltip = 'Premium.\nThe upper quarter of the range of the last ' + str.tostring(pdLen) + ' bars. Price here is high relative to the recent past.\nWhat to do: buying here is a poor deal. If the trend is down, sells are looked for from here.')
lbDisc := label.new(pdX1, (rngLo + discHi) / 2, 'CHEAP', style = label.style_label_left, color = color.new(color.black, 100), textcolor = cUp, size = lblBig, tooltip = 'Discount.\nThe lower quarter of the range of the last ' + str.tostring(pdLen) + ' bars. Price here is low relative to the recent past.\nWhat to do: selling here is a poor deal. If the trend is up, buys are looked for from here.')
lbEq := label.new(pdX1, rngMid, 'MIDDLE', style = label.style_label_left, color = color.new(color.black, 100), textcolor = cNeu, size = lblBig, tooltip = 'Equilibrium, the fair price.\nThe middle of the range of the last ' + str.tostring(pdLen) + ' bars. Above it price counts as expensive, below it as cheap.\nWhat to do: do not enter right at the middle, nobody has an edge there.')
lbEq
var array<line> lvLines = array.new_line()
var array<label> lvLabels = array.new_label()
f_keyStyle(float y) =>
tl = math.abs(y - tStop) <= math.abs(y - tTarget) ? tStop : tTarget
inTrade ? y >= tl ? label.style_label_lower_left : label.style_label_upper_left : label.style_label_left
f_level(float y, string txt, color c, int w, string tip, bool key) =>
if not na(y)
x1 = math.max(bar_index - 60, 0)
array.push(lvLines, line.new(x1, y, bar_index + 16, y, color = c, width = w, style = w > 1 ? line.style_solid : line.style_dotted))
array.push(lvLabels, label.new(bar_index + 16, y, str.tostring(y, format.mintick) + ' ' + txt, style = key ? f_keyStyle(y) : label.style_label_left, color = color.new(color.black, 100), textcolor = c, size = key ? lblBig : lblSmall, tooltip = tip))
f_plain(float y, string txt, string tip) =>
if not na(y) and y != nz(lvlAbove) and y != nz(lvlBelow)
f_level(y, txt, color.new(cNeu, 30), 1, tip, false)
tipTail = '\nHow to read it: a candle CLOSED beyond the level means the breakout is real. Price went beyond the level and came back means a trap: stops were collected.'
tipDH = 'Yesterday\'s high.\nNobody wanted to buy above this price yesterday. Today it is the nearest resistance: price often reaches it and either bounces down or breaks through and speeds up.' + tipTail
tipDL = 'Yesterday\'s low.\nNobody wanted to sell below this price yesterday. Today it is the nearest support: price often reaches it and either bounces up or breaks through and speeds up.' + tipTail
tipWH = 'Last week\'s high.\nStronger than yesterday\'s level: large players watch it and many stops sit above it.' + tipTail
tipWL = 'Last week\'s low.\nStronger than yesterday\'s level: large players watch it and many stops sit below it.' + tipTail
tipMH = 'Last month\'s high.\nThe strongest of the three levels. Breakouts are rare and meaningful: the move after them often lasts days and weeks.' + tipTail
tipML = 'Last month\'s low.\nThe strongest of the three levels. Breakouts are rare and meaningful: the move after them often lasts days and weeks.' + tipTail
tipBrk = 'Breakout point.\nThe nearest level in the direction of the H4 and daily trend. If a candle closes beyond it, the move continues. Going beyond the level without a candle close does not count.'
tipRev = 'Reversal point.\nThe nearest level against the H4 and daily trend. If a candle closes beyond it, the trend plan is cancelled.'
tipEdge = 'Boundary.\nH4 and daily point in different directions, there is no common direction. These are the nearest levels above and below. While price is between them, it is better to wait.'
tipRnd = 'Round number.\nMany orders and stops gather at round prices (1.1000, 1.1100), so price often slows down or turns there.' + tipTail
if barstate.islast
while array.size(lvLines) > 0
line.delete(array.pop(lvLines))
while array.size(lvLabels) > 0
label.delete(array.pop(lvLabels))
if showLevels
if useD
f_plain(pdh, 'yesterday high', tipDH)
f_plain(pdl, 'yesterday low', tipDL)
if useW
f_plain(pwh, 'week high', tipWH)
f_plain(pwl, 'week low', tipWL)
if useM
f_plain(pmh, 'month high', tipMH)
f_plain(pml, 'month low', tipML)
if useRnd
f_plain(rndAbove, 'round number', tipRnd)
f_plain(rndBelow, 'round number', tipRnd)
if mainDir != 0
f_level(brk, mainDir == 1 ? 'BREAKOUT: a close above and the rise continues' : 'BREAKOUT: a close below and the fall continues', mainDir == 1 ? cUp : cDn, 2, tipBrk, true)
f_level(rev, mainDir == 1 ? 'REVERSAL: below this the plan is off' : 'REVERSAL: above this the plan is off', cRev, 2, tipRev, true)
else
f_level(lvlAbove, funny ? 'BOUNDARY: not going past it yet' : 'BOUNDARY above', cAcc, 2, tipEdge, true)
f_level(lvlBelow, funny ? 'BOUNDARY: not going past it yet' : 'BOUNDARY below', cAcc, 2, tipEdge, true)
f_tradeStyle(float y) =>
float dA = na(lvlAbove) ? na : math.abs(lvlAbove - y)
float dB = na(lvlBelow) ? na : math.abs(lvlBelow - y)
float k = na(dA) ? lvlBelow : na(dB) ? lvlAbove : dA <= dB ? lvlAbove : lvlBelow
na(k) or not showLevels ? label.style_label_left : k >= y ? label.style_label_upper_left : label.style_label_lower_left
var box bxRisk = na
var box bxGain = na
var line lnEntry = na
var line lnStop = na
var line lnTgt = na
var line lnT1 = na
var label lbT = na
var label lbS = na
if barstate.islast
box.delete(bxRisk)
box.delete(bxGain)
line.delete(lnEntry)
line.delete(lnStop)
line.delete(lnTgt)
line.delete(lnT1)
label.delete(lbT)
label.delete(lbS)
if inTrade
xr = bar_index + 10
xOpen = math.max(tOpenBar, bar_index - 400)
if showZones
bxRisk := box.new(xOpen, math.max(tEntry, tStop), xr, math.min(tEntry, tStop), border_color = color.new(cDn, 100), bgcolor = stopInProfit ? color.new(cUp, 82) : color.new(cDn, 86))
bxGain := box.new(xOpen, math.max(tEntry, tTarget), xr, math.min(tEntry, tTarget), border_color = color.new(cGood, 100), bgcolor = color.new(cGood, 90))
bxGain
lnEntry := line.new(xOpen, tEntry, xr, tEntry, color = color.new(color.white, 35), width = 1)
lnStop := line.new(xOpen, tStop, xr, tStop, color = cWarn, width = 2)
lnTgt := line.new(xOpen, tTarget, xr, tTarget, color = cGood, width = 2)
if useBE and not t1Done
lnT1 := line.new(xOpen, tT1, xr, tT1, color = color.new(cGood, 40), width = 1, style = line.style_dashed)
lnT1
maxR = useBE ? 0.5 + 0.5 * rr : rr
tgtUsd = maxR * tRisk * usdPerUnit * workLot
stpUsd = (t1Done ? 0.5 : 1.0) * tDir * (tStop - tEntry) * usdPerUnit * workLot + (t1Done ? 0.5 * tRisk * usdPerUnit * workLot : 0.0)
noteT = funny ? 'taking it and going for coffee' : 'taking profit here'
noteS = stopInProfit ? funny ? 'already in profit, cannot get worse' : 'stop is already in profit' : funny ? 'here I say oops and get out' : 'exit with a loss here'
txtT = 'TARGET ' + str.tostring(tTarget, format.mintick) + (na(usdPerUnit) ? '' : ' ' + f_money(tgtUsd)) + '\n' + noteT
txtS = 'STOP ' + str.tostring(tStop, format.mintick) + (na(usdPerUnit) ? '' : ' ' + f_money(stpUsd)) + '\n' + noteS
lbT := label.new(xr, tTarget, txtT, style = f_tradeStyle(tTarget), color = color.new(cGood, 5), textcolor = color.white, size = lblBig, tooltip = 'Target (take profit).\nThe price where the trade closes with a profit. It is twice as far from the entry as the stop. The amount is for the lot from the table.')
lbS := label.new(xr, tStop, txtS, style = f_tradeStyle(tStop), color = color.new(cWarn, 5), textcolor = color.white, size = lblBig, tooltip = 'Stop (stop loss).\nThe price where the trade closes if the market goes against you. The line follows price and never moves back. The amount is for the lot from the table.')
lbS
colPanel = #131722
colHead = #0B0E14
colDim = #8A93A6
var array<string> rwIco = array.new_string()
var array<string> rwLab = array.new_string()
var array<string> rwVal = array.new_string()
var array<string> rwTip = array.new_string()
var array<color> rwCol = array.new_color()
f_row(table t, int row, string ico, string lab, string val, color valCol, string tip) =>
array.push(rwIco, ico)
array.push(rwLab, lab)
array.push(rwVal, val)
array.push(rwCol, valCol)
array.push(rwTip, tip)
f_stTxt(int ev, float lvl) =>
at = na(lvl) ? '' : ': price closed ' + (ev > 0 ? 'above the high ' : 'below the low ') + str.tostring(lvl, format.mintick) + '. On the chart it is the line labelled ' + (math.abs(ev) == 2 ? 'CHoCH' : 'BOS')
ev == 1 ? 'rise continues (BOS)' + at : ev == 2 ? 'first sign of a turn UP (CHoCH)' + at : ev == -1 ? 'fall continues (BOS)' + at : ev == -2 ? 'first sign of a turn DOWN (CHoCH)' + at : 'no events yet'
f_smTxt(int md, bool smFresh, bool smZone) =>
md == 0 ? 'higher charts disagree: big money has not picked a side, wait' : smFresh ? md == -1 ? 'stops above the high were taken and price came back: a place to sell, wait for a down candle' : 'stops below the low were taken and price came back: a place to buy, wait for an up candle' : smZone ? md == -1 ? 'price is in the expensive half: this is where they sell. Wait for a stop run above or the end of a pullback' : 'price is in the cheap half: this is where they buy. Wait for a stop run below or the end of a pullback' : md == -1 ? 'price is in the cheap half (discount). Selling with the trend is possible but the stop is far. After a pullback up the stop is closer' : 'price is in the expensive half (premium). Buying with the trend is possible but the stop is far. After a pullback down the stop is closer'
f_smTip() =>
'Where to look for an entry by big-money logic.\nDirection comes from H4 and daily. Smart Money answers the second question: WHERE to enter.\n1. Sell only in the expensive half of the recent range, buy only in the cheap half.\n2. The best moment: price jumps beyond a recent high or low, collects the stops there and comes back.\n3. Then wait for a candle in the trend direction.\nIn the history test a stop run on its own, without the trend, lost money. So here it works only together with the trend.'
f_crTxt(int crKind, float rs) =>
v = 'RSI ' + str.tostring(rs, '0') + ' of 100'
crKind == 2 ? 'GREED (' + v + (funny ? '): everyone buys, afraid to be late. That does not hurt an uptrend' : '): everyone buys') : crKind == -2 ? 'FEAR (' + v + (funny ? '): everyone sells, afraid to miss out. That does not hurt a downtrend' : '): everyone sells') : crKind == 1 ? 'buyers are getting bolder (' + v + '), no panic' : crKind == -1 ? 'sellers are getting bolder (' + v + '), no panic' : 'calm (' + v + '), nobody is running anywhere'
f_crTip() =>
'Crowd mood on this chart: fear or greed.\nMeasured by the speed of price over 14 candles (RSI): above 70 greed, below 30 fear.\nSource: only the price of this chart, no outside fear indexes.\nHistory test: in fear and greed the trend continued no worse and no better than usual. The row shows the mood, it is not a signal by itself.'
f_nwTxt() =>
newsS == 'Fed rate' ? 'Fed rate decision (evening, usually 14:00 New York). No entries an hour before and after. Open trade: stop to breakeven or close' : newsS == 'ECB rate' ? 'ECB rate decision (usually 8:15 New York, speech at 8:45). No entries from 7:30 to 10:00' : newsS == 'US jobs' ? 'US jobs report (usually 8:30 New York). Price is thrown both ways: no entries until 9:30' : newsS == 'inflation' ? 'inflation (US usually 8:30 New York). The first spike is often false: wait an hour and a candle close' : newsS == 'politician spoke' ? funny ? 'someone important said something. A spike on words often fades: do not chase, wait for the H4 close' : 'politician statement: do not chase the spike, wait for the H4 close' : 'big news: no entries an hour before and after, smaller size than usual'
f_nwTip() =>
'The indicator cannot read the news. Today\'s main event is picked in the settings, section My trade.\nTimes are the usual ones, check them against a calendar before trading.'
f_smcRows(table t, int r0, int md, float pos, int upAgo, int dnAgo, float rs) =>
smFresh = md == -1 ? upAgo <= 5 : md == 1 ? dnAgo <= 5 : false
smZone = md == -1 ? pos >= 0.5 : md == 1 ? pos <= 0.5 : false
f_row(t, r0, '🏦', 'Smart Money', f_smTxt(md, smFresh, smZone), md == 0 ? cNeu : smFresh ? cGood : smZone ? color.white : cWarn, f_smTip())
crKind = rs >= 70 ? 2 : rs <= 30 ? -2 : rs >= 60 ? 1 : rs <= 40 ? -1 : 0
f_row(t, r0 + 1, '👥', 'Crowd', f_crTxt(crKind, rs), math.abs(crKind) == 2 ? cWarn : color.white, f_crTip())
if newsS != 'none'
f_row(t, r0 + 2, '📰', 'News', f_nwTxt(), cWarn, f_nwTip())
newsS != 'none' ? 3 : 2
f_vixRow(table t, int r0, float v) =>
k = na(v) ? -1 : v < 15 ? 0 : v < 20 ? 1 : v < 30 ? 2 : 3
txt = k == -1 ? 'no VIX data on this TradingView account' : 'VIX ' + str.tostring(v, '0.0') + ' · ' + (k == 0 ? 'calm: big money is relaxed, markets move smoothly' : k == 1 ? 'normal: an ordinary working mood' : k == 2 ? 'NERVOUS: money leaves risk, moves are sharper, the dollar more often rises' : 'PANIC: markets shake, spreads widen, stops slip. Trade smaller or stay out')
f_row(t, r0, '😱', 'Fear index', txt, k == 3 ? cDn : k == 2 ? cWarn : k == -1 ? cNeu : color.white, 'VIX, the fear index from the Chicago exchange. It shows what swings big players expect in US stocks over the next month. Updates once a day.\nBelow 15: calm. 15–20: normal. 20–30: nervous. Above 30: panic.\nFor forex: when fear rises, money usually runs to the dollar, yen and franc, while the euro, pound and aussie weaken. This is a general observation, not tested on my own data.\nThe Crowd row is measured on this chart, this row shows fear across the whole market.')
1
f_pbRow(table t, int r0, int d, int upRun, int dnRun, int ago) =>
run = d == -1 ? upRun : dnRun
txt = d == 0 ? 'no trend, nothing to measure a pullback from' : ago <= 3 ? d == -1 ? 'ENDED: the up candles are beaten by a down candle. Signal to continue DOWN, stop above the pullback high' : 'ENDED: the down candles are beaten by an up candle. Signal to continue UP, stop below the pullback low' : run >= 2 ? d == -1 ? 'running: ' + str.tostring(run) + ' candles up against the trend. Wait for a candle that closes below the previous one' : 'running: ' + str.tostring(run) + ' candles down against the trend. Wait for a candle that closes above the previous one' : 'no pullback, price runs with the trend. You can enter now but the stop is far. After a pullback it is closer'
f_row(t, r0, '↩️', 'Pullback', txt, d == 0 ? cNeu : ago <= 3 ? cGood : run >= 2 ? cWarn : color.white, 'Pullback: a few candles against the trend, after which price goes with the trend again.\nEnd of a pullback: two or more candles against the trend, then a candle closes beyond the previous one in the trend direction.\nHistory test, target twice the stop: on the daily chart +0.14 risk per trade (410 trades, four instruments), on H4 about +0.05 (575 trades). The target is hit in about 4 cases of 10, the rest stop out: the profit comes from target size, not from frequency.')
1
f_pbMark(bool dn, color c) =>
label.new(bar_index, dn ? high : low, dn ? 'pullback over ↓' : 'pullback over ↑', yloc = dn ? yloc.abovebar : yloc.belowbar, style = label.style_none, textcolor = c, size = size.small)
f_scMark(bool dn, color c) =>
label.new(bar_index, dn ? high : low, dn ? 'scalp ↓' : 'scalp ↑', yloc = dn ? yloc.abovebar : yloc.belowbar, style = dn ? label.style_label_down : label.style_label_up, color = c, textcolor = color.white, size = size.small)
f_scRow(table t, int r0, bool on, bool tm, int d, float ent, float stp, float tgt, int ago, int md) =>
upRun = close[1] > open[1] and close > open
dnRun = close[1] < open[1] and close < open
live = ago <= 30 and d != 0
hit = live and (d == 1 ? close >= tgt or close <= stp : close <= tgt or close >= stp)
agr = md == 0 ? '' : md == d ? ' · with the H4 trend' : ' · AGAINST the H4 trend'
txt = not tm ? 'not the time: signals only in London and New York hours, 07:00–17:00 UTC' : live and not hit ? (d == -1 ? 'ENTRY DOWN from ' : 'ENTRY UP from ') + str.tostring(ent, format.mintick) + ' · stop ' + str.tostring(stp, format.mintick) + ' (' + f_pips(math.abs(ent - stp) / pip) + ') · target ' + str.tostring(tgt, format.mintick) + agr + ' · candles passed: ' + str.tostring(ago) + ' of 30' : upRun ? 'get ready: candles go up. Signal DOWN if a candle closes below the previous one' : dnRun ? 'get ready: candles go down. Signal UP if a candle closes above the previous one' : 'wait: two candles in a row in one direction are needed'
if on
f_row(t, r0, '⚡', 'Scalping', txt, not tm ? cNeu : live and not hit ? d == 1 ? cUp : cDn : upRun or dnRun ? cWarn : color.white, 'Scalping for the one- and five-minute chart.\nRule: two candles in a row in one direction, then a candle closes beyond the previous one the other way. Entry at that close.\nStop beyond these three candles (only if it is 3 to 8 pips), target one and a half stops, not done in 30 candles: exit. On the chart it is the scalp mark and two dotted lines: stop and target.\nOne-month test on EUR/USD minute history (219 trades): about +0.4 pips per trade at a 1 pip spread and +0.8 at 0.6. That is small and not proven: above a 1 pip spread the rule loses. Check your spread before entering.\nMean reversion, moving-average crosses and stop runs on minutes lost in the same test, so they are not here.')
on ? 1 : 0
f_arrow(int s) =>
s > 0 ? '▲' : s < 0 ? '▼' : '–'
[dayHi, dayLo] = request.security(syminfo.tickerid, 'D', [high, low])
adrDay = request.security(syminfo.tickerid, 'D', ta.sma(high - low, 20)[1], lookahead = barmerge.lookahead_on)
var int lossToday = 0
if ta.change(time('D')) != 0
lossToday := 0
lossToday
if closedNow and res < 0
lossToday := lossToday + 1
lossToday
f_left(int ms) =>
s = math.floor(math.max(ms, 0) / 1000.0)
m = math.floor(s / 60.0)
hh = math.floor(m / 60.0)
mm = m - hh * 60
ss = s - m * 60
m >= 5 ? (hh > 0 ? str.tostring(hh, '0') + ' h ' : '') + str.tostring(mm, '0') + ' min' : m >= 1 ? str.tostring(m, '0') + ' min ' + str.tostring(ss, '0') + ' sec' : str.tostring(ss, '0') + ' sec'
var array<int> evT = array.from(1794848400000, 1794922200000, 1794996000000, 1795028400000, 1796391000000, 1796842800000, 1796909400000, 1797513300000, 1799415000000, 1799847000000, 1801076400000, 1801746900000, 1801834200000, 1802352600000, 1804253400000, 1804685400000, 1805306400000, 1805375700000)
var array<int> evK = array.from(5, 6, 8, 7, 3, 1, 4, 2, 3, 4, 1, 2, 3, 4, 3, 4, 1, 2)
f_nbRow(table t, int r0, table nt) =>
parts = str.split(str.replace_all(nbTxt, ',', '.'), ' ')
array<float> v = array.new_float()
for i = 0 to array.size(parts) - 1 by 1
x = str.tonumber(array.get(parts, i))
if not na(x)
array.push(v, x)
n = array.size(v)
float sm = 0.0
int w = 0
float bst = na
float wst = na
if n > 0
for i = 0 to n - 1 by 1
x = array.get(v, i)
sm := sm + x
w := w + (x > 0 ? 1 : 0)
bst := na(bst) ? x : math.max(bst, x)
wst := na(wst) ? x : math.min(wst, x)
wst
txt = n == 0 ? 'empty. Enter trade results in the settings, section My trade' : 'trades ' + str.tostring(n) + ' · wins ' + str.tostring(w) + ' (' + str.tostring(100.0 * w / n, '0') + '%) · ' + 'total ' + f_money(sm) + ' · best ' + f_money(bst) + ' · worst ' + f_money(wst)
f_row(t, r0, '📓', 'Notebook', txt, n == 0 ? cNeu : sm >= 0 ? cUp : cDn, 'Your trading notebook. The indicator cannot see the account, so the result of each closed trade is typed in the settings: numbers in dollars separated by spaces, a loss with a minus sign.\nThe row shows the totals, the separate window at the bottom centre lists the last 15 trades in order.')
if nbShow and n > 0
table.cell(nt, 0, 0, 'Notebook', text_color = color.white, bgcolor = colHead, text_size = txtSize)
table.cell(nt, 1, 0, 'result', text_color = colDim, bgcolor = colHead, text_size = txtSize)
table.cell(nt, 2, 0, 'total', text_color = colDim, bgcolor = colHead, text_size = txtSize)
fr0 = math.max(0, n - 15)
float run = 0.0
for i = 0 to n - 1 by 1
x = array.get(v, i)
run := run + x
if i >= fr0
rw = i - fr0 + 1
table.cell(nt, 0, rw, '№ ' + str.tostring(i + 1), text_color = colDim, bgcolor = colPanel, text_size = txtSize)
table.cell(nt, 1, rw, f_money(x), text_color = x >= 0 ? cUp : cDn, bgcolor = colPanel, text_size = txtSize, text_halign = text.align_right)
table.cell(nt, 2, rw, f_money(run), text_color = run >= 0 ? cUp : cDn, bgcolor = colPanel, text_size = txtSize, text_halign = text.align_right)
1
f_calRow(table t, int r0) =>
int ix = na
for i = 0 to array.size(evT) - 1 by 1
if na(ix) and array.get(evT, i) > timenow - 3600000
ix := i
ix
string txt = 'the event calendar has ended (March 2027): a new indicator version is needed'
color c = cNeu
if not na(ix)
et = array.get(evT, ix)
k = array.get(evK, ix)
left = et - timenow
nm = k == 1 ? 'Fed rate decision (US)' : k == 2 ? 'ECB rate decision (Europe)' : k == 3 ? 'US jobs report' : k == 4 ? 'US inflation' : k == 5 ? 'Fed chair speech' : k == 6 ? 'US retail sales' : k == 7 ? 'Fed minutes' : 'eurozone inflation'
pw = k <= 4 ? ' · impact: VERY STRONG' : k == 5 ? ' · impact: strong if he says something new on rates' : ' · impact: medium'
nt = et == 1796842800000 ? '. The market already expects +0.25. Surprise: +0.50 (dollar sharply up) or a soft tone (dollar down)' : et == 1797513300000 ? '. A hike is about 2 in 3. No hike: euro down' : ''
whn = str.format_time(et, 'dd.MM HH:mm', tzIn)
txt := left < 0 ? nm + ' is just out. No entries for an hour: price is thrown both ways' : left <= 86400000 ? 'TODAY ' + nm + pw + nt + ': ' + whn + ', in ' + f_left(left) + '. No entries an hour before and after' : 'next: ' + nm + pw + nt + ', ' + whn + ' your time, in ' + str.tostring(math.floor(left / 86400000)) + ' d'
c := left <= 86400000 ? cWarn : color.white
c
f_row(t, r0, '📅', 'Events', txt, c, 'The main scheduled news for EUR/USD: Fed and ECB rate decisions, US jobs and inflation. Dates are built in from the official Fed, ECB and US labor statistics calendars, through March 2027.\nSudden news (politicians, wars, accidents) cannot be known: TradingView does not let scripts read the internet. Mark those by hand in the settings, section My trade.')
1
nyTz = 'America/New_York'
hrMs = 3600000
nyH = hour(timenow, nyTz)
nyDow = dayofweek(timenow, nyTz)
nyMid = timestamp(nyTz, year(timenow, nyTz), month(timenow, nyTz), dayofmonth(timenow, nyTz), 0, 0, 0)
isWeekend = syminfo.type != 'crypto' and (nyDow == dayofweek.saturday or nyDow == dayofweek.sunday and nyH < 17 or nyDow == dayofweek.friday and nyH >= 17)
sessId = nyH >= 17 or nyH < 3 ? 0 : nyH < 8 ? 1 : nyH < 12 ? 2 : 3
sessName = sessId == 0 ? 'Asia' : sessId == 1 ? 'London' : sessId == 2 ? 'London and New York' : 'New York'
sessStart = sessId == 0 ? nyH >= 17 ? nyMid + 17 * hrMs : nyMid - 7 * hrMs : sessId == 1 ? nyMid + 3 * hrMs : sessId == 2 ? nyMid + 8 * hrMs : nyMid + 12 * hrMs
sessEnd = sessId == 0 ? nyH >= 17 ? nyMid + 27 * hrMs : nyMid + 3 * hrMs : sessId == 1 ? nyMid + 8 * hrMs : sessId == 2 ? nyMid + 12 * hrMs : nyMid + 17 * hrMs
clockTxt = str.format_time(timenow, 'HH:mm:ss', tzIn)
sessHours = str.format_time(sessStart, 'HH:mm', tzIn) + '–' + str.format_time(sessEnd, 'HH:mm', tzIn)
daysToOpen = nyDow == dayofweek.friday ? 2 : nyDow == dayofweek.saturday ? 1 : 0
openTs = nyMid + daysToOpen * 24 * hrMs + 17 * hrMs
openDow = dayofweek(openTs, tzIn)
dowTxt = openDow == dayofweek.monday ? 'on Monday' : openDow == dayofweek.sunday ? 'on Sunday' : 'on Saturday'
sessOpen = sessName + ' ' + sessHours + ' · ends in ' + f_left(sessEnd - timenow)
sessShut = (funny ? 'weekend, the market sleeps. It opens ' : 'weekend. The market opens ') + dowTxt + ' ' + str.format_time(openTs, 'HH:mm', tzIn) + ', in ' + f_left(openTs - timenow)
nyClock = str.format_time(timenow, 'HH:mm', nyTz)
clockFull = tzIn == nyTz ? clockTxt : clockTxt + ' your time, ' + nyClock + ' in New York'
sessTxt = clockFull + ' · ' + (isWeekend ? sessShut : sessOpen)
sessCol = isWeekend ? cNeu : sessId == 2 ? cGood : color.white
tipSess = 'The time and the current trading session, in your clock time.\nAsia: quiet market, entries rarely work.\nLondon: the main move of the day usually starts here.\nLondon and New York: the most active hours.\nNew York: the move fades in the second half.\nThe time zone is set in the settings.'
barLeft = time_close - timenow
candleTxt = barLeft > 0 and not isWeekend ? 'closes in ' + f_left(barLeft) + '. A signal counts only after the close' : 'the last candle is closed, a new one starts when the market opens'
tipCandle = 'Time left until the current candle closes.\nBreakouts and reversals count only on a candle close, so decisions are made after that moment.'
isLate = nyH >= 14 and nyH < 17
dayRng = dayHi - dayLo
dayUsed = adrDay > 0 ? dayRng / adrDay : na
usedTxt = 'moved today ' + f_pips(dayRng / pip) + ' of the usual ' + str.tostring(adrDay / pip, '0')
dayKind = isWeekend ? 0 : lossToday >= 2 ? 4 : nz(dayUsed) >= 1.0 ? 2 : isLate ? 3 : nz(dayUsed) >= 0.8 ? 1 : 5
hintDone = funny ? 'the daily norm is done. Take it and go have dinner' : 'the daily norm is done, take profit'
dayHint = dayKind == 0 ? 'market closed' : dayKind == 4 ? 'two losing trades. Done for today' : dayKind == 2 ? hintDone : dayKind == 3 ? 'evening, no new entries' : dayKind == 1 ? 'almost no room left, do not start a new trade' : 'there is still room to move'
dayTxt = isWeekend ? dayHint : usedTxt + ' · ' + dayHint
dayCol = dayKind == 0 ? cNeu : dayKind == 4 ? cDn : dayKind == 5 ? color.white : cWarn
tipDay = 'How many pips price has covered today and how many it usually covers (the average range of the last 20 days).\nHourly history test on EUR/USD, 718 days:\nby 10:00 New York the day has usually done 95% of its move;\nby 14:00 New York the high and the low of the day are final in 77% of days;\nonce the day has done its usual move, holding a trade until the end of the day adds nothing on average.\nThe indicator cannot know the best price of the day. It shows when waiting longer stops paying.'
bodyB = math.abs(close - open)
rngB = high - low
lwickB = math.min(open, close) - low
uwickB = high - math.max(open, close)
engBull = close > open and close[1] < open[1] and close >= open[1] and open <= close[1] and bodyB > math.abs(close[1] - open[1]) and rngB >= 0.7 * atr
engBear = close < open and close[1] > open[1] and close <= open[1] and open >= close[1] and bodyB > math.abs(close[1] - open[1]) and rngB >= 0.7 * atr
pinBull = rngB >= 0.7 * atr and lwickB >= 0.6 * rngB and uwickB <= 0.2 * rngB
pinBear = rngB >= 0.7 * atr and uwickB >= 0.6 * rngB and lwickB <= 0.2 * rngB
insideB = high < high[1] and low > low[1]
bodyB1 = math.abs(close[1] - open[1])
bodyB2 = math.abs(close[2] - open[2])
starBull = close[2] < open[2] and bodyB2 >= 0.5 * atr and bodyB1 <= 0.35 * bodyB2 and close > open and close > (open[2] + close[2]) / 2
starBear = close[2] > open[2] and bodyB2 >= 0.5 * atr and bodyB1 <= 0.35 * bodyB2 and close < open and close < (open[2] + close[2]) / 2
solBull = close > open and close[1] > open[1] and close[2] > open[2] and close > close[1] and close[1] > close[2] and bodyB >= 0.4 * atr and bodyB1 >= 0.4 * atr and bodyB2 >= 0.4 * atr
solBear = close < open and close[1] < open[1] and close[2] < open[2] and close < close[1] and close[1] < close[2] and bodyB >= 0.4 * atr and bodyB1 >= 0.4 * atr and bodyB2 >= 0.4 * atr
patCode = starBull ? 4 : starBear ? -4 : engBull ? 1 : engBear ? -1 : pinBull ? 2 : pinBear ? -2 : solBull ? 5 : solBear ? -5 : insideB ? 3 : 0
patLast = nz(patCode[1]) != 0 ? nz(patCode[1]) : nz(patCode[2]) != 0 ? nz(patCode[2]) : nz(patCode[3])
patAge = nz(patCode[1]) != 0 ? 1 : nz(patCode[2]) != 0 ? 2 : nz(patCode[3]) != 0 ? 3 : 0
patDir = patLast == 3 or patLast == 0 ? 0 : patLast > 0 ? 1 : -1
patName = patLast == 1 ? 'bullish engulfing' : patLast == -1 ? 'bearish engulfing' : patLast == 2 ? 'hammer (bullish pin bar)' : patLast == -2 ? 'shooting star (bearish pin bar)' : patLast == 3 ? 'inside bar' : patLast == 4 ? 'morning star' : patLast == -4 ? 'evening star' : patLast == 5 ? 'three white soldiers' : patLast == -5 ? 'three black crows' : ''
patWhen = patAge == 1 ? 'on the last candle' : patAge == 2 ? '2 candles ago' : '3 candles ago'
patNote = patLast == 3 ? 'the market is squeezed, wait for the exit' : mainDir == 0 ? 'no common direction, does not count' : patDir == mainDir ? 'with the trend, supports the plan' : 'against the trend, skip it'
patTxt = patAge == 0 ? 'nothing notable in the last 3 candles' : patName + ', ' + patWhen + ' · ' + patNote
patCol = patAge == 0 ? cNeu : patLast == 3 ? color.white : patDir == mainDir and mainDir != 0 ? cGood : cNeu
tipPat = 'Candlestick patterns on closed candles of this timeframe.\nEngulfing: the candle fully covered the body of the previous one in the other direction.\nPin bar: a long tail on one side, price was rejected there.\nInside bar: the whole candle sits inside the previous one, the market is squeezed.\nMorning and evening star: a big candle, a small one and a big one the other way.\nThree soldiers and three crows: three confident candles in a row in one direction.\nHistory test (engulfing and pin bar, H4, six instruments, with spread): engulfing alone gives no result, the pin bar is negative. So this is a hint for the overall picture, not a signal.'
var array<label> patLabels = array.new_label()
if showPat and barstate.isconfirmed and patCode != 0 and patCode != 3
patUp = patCode > 0
patMark = math.abs(patCode) == 1 ? 'engulfing' : patCode == 2 ? 'hammer' : patCode == -2 ? 'shooting star' : patCode == 4 ? 'morning star' : patCode == -4 ? 'evening star' : patCode == 5 ? 'three soldiers' : 'three crows'
array.push(patLabels, label.new(bar_index, patUp ? low : high, patMark, yloc = patUp ? yloc.belowbar : yloc.abovebar, style = label.style_none, textcolor = color.new(patUp ? cUp : cDn, 15), size = size.tiny, tooltip = tipPat))
if showPat and barstate.isconfirmed and (pbEndDn or pbEndUp)
array.push(patLabels, f_pbMark(pbEndDn, pbEndDn ? cDn : cUp))
scOn = tfSec <= 300 and syminfo.type == 'forex'
scHr = hour(time, 'UTC')
scTime = scHr >= 7 and scHr < 17
scStD = math.max(high, high[1], high[2]) + 0.3 * pip
scStU = math.min(low, low[1], low[2]) - 0.3 * pip
scDn = scOn and scTime and close[1] > open[1] and close[2] > open[2] and close < low[1] and scStD - close >= 3 * pip and scStD - close <= 8 * pip
scUp = scOn and scTime and close[1] < open[1] and close[2] < open[2] and close > high[1] and close - scStU >= 3 * pip and close - scStU <= 8 * pip
var int scDir = 0
var float scEnt = na
var float scStp = na
var float scTgt = na
var int scBar = na
var line scL1 = na
var line scL2 = na
if barstate.isconfirmed and (scDn or scUp)
scDir := scDn ? -1 : 1
scEnt := close
scStp := scDn ? scStD : scStU
scTgt := close + scDir * 1.5 * math.abs(close - scStp)
scBar := bar_index
line.delete(scL1)
line.delete(scL2)
scL1 := line.new(bar_index, scStp, bar_index + 30, scStp, color = cWarn, style = line.style_dotted)
scL2 := line.new(bar_index, scTgt, bar_index + 30, scTgt, color = cGood, style = line.style_dotted)
if showPat
array.push(patLabels, f_scMark(scDn, scDn ? cDn : cUp))
if array.size(patLabels) > 24
label.delete(array.shift(patLabels))
atrAvg = ta.sma(atr, 100)
wRatio = atrAvg > 0 ? atr / atrAvg : na
wKind = na(wRatio) ? 1 : wRatio < 0.7 ? 0 : wRatio < 1.25 ? 1 : wRatio < 1.8 ? 2 : 3
wIcon = wKind == 0 ? '😴' : wKind == 1 ? '🌤' : wKind == 2 ? '💨' : '⛈'
wTxt = wKind == 0 ? 'calm: candles are smaller than usual, the market is dozing' : wKind == 1 ? 'this is the usual size' : wKind == 2 ? 'windy: candles are bigger than usual, the stop needs more room' : 'storm: candles are almost twice the usual size. Better wait it out'
wCol = wKind == 0 ? cNeu : wKind == 1 ? color.white : wKind == 2 ? cWarn : cDn
tipW = 'Market weather: candle size now versus the 100-bar average (measured by ATR).\nCalm: little movement, breakouts often fail.\nWindy and storm: price swings wide and a usual stop gets hit more often.\nThe size of a usual candle right now is in brackets.'
tfName = tfSec < 3600 ? 'M' + str.tostring(tfSec / 60) : tfSec < 86400 ? 'H' + str.tostring(tfSec / 3600) : timeframe.period
var table nbT = table.new(position.bottom_center, 3, 17, bgcolor = colPanel, frame_color = color.new(cAcc, 45), frame_width = 1, border_width = 0)
var table tb = table.new(tblPos, 3, 36, bgcolor = colPanel, frame_color = color.new(cAcc, 45), frame_width = 1, border_width = 0)
if barstate.islast
array.clear(rwIco)
array.clear(rwLab)
array.clear(rwVal)
array.clear(rwCol)
array.clear(rwTip)
table.cell(tb, 0, 0, 'TrendVote 29 · ' + syminfo.ticker + ' · ' + tfName + (useSigTf ? ' · trend from H4' : ''), text_color = cAcc, bgcolor = colHead, text_size = txtSize, text_halign = text.align_left)
table.cell(tb, 1, 0, '', bgcolor = colHead)
table.cell(tb, 2, 0, '', bgcolor = colHead)
table.merge_cells(tb, 0, 0, 2, 0)
table.cell(tb, 0, 1, advTxt, text_color = color.white, bgcolor = advBg, text_size = hdSize, text_halign = text.align_left, tooltip = 'Main advice.\nBuilt from three things: the H4 and daily direction, where price sits inside the range, and whether a key level is close.\nIt is a hint, not a signal and not a guarantee.')
table.cell(tb, 1, 1, '', bgcolor = advBg)
table.cell(tb, 2, 1, '', bgcolor = advBg)
table.merge_cells(tb, 0, 1, 2, 1)
int r = 2
votesNum = math.round((7 + math.abs(scoreS)) / 2)
strTxt = adxS > 30 ? 'strong trend' : adxS > adxThr ? 'trend present' : 'weak trend'
f_row(tb, r, dir == 1 ? '🐂' : dir == -1 ? '🐻' : '☕', 'Trend', (dir == 1 ? 'UP' : dir == -1 ? 'DOWN' : 'WAIT') + ' · ' + str.tostring(votesNum) + ' of 7 ' + (scoreS > 0 ? 'for up' : 'for down') + ' · ' + strTxt, dirCol, 'Seven indicators vote on where the market is going on the signal timeframe. Trend strength comes from ADX: above 30 is strong, below the threshold is weak.\nThis is a direction, not an entry point: the arrow comes when most of the move is already done.')
r := r + 1
allUp = s15 > 0 and s60 > 0 and s240 > 0 and sD > 0
allDn = s15 < 0 and s60 < 0 and s240 < 0 and sD < 0
f_row(tb, r, '⏱', 'Timeframes', 'M15 ' + f_arrow(s15) + ' H1 ' + f_arrow(s60) + ' H4 ' + f_arrow(s240) + ' D ' + f_arrow(sD), allUp ? cUp : allDn ? cDn : color.white, 'Where four timeframes point. When all point one way, do not go against them.')
r := r + 1
if showSMC
stTxt = f_stTxt(lastEv, lastEvLvl)
f_row(tb, r, '🧱', 'Structure', stTxt, math.abs(lastEv) == 2 ? cWarn : lastEv > 0 ? cUp : lastEv < 0 ? cDn : color.white, 'The latest market structure event on this timeframe: the previous swing high or low was broken.\nContinuation is called BOS, a sign of reversal is called CHoCH.')
r := r + 1
r
f_row(tb, r, '🔎', 'Pattern', patTxt, patCol, tipPat)
r := r + 1
pdN = str.tostring(pdLen)
pdWhere = pdPos >= 0.75 ? 'EXPENSIVE (premium): near the top of the last ' + pdN + ' bars' : pdPos <= 0.25 ? 'CHEAP (discount): near the bottom of the last ' + pdN + ' bars' : pdPos > 0.5 ? 'slightly above the middle of the last ' + pdN + ' bars. The middle (equilibrium): neither expensive nor cheap' : 'slightly below the middle of the last ' + pdN + ' bars. The middle (equilibrium): neither expensive nor cheap'
f_row(tb, r, '📍', 'Price', pdWhere, pdPos >= 0.75 ? cDn : pdPos <= 0.25 ? cUp : color.white, 'Price is compared with the highest and the lowest price of the last bars of this timeframe.\nNear the bottom: cheap, too late to sell.\nNear the top: expensive, too late to buy.\nThe number of bars is set in the settings.')
r := r + 1
r := r + f_smcRows(tb, r, mainDir, pdPos, smUpAgo, smDnAgo, crRsi)
r := r + f_pbRow(tb, r, dir, pbUpRun, pbDnRun, pbAgo)
r := r + f_scRow(tb, r, scOn, scTime, scDir, scEnt, scStp, scTgt, na(scBar) ? 999 : bar_index - scBar, mainDir)
r := r + f_vixRow(tb, r, vixNow)
r := r + f_calRow(tb, r)
if showLevels
lvUp = mainDir == -1 ? rev : mainDir == 1 ? brk : lvlAbove
lvDn = mainDir == -1 ? brk : mainDir == 1 ? rev : lvlBelow
upTxt = mainDir == -1 ? 'the sell plan is off, wait' : mainDir == 1 ? 'the rise continues' : 'an up direction appears'
dnTxt = mainDir == -1 ? 'the fall continues' : mainDir == 1 ? 'the buy plan is off, wait' : 'a down direction appears'
tipIf = 'Two scenarios from the nearest levels.\nIf a candle closes beyond the level in the trend direction, the move continues.\nIf it closes beyond the level against the trend, the trend plan is cancelled.\nOnly a candle close beyond the level counts: a poke and return does not.\nLevels that are too close are skipped: closer than a quarter of a usual candle is noise.\nLevels come from yesterday, last week, last month, recent swing highs and lows and round numbers.'
f_row(tb, r, '⬆️', 'If above', na(lvUp) ? 'no level above: price has not been this high on this chart' : str.tostring(lvUp, format.mintick) + ' → ' + upTxt + ' · distance ' + f_pips(math.abs(lvUp - close) / pip), mainDir == 1 ? cUp : mainDir == -1 ? cWarn : color.white, tipIf)
r := r + 1
f_row(tb, r, '⬇️', 'If below', na(lvDn) ? 'no level below: price has not been this low on this chart' : str.tostring(lvDn, format.mintick) + ' → ' + dnTxt + ' · distance ' + f_pips(math.abs(close - lvDn) / pip), mainDir == -1 ? cDn : mainDir == 1 ? cWarn : color.white, tipIf)
r := r + 1
r
myDir = myDirS == 'buy' ? 1 : myDirS == 'sell' ? -1 : 0
myTip = 'Your real trade. The indicator cannot see the broker account, so the direction, entry price and size are set in the settings, section My trade. The entry price is easy to pick on the chart with the crosshair.\nTrade closed: enter the exit price and the row shows the result.\nFor an open sell the spread from the settings is subtracted, so the amount may differ from the broker by a few cents.'
if myDir != 0 and myEntry > 0
myOk = math.abs(close - myEntry) / close < 0.2
myDone = myExit > 0
myPx = myDone ? myExit : close
myPips = myDir == 1 ? (myPx - myEntry) / pip : (myEntry - myPx) / pip - (myDone ? 0 : costPips)
myUsd = myPips * pip * usdPerUnit * myLots
myHead = (myDone ? 'closed: ' : '') + (myDir == 1 ? 'BUY ' : 'SELL ') + str.tostring(myLots, '0.00') + ' from ' + str.tostring(myEntry, format.mintick) + (myDone ? ' to ' + str.tostring(myExit, format.mintick) : '')
myTxt = not myOk ? 'the entry price is not from this instrument, fix it in the settings' : myHead + ' · ' + (myPips >= 0 ? '+' : '') + f_pips(myPips) + (na(myUsd) ? '' : ' ' + f_money(myUsd))
f_row(tb, r, '💼', 'My trade', myTxt, not myOk ? cNeu : myPips >= 0 ? cUp : cDn, myTip)
r := r + 1
r
else
f_row(tb, r, '💼', 'My trade', 'not set. Settings, section My trade: direction and entry price', cNeu, myTip)
r := r + 1
r
table.clear(nbT, 0, 0, 2, 16)
r := r + f_nbRow(tb, r, nbT)
floatPips = tDir == 1 ? (close - tEntry) / pip : tDir == -1 ? (tEntry - close) / pip : 0.0
floatUsd = floatPips * pip * usdPerUnit * workLot
floatTxt = (floatPips >= 0 ? '+' : '') + f_pips(floatPips) + (na(floatUsd) ? '' : ' ' + f_money(floatUsd))
floatR = tDir != 0 and tRisk > 0 ? floatPips * pip / tRisk : 0.0
phr = int(math.floor(timenow / 1800000.0)) % 3
trState = tDir == 0 ? pendL or pendS ? 7 : dir != 0 ? 8 : 9 : floatR >= 1.6 ? 4 : floatR >= 1.0 ? 3 : floatR >= 0.15 ? 2 : floatR > -0.15 ? 1 : floatR > -0.5 ? 5 : 6
fun1 = f_pick(phr, 'just got in, buckle up', 'trade is open, let it breathe', 'off we go. Now the main thing is not to fidget')
fun2 = f_pick(phr, 'running in profit. Hands off', 'going the right way. Hands off the mouse', 'dripping in slowly. Let it drip')
fun3 = f_pick(phr, 'already more than one risk. Lovely', 'halfway to the target', 'going well. Do not scare it off')
fun4 = f_pick(phr, 'target is very close. Sit tight', 'almost home. You can put the coffee on', 'just a little more, do not touch')
fun5 = f_pick(phr, 'slightly in the red. It happens, the stop is in place', 'against us for now. There is a plan, we wait', 'a small minus. The stop knows its job')
fun6 = f_pick(phr, 'close to the stop. We do not move it', 'unpleasant, but that is what the stop is for', 'it may get stopped out. That is the price of playing')
fun7 = f_pick(phr, 'waiting for a pullback. Patience is a position too', 'trend is there, waiting for a better price', 'not chasing, waiting for a pullback')
fun8 = f_pick(phr, 'that train has left, waiting for the next one', 'the trend runs without us. We do not chase', 'too late. Waiting for a new arrow')
fun9 = f_pick(phr, 'none. Hands in pockets, kettle on', 'no trade, and that is a position too', 'empty. The market can wait, the money stays safe')
funTxt = trState == 1 ? fun1 : trState == 2 ? fun2 : trState == 3 ? fun3 : trState == 4 ? fun4 : trState == 5 ? fun5 : trState == 6 ? fun6 : trState == 7 ? fun7 : trState == 8 ? fun8 : fun9
plainTxt = trState == 1 ? 'just opened' : trState == 2 ? 'in profit' : trState == 3 ? 'more than one risk made' : trState == 4 ? 'target is close' : trState == 5 ? 'small loss' : trState == 6 ? 'close to the stop' : trState == 7 ? 'trend is there, waiting for a pullback' : trState == 8 ? 'closed, waiting for a new arrow' : 'none'
tailTxt = tDir != 0 and t1Done ? ' · stop at breakeven' : tDir != 0 and stopInProfit ? ' · stop already in profit' : ''
tradeTxt = (tDir == 1 ? 'UP ' + floatTxt + ' · ' : tDir == -1 ? 'DOWN ' + floatTxt + ' · ' : '') + (funny ? funTxt : plainTxt) + tailTxt
f_row(tb, r, tDir != 0 ? '🚗' : '💤', 'Arrow trade', tradeTxt, tDir != 0 ? floatPips >= 0 ? cUp : cDn : color.white, 'Practice trade for the latest arrow: shows what would happen if you entered strictly by the arrows.\nFirst the direction and the result right now: in pips and in dollars for the lot calculated from the balance and risk in the settings (0.01 minimum).\nThen a short comment that changes as the trade develops.\nThe entry, stop and target are drawn on the chart.')
r := r + 1
f_row(tb, r, '🕒', 'Session', sessTxt, sessCol, tipSess)
r := r + 1
f_row(tb, r, '⏳', 'Candle', 'of this chart (' + tfName + ') · ' + candleTxt, isWeekend ? cNeu : color.white, tipCandle)
r := r + 1
if timeframe.isintraday or isWeekend
f_row(tb, r, '📏', 'Day', dayTxt, dayCol, tipDay)
r := r + 1
r
f_row(tb, r, wIcon, 'Noise', 'in one candle price moves about ' + f_pips(atr / pip) + '. A closer stop gets hit by chance' + ' · ' + wTxt, wCol, tipW)
r := r + 1
if useSigTf
trgOk = patAge > 0 and patLast != 3 and patDir == mainDir and mainDir != 0
entTxt = mainDir == 0 ? funny ? 'H4 and daily disagree. On this chart we sit on our hands' : 'H4 and daily disagree, no entry' : trgOk ? (mainDir == 1 ? 'H4 trend is up and here is an up candle: ' : 'H4 trend is down and here is a down candle: ') + patName + '. This is how the moment is picked' : mainDir == 1 ? 'H4 trend is up. Here we wait for a dip and an up candle' : 'H4 trend is down. Here we wait for a bounce and a down candle'
f_row(tb, r, '🚪', 'Entry', entTxt, trgOk ? cGood : mainDir == 0 ? cNeu : color.white, 'The direction comes from H4 and daily. The small chart is only for picking the moment: wait for a pullback against the trend and a candle back with the trend (engulfing, pin bar, star).\nHistory test: the small timeframes\' own signals lost money, and candle entries alone showed no profit. So this is a way to pick a better price, not a guarantee.')
r := r + 1
r
table.clear(tb, 0, 2, 2, 35)
for i = 0 to array.size(rwIco) - 1 by 1
tp = array.get(rwTip, i)
table.cell(tb, 0, i + 2, array.get(rwIco, i), text_color = color.white, bgcolor = colPanel, text_size = txtSize, tooltip = tp)
table.cell(tb, 1, i + 2, array.get(rwLab, i), text_color = colDim, bgcolor = colPanel, text_size = txtSize, text_halign = text.align_left, tooltip = tp)
table.cell(tb, 2, i + 2, array.get(rwVal, i), text_color = array.get(rwCol, i), bgcolor = colPanel, text_size = txtSize, text_halign = text.align_left, tooltip = tp)
alertcondition(buySig, 'TrendVote: UP', 'TrendVote: UP signal')
alertcondition(sellSig, 'TrendVote: DOWN', 'TrendVote: DOWN signal')
alertcondition(openL or openS, 'TrendVote: trade entry', 'TrendVote: trade entry')
alertcondition(closedNow, 'TrendVote: trade closed', 'TrendVote: trade closed')
alertcondition(exitSig, 'TrendVote: move ended', 'TrendVote: move ended')
alertcondition(brokeUp or brokeDn, 'TrendVote: level breakout', 'TrendVote: level breakout')