665 lines
50 KiB
Plaintext
665 lines
50 KiB
Plaintext
//@version=6
|
|
// Bracket Morning Panel: all direction rules plus ATR sizing in one indicator (evaluations: 4 NQ / 3 gold / 2 crude / 1 NG; euro FX (6E) is a potential add, not on this panel).
|
|
// Gold (entry 8:21): silver % move minus gold % move from the 6:00 pm reopen to 8:19.
|
|
// Gap above the threshold -> LONG, otherwise SHORT.
|
|
// Crude (entry 9:01): yesterday's 2:30 pm settlement vs yesterday's 9:00 candle close.
|
|
// Settled higher -> SHORT today, lower -> LONG.
|
|
// NG (entry 6:01 pm, at the evening reopen, for the NEXT trading day): always the SAME side as crude
|
|
// (energy group: opposite sides would be hedging). Crude's side for that day is already set by the 2:30 pm
|
|
// settlement, so the panel shows it from 6:00 pm. Hold to the usual 4:40 pm exit next day.
|
|
// NQ (News-day rule below is OFF by default: it failed the 2010-14 holdout. NQ then always uses the normal-day rule.)
|
|
// News check first (8:31): news day = 8:30 candle volume >= 4.4x the average of the 8:15-8:29 candles.
|
|
// News day: the 8:30 candle gets the same tests as the 9:30 one (first match wins):
|
|
// a. Displacement (8:31): body >= 30% of the 8:30 candle's range, wick against <= 15% -> follow the candle.
|
|
// b. Drive (8:33): 8:29 close -> 8:32 close move >= 5% of daily ATR(14), given back <= 25% from the 8:30-8:32
|
|
// extreme -> follow the move. c. Three candles (8:33): 8:30, 8:31, 8:32 all close the same way -> follow.
|
|
// If none of a-c fires, trade the normal-day rule below.
|
|
// Normal day (entry 9:31 or 9:33), first match wins:
|
|
// 1. Displacement (9:31): the 9:30 candle has body >= 30% of its range and the wick against it <= 15%
|
|
// of the range -> follow the candle (green -> LONG, red -> SHORT).
|
|
// 2. Drive (9:33): the move from the 9:29 close to the 9:32 close is >= 5% of daily ATR(14) and price has
|
|
// given back <= 25% of the move from the 9:30-9:32 extreme -> follow the move.
|
|
// 3. Three candles (9:33): the 9:30, 9:31 and 9:32 candles all close the same way -> follow them.
|
|
// 4. Otherwise (9:33): the old rule. 9:30 close vs the prior cash close: above -> SHORT, below -> LONG.
|
|
// Prior cash close = the last regular session's close: the 3:59 candle, or the 1:14 pm candle after an
|
|
// early-close day (e.g. the day after Thanksgiving). Holiday sessions that halt at 1:00 pm don't count.
|
|
// Sizing: contracts = round(stop $ / ($ per point x 0.20 x daily ATR(14))), min 1, max 4;
|
|
// stop pts = (stop $ - allowance x contracts) / (contracts x $ per point), allowance $0 by default (stop at the floor); target pts = (target $ + commission x contracts) / (contracts x $ per point).
|
|
// Small contracts when the stop $ is under 75% of one full contract's risk at the ATR stop distance:
|
|
// MGC / MCL / MNQ (1/10 size, max 40); nat gas uses QG (E-mini, 1/4 size, tick 0.005, max 16) because Lucid has no micro NG.
|
|
// Then $3 allowance per small contract and its own commission.
|
|
// Evaluation endgame: type what the account still needs to pass. $500 or less -> stop = what's needed (1:1);
|
|
// more than $500 -> target = what's needed, stop = all the room (the Stop $ input). 0 = off (fresh account).
|
|
// Works on any chart timeframe (1 min, 5 min, 1 hour...): every signal is computed from 1-minute data of each contract.
|
|
// Continuous "1!" symbols are fine (roll days change the NQ side about once a year and a few gold signals a year).
|
|
// Exact months (e.g. NQZ2026) avoid even that, if you prefer.
|
|
// Skip US market holidays and early-close days. Per-account stop/target $: the account rows under the market rows (fill them in Settings).
|
|
// Signals lock the moment the decision candle has closed (gold: 8:19 candle -> shown from 8:20; NQ: the 8:30 / 9:30 candle -> from 8:31 / 9:31, else the 8:32 / 9:32 candle -> from 8:33 / 9:33),
|
|
// using that candle's final close, so they never flicker. Until then the side shows "waiting".
|
|
// Set alerts to "Once Per Bar" so they fire the moment the side is known (with "Once Per Bar Close" a 5-minute chart alerts up to 5 minutes late).
|
|
indicator("Bracket Morning Panel", overlay = false) // own pane below the chart, so the table never covers price
|
|
|
|
tz = "America/New_York"
|
|
grpC = "Contracts (use the exact month you trade)"
|
|
gcSym = input.symbol("COMEX:GC1!", "Gold", group = grpC, display = display.none)
|
|
siSym = input.symbol("COMEX:SI1!", "Silver", group = grpC, display = display.none)
|
|
clSym = input.symbol("NYMEX:CL1!", "Crude", group = grpC, display = display.none)
|
|
nqSym = input.symbol("CME_MINI:NQ1!", "NQ", group = grpC, display = display.none)
|
|
ngSym = input.symbol("NYMEX:NG1!", "Natural gas", group = grpC, display = display.none)
|
|
|
|
grpG = "Gold gap threshold"
|
|
thrInput = input.float(0.99, "Threshold (%): 250-day median |gap|", step = 0.01, group = grpG, tooltip = "The backtested rule: median |silver-gold gap| over the last 250 trading days. 0.99% as of 11 Nov 2026. Update every month or two from fresh data.", display = display.none)
|
|
useAuto = input.bool(false, "Automatic threshold (5-min bars)", group = grpG, tooltip = "OFF by default. TradingView loads only about 18 (free) to 145 (Ultimate) days of 5-minute history, short of the 250-day rule. When ON, the median uses as many days as are loaded and is checked daily against the exact 1-minute gap.", display = display.none)
|
|
chkTol = input.float(0.05, "Check tolerance (% points)", step = 0.01, group = grpG, display = display.none)
|
|
lookback = input.int(250, "Median lookback (trading days)", minval = 20, group = grpG, display = display.none)
|
|
minDays = input.int(15, "Days before using the median", minval = 10, group = grpG, tooltip = "Tested: an 18-day median picks the same side as the 250-day one on 91-94% of days, with the same edge.", display = display.none)
|
|
|
|
useNews = input.bool(false, "NQ news-day rule (8:30 trades)", tooltip = "OFF (default): NQ always trades the normal-day rule at 9:31 / 9:33. The news-day rule failed the 2010-14 holdout test. ON only for testing.", display = display.none)
|
|
newsThr = input.float(4.4, "NQ news day: 8:30 volume vs 8:15-8:29 average (x)", step = 0.1, display = display.none)
|
|
|
|
grpS = "Sizing (defaults = fresh evaluation, daily loss limit OFF)"
|
|
stopUsd = input.float(2000, "Stop $", step = 50, group = grpS, tooltip = "Fresh evaluation: 2000 with the daily loss limit OFF (all the room), 1200 with it ON.", display = display.none)
|
|
targetUsd = input.float(3000, "Target $", step = 50, group = grpS, display = display.none)
|
|
atrFrac = input.float(0.20, "Stop as share of daily ATR", step = 0.01, group = grpS, display = display.none)
|
|
maxC = input.int(4, "Max contracts (full-size)", minval = 1, group = grpS, display = display.none)
|
|
nqFull = input.bool(true, "NQ: always full contracts (no MNQ)", group = grpS, tooltip = "Fleet test 2016-26: always at least 1 NQ beat the micro switch by about $0.4-0.8k a year, and it is simpler to enter. Other markets keep the micro switch.", display = display.none)
|
|
costUsd = input.float(0, "Stop: cost allowance per contract ($)", step = 1, group = grpS, tooltip = "0 = stop exactly at the floor (default). With the stop at all the room, a stop-out ends the account either way, so leaving a few dollars of room protects nothing and only makes stop-outs more likely. Fleet test 2016-26: $0 beat $20 by about $10-15k a year. Use 20 only for a stop that is NOT all the room.", display = display.none)
|
|
costUsdM = input.float(0, "Stop: cost allowance per micro ($)", step = 0.5, group = grpS, tooltip = "0 = stop exactly at the floor (default); see above.", display = display.none)
|
|
grpE = "Evaluation endgame (one account at a time)"
|
|
needUsd = input.float(0, "Still needed to pass ($), 0 = off", step = 50, minval = 0, group = grpE, tooltip = "For an evaluation close to its target. $500 or less: stop = what's needed (1:1), sized in micros. More than $500: target = what's needed, stop = Stop $ above (all the room). Set back to 0 afterwards.", display = display.none)
|
|
endThr = input.float(500, "Use a 1:1 stop when needed is at most ($)", step = 50, group = grpE, display = display.none)
|
|
grpF = "Target: commission per contract, round trip ($). Limit orders do not slip."
|
|
gcComm = input.float(4.60, "Gold", step = 0.1, group = grpF, display = display.none)
|
|
clComm = input.float(4.00, "Crude", step = 0.1, group = grpF, display = display.none)
|
|
nqComm = input.float(3.50, "NQ", step = 0.1, group = grpF, display = display.none)
|
|
ngComm = input.float(4.00, "Natural gas", step = 0.1, group = grpF, display = display.none)
|
|
gcCommM = input.float(1.60, "Micro gold (MGC)", step = 0.1, group = grpF, display = display.none)
|
|
clCommM = input.float(1.00, "Micro crude (MCL)", step = 0.1, group = grpF, display = display.none)
|
|
nqCommM = input.float(1.00, "Micro NQ (MNQ)", step = 0.1, group = grpF, display = display.none)
|
|
ngCommM = input.float(2.60, "E-mini nat gas (QG)", step = 0.1, group = grpF, display = display.none)
|
|
|
|
// ---------- helpers (evaluated in each symbol's own context via request.security) ----------
|
|
endsAt(h, m) => hour(time_close, tz) == h and minute(time_close, tz) == m
|
|
|
|
goldMove() =>
|
|
var float o = na
|
|
var float m819 = na
|
|
if timeframe.change("D") // CME trading day starts at the 6:00 pm ET reopen
|
|
o := open
|
|
m819 := na
|
|
if endsAt(8, 21) and not na(o) // 8:20 candle: close[1] is the final close of the 8:19 candle
|
|
m819 := close[1] / o - 1.0
|
|
[m819, close / o - 1.0] // [move to the 8:19 close (locked), move so far (live)]
|
|
|
|
mins(t) => hour(t, tz) * 60 + minute(t, tz)
|
|
|
|
// One opening window: open candle at minute o (minutes after midnight ET), pre candle o-1, entries o+1 / o+3.
|
|
openWindow(int o) =>
|
|
tc = mins(time_close)
|
|
var float pre = na
|
|
var float c1 = na // open candle close
|
|
var float c3 = na // close of the third candle (o+2)
|
|
var float hiX = na // highest high / lowest low of the three candles
|
|
var float loX = na
|
|
var int disp = 0
|
|
var int d1 = 0
|
|
var int d2 = 0
|
|
var int three = 0
|
|
var bool done1 = false
|
|
var bool done3 = false
|
|
if timeframe.change("D")
|
|
pre := na
|
|
c1 := na
|
|
c3 := na
|
|
hiX := na
|
|
loX := na
|
|
disp := 0
|
|
d1 := 0
|
|
d2 := 0
|
|
three := 0
|
|
done1 := false
|
|
done3 := false
|
|
if tc == o + 1 // open candle forming: close[1] is the final pre-candle close
|
|
pre := close[1]
|
|
if tc == o + 2 and not na(pre) // [1] is the final open candle
|
|
op = open[1]
|
|
h = high[1]
|
|
l = low[1]
|
|
c = close[1]
|
|
r = h - l
|
|
c1 := c
|
|
hiX := h
|
|
loX := l
|
|
d1 := int(math.sign(c - op))
|
|
if r > 0 and c != op
|
|
sd = c > op ? 1 : -1
|
|
wa = sd > 0 ? (op - l) / r : (h - op) / r
|
|
disp := math.abs(c - op) / r >= 0.30 and wa <= 0.15 ? sd : 0
|
|
done1 := true
|
|
if tc == o + 3 and done1 // [1] is the final second candle
|
|
hiX := math.max(hiX, high[1])
|
|
loX := math.min(loX, low[1])
|
|
d2 := int(math.sign(close[1] - open[1]))
|
|
if tc == o + 4 and done1 // [1] is the final third candle
|
|
hiX := math.max(hiX, high[1])
|
|
loX := math.min(loX, low[1])
|
|
c3 := close[1]
|
|
d3 = int(math.sign(close[1] - open[1]))
|
|
three := d1 != 0 and d1 == d2 and d1 == d3 ? d1 : 0
|
|
done3 := true
|
|
[done1, done3, disp, three, pre, c1, c3, hiX, loX]
|
|
|
|
nqSignal() =>
|
|
var float c16 = na // prior cash close (3:59 candle, or the last candle of an early-close day)
|
|
var float lastRth = na // close of the latest 9:30-3:59 candle this trading day
|
|
var int lastRthM = na // its start minute (ET)
|
|
var float ref = na // c16 as used today
|
|
var int cur = 0 // old rule's side
|
|
var float ratio = na // 8:30 candle volume / average 8:15-8:29 volume
|
|
var bool newsDone = false
|
|
if timeframe.change("D")
|
|
// finalize the previous day's cash close at the 6 pm reopen: full day (last candle 3:59) or early close (last candle 1:00-1:14 pm);
|
|
// a holiday session that halts at 1:00 pm (last candle 12:59) is not a cash session, so the older close is kept
|
|
if not na(lastRthM) and (lastRthM == 959 or (lastRthM >= 780 and lastRthM <= 794))
|
|
c16 := lastRth
|
|
lastRth := na
|
|
lastRthM := na
|
|
ref := na
|
|
cur := 0
|
|
ratio := na
|
|
newsDone := false
|
|
if mins(time_close) == 512 // 8:31 candle forming: [1] is the final 8:30 candle
|
|
base = 0.0
|
|
for i = 2 to 25
|
|
m = mins(time[i])
|
|
if m >= 495 and m <= 509 // candles 8:15-8:29
|
|
base += volume[i]
|
|
ratio := base > 0 ? volume[1] / (base / 15) : na
|
|
newsDone := true
|
|
[a1, a3, aDisp, aThree, aPre, aC1, aC3, aHi, aLo] = openWindow(510) // 8:30
|
|
[b1, b3, bDisp, bThree, bPre, bC1, bC3, bHi, bLo] = openWindow(570) // 9:30
|
|
if mins(time_close) == 572 and not na(c16) // 9:31 candle forming: [1] is the final 9:30 candle
|
|
ref := c16
|
|
cur := close[1] > c16 ? -1 : 1
|
|
m0 = mins(time)
|
|
if m0 >= 570 and m0 <= 959 // regular-session candle: remember it (its final close is committed when the candle closes)
|
|
lastRth := close
|
|
lastRthM := m0
|
|
[newsDone, ratio, a1, a3, aDisp, aThree, aPre, aC3, aHi, aLo, b1, b3, bDisp, bThree, bPre, bC1, bC3, bHi, bLo, cur, ref]
|
|
|
|
clSignal() =>
|
|
var float c901 = na
|
|
var float settle = na
|
|
var int dirNext = 0
|
|
var int dirToday = 0
|
|
var float yOpen = na
|
|
var float ySettle = na
|
|
if timeframe.change("D") // new trading day: yesterday's result becomes today's direction
|
|
dirToday := dirNext
|
|
yOpen := c901
|
|
ySettle := settle
|
|
dirNext := 0
|
|
c901 := na
|
|
settle := na
|
|
if endsAt(9, 2) // 9:01 candle: close[1] is the final close of the 9:00 candle
|
|
c901 := close[1]
|
|
if endsAt(14, 31) and not na(c901) // 2:30 candle: close[1] is the final close of the 2:29 candle (2:30 pm settlement time)
|
|
settle := close[1]
|
|
dirNext := close[1] > c901 ? -1 : 1
|
|
[dirToday, yOpen, ySettle, endsAt(9, 2), endsAt(18, 2)] // last two: crude entry minute (9:01), NG entry minute (6:01 pm)
|
|
|
|
dailyInfo() => [ta.atr(14)[1], syminfo.pointvalue, syminfo.mintick] // yesterday's ATR, completed days only
|
|
|
|
endOn = needUsd > 0
|
|
stopEff = endOn and needUsd <= endThr ? needUsd : stopUsd
|
|
tgtEff = endOn ? needUsd : targetUsd
|
|
|
|
sizeFor(atrD, pv, mt, comm, commM, ratio, mtM, bool forceFull = false) =>
|
|
micro = not forceFull and stopEff < 0.75 * pv * atrFrac * atrD // stop too small for one full contract at the ATR stop distance
|
|
p = micro ? pv / ratio : pv
|
|
cap = micro ? maxC * ratio : maxC
|
|
tk = micro ? mtM : mt // QG ticks 0.005, NG 0.001
|
|
cst = micro ? costUsdM : costUsd
|
|
cm = micro ? commM : comm
|
|
n = math.max(1, math.min(cap, math.round(stopEff / (p * atrFrac * atrD))))
|
|
sp = math.floor(math.max(stopEff - cst * n, 0) / (n * p) / tk + 1e-6) * tk // 1e-6 guards against float error (1.18 / 0.01 = 117.999...)
|
|
tp = math.ceil((tgtEff + cm * n) / (n * p) / tk - 1e-6) * tk
|
|
[n, sp, tp, sp * n * p, tp * n * p, micro] // Risk USD / Reward USD = whole position
|
|
|
|
// ---------- display helpers ----------
|
|
sideText(d) => d == 1 ? "LONG" : d == -1 ? "SHORT" : "waiting"
|
|
sideColor(d) => d == 1 ? color.lime : d == -1 ? color.new(#ff5252, 0) : color.silver
|
|
num(x) => na(x) ? "-" : str.tostring(x, "#.##")
|
|
pts(x) => na(x) ? "-" : str.tostring(x, "#.####") // prices/points: enough decimals for NG (0.001 tick)
|
|
usd(x) => na(x) ? "-" : "$" + str.tostring(x, "#,##0.00")
|
|
|
|
// ---------- data ----------
|
|
[g819, gLive] = request.security(gcSym, "1", goldMove())
|
|
[s819, sLive] = request.security(siSym, "1", goldMove())
|
|
[nwDone, nwRatio, a1, a3, aDisp, aThree, aPre, aC3, aHi, aLo, nqDone1, nqDone3, nqDisp, nqThree, nqPre, nqPx, nqC932, nqHi, nqLo, nqCur, nqRef] = request.security(nqSym, "1", nqSignal())
|
|
[clDir, clOpen, clSettle, clEntryNow, ngEntryNow] = request.security(clSym, "1", clSignal())
|
|
|
|
[gcAtr, gcPv, gcMt] = request.security(gcSym, "D", dailyInfo(), lookahead = barmerge.lookahead_on)
|
|
[clAtr, clPv, clMt] = request.security(clSym, "D", dailyInfo(), lookahead = barmerge.lookahead_on)
|
|
[nqAtr, nqPv, nqMt] = request.security(nqSym, "D", dailyInfo(), lookahead = barmerge.lookahead_on)
|
|
[ngAtr, ngPv, ngMt] = request.security(ngSym, "D", dailyInfo(), lookahead = barmerge.lookahead_on)
|
|
|
|
// ---------- automatic gold threshold ----------
|
|
// On standard 5-minute bars of the silver/gold ratio: the 6:00 pm bar's open is the reopen, and the 8:15-8:20 bar's close is the 8:19 close.
|
|
// The ratio's % change is (1+si)/(1+gc)-1, within ~0.01% of si%-gc% for normal moves. The median is of PRIOR days only
|
|
// (computed before today's value is added), over as many days as TradingView has loaded, up to the lookback.
|
|
autoThr() =>
|
|
var array<float> h = array.new<float>()
|
|
var float o18 = na
|
|
var float medPrior = na
|
|
var float lastGap = na
|
|
var int lastDay = na
|
|
if hour(time, tz) == 18 and minute(time, tz) == 0
|
|
o18 := open
|
|
if hour(time, tz) == 8 and minute(time, tz) == 15 and barstate.isconfirmed and not na(o18)
|
|
medPrior := h.size() >= minDays ? h.median() : na
|
|
g = (close / o18 - 1.0) * 100.0
|
|
lastGap := g
|
|
lastDay := dayofmonth(time_close, tz)
|
|
h.push(math.abs(g))
|
|
if h.size() > lookback
|
|
h.shift()
|
|
o18 := na
|
|
[medPrior, h.size(), lastGap, lastDay]
|
|
[aThr, aN, aGap, aDay] = request.security(siSym + "/" + gcSym, "5", autoThr())
|
|
|
|
// ---------- gold decision: once per trading day, as soon as both locked 8:19 moves exist ----------
|
|
gap = (sLive - gLive) * 100.0 // live, for the "now" display
|
|
gap819 = (s819 - g819) * 100.0 // final, from the closed 8:19 candles
|
|
|
|
var array<float> hist = array.new<float>()
|
|
var float thr = thrInput
|
|
var float goldGap = na
|
|
var int goldDir = 0
|
|
var bool goldDone = false
|
|
|
|
if timeframe.change("D")
|
|
goldDir := 0
|
|
goldGap := na
|
|
goldDone := false
|
|
|
|
var string thrSrc = "input"
|
|
var bool autoBad = false
|
|
if not goldDone and not na(gap819)
|
|
sameDay = not na(aDay) and aDay == dayofmonth(time, tz)
|
|
if useAuto and sameDay and math.abs(aGap - gap819) > chkTol
|
|
autoBad := true // bars not aligned as expected: stop trusting the automatic value
|
|
useA = useAuto and not autoBad and not na(aThr)
|
|
thr := useA ? aThr : thrInput // the typed-in 250-day median unless the automatic value is switched on and passes its check
|
|
thrSrc := useA ? "auto, " + str.tostring(math.min(aN - 1, lookback)) + " days" : (autoBad ? "input; auto failed check" : "input") + "; auto history " + str.tostring(nz(aN)) + " days"
|
|
goldGap := gap819
|
|
goldDir := gap819 > thr ? 1 : -1
|
|
goldDone := true
|
|
hist.push(math.abs(gap819))
|
|
if hist.size() > lookback
|
|
hist.shift()
|
|
|
|
// ---------- NQ decision ----------
|
|
driveOf(done3, pre, c3, hi, lo, atrD) =>
|
|
mv = c3 - pre
|
|
sg = nz(math.sign(mv))
|
|
ext = sg > 0 ? hi : lo
|
|
pull = (ext - c3) * sg
|
|
dr = done3 and sg != 0 and math.abs(mv) >= 0.05 * atrD and pull <= 0.25 * math.abs(ext - pre) ? int(sg) : 0
|
|
[dr, mv, pull]
|
|
|
|
// normal-day rule (9:30 window)
|
|
[nqDrive, nqMv, nqPull] = driveOf(nqDone3, nqPre, nqC932, nqHi, nqLo, nqAtr)
|
|
hDir = not nqDone1 ? 0 : nqDisp != 0 ? nqDisp : not nqDone3 ? 0 : nqDrive != 0 ? nqDrive : nqThree != 0 ? nqThree : nqCur
|
|
hBranch = not nqDone1 ? "waiting for the 9:30 candle" : nqDisp != 0 ? "1. displacement 9:30 candle -> follow" :
|
|
not nqDone3 ? "no 9:30 displacement; waiting for the 9:32 candle" :
|
|
nqDrive != 0 ? "2. drive " + num(nqMv) + " pts from 9:29 (min " + num(0.05 * nqAtr) + "), gave back " + num(nqPull) + " -> follow" :
|
|
nqThree != 0 ? "3. three candles same way -> follow" :
|
|
"4. old rule: 9:30 close " + num(nqPx) + " vs prior cash close " + num(nqRef)
|
|
hEntry = nqDisp != 0 ? "9:31" : nqDone1 ? "9:33" : "9:31 / 9:33"
|
|
|
|
// news day (8:30 window)
|
|
newsSeen = nwDone and not na(nwRatio) and nwRatio >= newsThr // shown for information
|
|
news = useNews and newsSeen
|
|
[aDrive, aMv, aPull] = driveOf(a3, aPre, aC3, aHi, aLo, nqAtr)
|
|
newsSig = aDisp != 0 ? aDisp : not a3 ? 0 : aDrive != 0 ? aDrive : aThree
|
|
newsWait = news and aDisp == 0 and not a3 // 8:31-8:32: waiting for the 8:32 candle
|
|
newsTrade = news and newsSig != 0
|
|
pending = useNews ? not nwDone and not nqDone1 : not nqDone1 // news rule off: just wait for the 9:30 candle
|
|
nqDir = pending or newsWait ? 0 : newsTrade ? newsSig : hDir
|
|
tag = not useNews ? "" : not nwDone ? "" : (news ? "NEWS DAY" : "normal day") + " (8:30 volume " + num(nwRatio) + "x vs " + num(newsThr) + "x): "
|
|
nqBranch = pending ? (useNews ? "waiting for the 8:30 candle (news check at 8:31)" : "waiting for the 9:30 candle") :
|
|
newsWait ? tag + "no 8:30 displacement; waiting for the 8:32 candle" :
|
|
newsTrade ? tag + (aDisp != 0 ? "a. 8:30 displacement -> follow" :
|
|
aDrive != 0 ? "b. 8:30 drive " + num(aMv) + " pts from 8:29 (min " + num(0.05 * nqAtr) + "), gave back " + num(aPull) + " -> follow" :
|
|
"c. 8:30 three candles same way -> follow") :
|
|
tag + (news ? "no 8:30 signal -> normal rule: " : "") + hBranch
|
|
nqEntry = pending ? (useNews ? "8:31 / 8:33 / 9:31 / 9:33" : "9:31 / 9:33") : newsWait ? "8:33 (or 9:31 / 9:33)" : newsTrade ? (aDisp != 0 ? "8:31" : "8:33") : hEntry
|
|
|
|
// ---------- sizing ----------
|
|
[gcN, gcSp, gcTp, gcRiskUsd, gcRewUsd, gcMicro] = sizeFor(gcAtr, gcPv, gcMt, gcComm, gcCommM, 10, gcMt)
|
|
[clN, clSp, clTp, clRiskUsd, clRewUsd, clMicro] = sizeFor(clAtr, clPv, clMt, clComm, clCommM, 10, clMt)
|
|
[nqN, nqSp, nqTp, nqRiskUsd, nqRewUsd, nqMicro] = sizeFor(nqAtr, nqPv, nqMt, nqComm, nqCommM, 10, nqMt, nqFull)
|
|
[ngN, ngSp, ngTp, ngRiskUsd, ngRewUsd, ngMicro] = sizeFor(ngAtr, ngPv, ngMt, ngComm, ngCommM, 4, 0.005)
|
|
|
|
// ---------- display ----------
|
|
|
|
grpD = "Display"
|
|
posIn = input.string("Top right", "Table position", options = ["Top right", "Top center", "Top left", "Middle right", "Middle center", "Middle left", "Bottom right", "Bottom center", "Bottom left"], group = grpD, display = display.none)
|
|
szMIn = input.string("Normal", "Text size: market rows", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = grpD, display = display.none)
|
|
szAIn = input.string("Small", "Text size: account rows and notes", options = ["Tiny", "Small", "Normal", "Large", "Huge"], group = grpD, display = display.none)
|
|
alIn = input.string("Center", "Text alignment", options = ["Center", "Left", "Right"], group = grpD, display = display.none)
|
|
toSize(string v) => v == "Tiny" ? size.tiny : v == "Small" ? size.small : v == "Large" ? size.large : v == "Huge" ? size.huge : size.normal
|
|
toPos(string v) => v == "Top center" ? position.top_center : v == "Top left" ? position.top_left : v == "Middle right" ? position.middle_right : v == "Middle center" ? position.middle_center : v == "Middle left" ? position.middle_left : v == "Bottom right" ? position.bottom_right : v == "Bottom center" ? position.bottom_center : v == "Bottom left" ? position.bottom_left : position.top_right
|
|
szMain = toSize(szMIn)
|
|
szAcc = toSize(szAIn)
|
|
hAl = alIn == "Left" ? text.align_left : alIn == "Right" ? text.align_right : text.align_center
|
|
var table t = table.new(toPos(posIn), 13, 17, bgcolor = color.new(color.black, 15), border_width = 1)
|
|
if barstate.islast
|
|
hdr = array.from("Market", "Entry (ET)", "Side", "Why", "ATR(14)", "Contracts", "Risk USD", "Reward USD", "Stop (pts)", "Target (pts)")
|
|
for i = 0 to 9
|
|
table.cell(t, i, 0, hdr.get(i), text_color = color.white, bgcolor = color.new(color.gray, 60), text_size = szMain, text_halign = hAl)
|
|
|
|
table.cell(t, 0, 1, "Gold", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 1, 1, "8:21", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 2, 1, sideText(goldDir), text_color = sideColor(goldDir), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 3, 1, goldDone ? "locked at 8:19: gap " + num(goldGap) + "% vs " + num(thr) + "% (" + thrSrc + ")" :
|
|
"waiting for 8:19 | live gap " + num(gap) + "% vs " + num(useAuto and not na(aThr) and not autoBad ? aThr : thrInput) + "%", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 4, 1, num(gcAtr), text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 5, 1, str.tostring(gcN) + (gcMicro ? " MGC" : ""), text_color = gcMicro ? color.yellow : color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 6, 1, usd(gcRiskUsd), text_color = color.red, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 7, 1, usd(gcRewUsd), text_color = color.lime, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 8, 1, pts(gcSp), text_color = color.new(color.red, 40), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 9, 1, pts(gcTp), text_color = color.new(color.lime, 40), text_size = szMain, text_halign = hAl)
|
|
|
|
table.cell(t, 0, 2, "Crude", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 1, 2, "9:01", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 2, 2, sideText(clDir), text_color = sideColor(clDir), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 3, 2, "yesterday: settle " + num(clSettle) + " vs 9:00 close " + num(clOpen), text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 4, 2, num(clAtr), text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 5, 2, str.tostring(clN) + (clMicro ? " MCL" : ""), text_color = clMicro ? color.yellow : color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 6, 2, usd(clRiskUsd), text_color = color.red, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 7, 2, usd(clRewUsd), text_color = color.lime, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 8, 2, pts(clSp), text_color = color.new(color.red, 40), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 9, 2, pts(clTp), text_color = color.new(color.lime, 40), text_size = szMain, text_halign = hAl)
|
|
|
|
table.cell(t, 0, 3, "Nat gas", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 1, 3, "6:01 pm (prev. eve)", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 2, 3, sideText(clDir), text_color = sideColor(clDir), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 3, 3, "crude's side for the trading day that opens at 6 pm (no hedging)", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 4, 3, num(ngAtr), text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 5, 3, str.tostring(ngN) + (ngMicro ? " QG" : ""), text_color = ngMicro ? color.yellow : color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 6, 3, usd(ngRiskUsd), text_color = color.red, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 7, 3, usd(ngRewUsd), text_color = color.lime, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 8, 3, pts(ngSp), text_color = color.new(color.red, 40), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 9, 3, pts(ngTp), text_color = color.new(color.lime, 40), text_size = szMain, text_halign = hAl)
|
|
|
|
table.cell(t, 0, 4, "NQ", text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 1, 4, nqEntry, text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 2, 4, sideText(nqDir), text_color = sideColor(nqDir), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 3, 4, nqBranch, text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 4, 4, num(nqAtr), text_color = color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 5, 4, str.tostring(nqN) + (nqMicro ? " MNQ" : ""), text_color = nqMicro ? color.yellow : color.white, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 6, 4, usd(nqRiskUsd), text_color = color.red, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 7, 4, usd(nqRewUsd), text_color = color.lime, text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 8, 4, pts(nqSp), text_color = color.new(color.red, 40), text_size = szMain, text_halign = hAl)
|
|
table.cell(t, 9, 4, pts(nqTp), text_color = color.new(color.lime, 40), text_size = szMain, text_halign = hAl)
|
|
|
|
endTxt = not endOn ? "" : needUsd <= endThr ? "ENDGAME: needs " + usd(needUsd) + " -> 1:1 stop (" + usd(needUsd) + "). Set back to 0 for other accounts. " : "ENDGAME: needs " + usd(needUsd) + " -> target " + usd(needUsd) + ", stop all the room. Set back to 0 for other accounts. "
|
|
note = endTxt + "Stop = exactly the room (no cost allowance; a stop-out ends the account either way). Target includes commission. Type as shown. Yellow = micros. Per-account sizes: account rows below. Skip holidays and early closes."
|
|
table.cell(t, 0, 5, note, text_color = color.new(color.white, 30), text_size = szAcc, text_halign = hAl)
|
|
table.merge_cells(t, 0, 5, 12, 5)
|
|
|
|
// ---------- account table (per-account sizing for manual trading) ----------
|
|
grpA = "Account table"
|
|
showAcct = input.bool(true, "Show account table", group = grpA, display = display.none)
|
|
acctEnd = input.bool(false, "Evaluations: 1:1 stop when still needed <= endgame threshold", group = grpA, tooltip = "Off by default (tested neutral). Uses the endgame threshold above.", display = display.none)
|
|
a1Name = input.string("", "Name", group = "Account 1", inline = "1a", display = display.none)
|
|
a1Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 1", inline = "1a", display = display.none)
|
|
a1Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 1", inline = "1a", display = display.none)
|
|
a1Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 1", inline = "1b", display = display.none)
|
|
a1Bal = input.float(0, "Balance", step = 1, group = "Account 1", inline = "1b", display = display.none)
|
|
a1Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 1", inline = "1b", display = display.none)
|
|
a1Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 1", inline = "1b", display = display.none)
|
|
a1C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 1", inline = "1c", display = display.none)
|
|
a1Best = input.float(0, "Best day this cycle", step = 1, group = "Account 1", inline = "1c", display = display.none)
|
|
a1Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 1", inline = "1c", display = display.none)
|
|
a2Name = input.string("", "Name", group = "Account 2", inline = "2a", display = display.none)
|
|
a2Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 2", inline = "2a", display = display.none)
|
|
a2Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 2", inline = "2a", display = display.none)
|
|
a2Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 2", inline = "2b", display = display.none)
|
|
a2Bal = input.float(0, "Balance", step = 1, group = "Account 2", inline = "2b", display = display.none)
|
|
a2Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 2", inline = "2b", display = display.none)
|
|
a2Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 2", inline = "2b", display = display.none)
|
|
a2C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 2", inline = "2c", display = display.none)
|
|
a2Best = input.float(0, "Best day this cycle", step = 1, group = "Account 2", inline = "2c", display = display.none)
|
|
a2Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 2", inline = "2c", display = display.none)
|
|
a3Name = input.string("", "Name", group = "Account 3", inline = "3a", display = display.none)
|
|
a3Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 3", inline = "3a", display = display.none)
|
|
a3Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 3", inline = "3a", display = display.none)
|
|
a3Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 3", inline = "3b", display = display.none)
|
|
a3Bal = input.float(0, "Balance", step = 1, group = "Account 3", inline = "3b", display = display.none)
|
|
a3Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 3", inline = "3b", display = display.none)
|
|
a3Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 3", inline = "3b", display = display.none)
|
|
a3C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 3", inline = "3c", display = display.none)
|
|
a3Best = input.float(0, "Best day this cycle", step = 1, group = "Account 3", inline = "3c", display = display.none)
|
|
a3Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 3", inline = "3c", display = display.none)
|
|
a4Name = input.string("", "Name", group = "Account 4", inline = "4a", display = display.none)
|
|
a4Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 4", inline = "4a", display = display.none)
|
|
a4Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 4", inline = "4a", display = display.none)
|
|
a4Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 4", inline = "4b", display = display.none)
|
|
a4Bal = input.float(0, "Balance", step = 1, group = "Account 4", inline = "4b", display = display.none)
|
|
a4Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 4", inline = "4b", display = display.none)
|
|
a4Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 4", inline = "4b", display = display.none)
|
|
a4C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 4", inline = "4c", display = display.none)
|
|
a4Best = input.float(0, "Best day this cycle", step = 1, group = "Account 4", inline = "4c", display = display.none)
|
|
a4Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 4", inline = "4c", display = display.none)
|
|
a5Name = input.string("", "Name", group = "Account 5", inline = "5a", display = display.none)
|
|
a5Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 5", inline = "5a", display = display.none)
|
|
a5Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 5", inline = "5a", display = display.none)
|
|
a5Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 5", inline = "5b", display = display.none)
|
|
a5Bal = input.float(0, "Balance", step = 1, group = "Account 5", inline = "5b", display = display.none)
|
|
a5Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 5", inline = "5b", display = display.none)
|
|
a5Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 5", inline = "5b", display = display.none)
|
|
a5C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 5", inline = "5c", display = display.none)
|
|
a5Best = input.float(0, "Best day this cycle", step = 1, group = "Account 5", inline = "5c", display = display.none)
|
|
a5Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 5", inline = "5c", display = display.none)
|
|
a6Name = input.string("", "Name", group = "Account 6", inline = "6a", display = display.none)
|
|
a6Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 6", inline = "6a", display = display.none)
|
|
a6Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 6", inline = "6a", display = display.none)
|
|
a6Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 6", inline = "6b", display = display.none)
|
|
a6Bal = input.float(0, "Balance", step = 1, group = "Account 6", inline = "6b", display = display.none)
|
|
a6Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 6", inline = "6b", display = display.none)
|
|
a6Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 6", inline = "6b", display = display.none)
|
|
a6C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 6", inline = "6c", display = display.none)
|
|
a6Best = input.float(0, "Best day this cycle", step = 1, group = "Account 6", inline = "6c", display = display.none)
|
|
a6Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 6", inline = "6c", display = display.none)
|
|
a7Name = input.string("", "Name", group = "Account 7", inline = "7a", display = display.none)
|
|
a7Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 7", inline = "7a", display = display.none)
|
|
a7Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 7", inline = "7a", display = display.none)
|
|
a7Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 7", inline = "7b", display = display.none)
|
|
a7Bal = input.float(0, "Balance", step = 1, group = "Account 7", inline = "7b", display = display.none)
|
|
a7Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 7", inline = "7b", display = display.none)
|
|
a7Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 7", inline = "7b", display = display.none)
|
|
a7C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 7", inline = "7c", display = display.none)
|
|
a7Best = input.float(0, "Best day this cycle", step = 1, group = "Account 7", inline = "7c", display = display.none)
|
|
a7Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 7", inline = "7c", display = display.none)
|
|
a8Name = input.string("", "Name", group = "Account 8", inline = "8a", display = display.none)
|
|
a8Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 8", inline = "8a", display = display.none)
|
|
a8Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 8", inline = "8a", display = display.none)
|
|
a8Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 8", inline = "8b", display = display.none)
|
|
a8Bal = input.float(0, "Balance", step = 1, group = "Account 8", inline = "8b", display = display.none)
|
|
a8Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 8", inline = "8b", display = display.none)
|
|
a8Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 8", inline = "8b", display = display.none)
|
|
a8C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 8", inline = "8c", display = display.none)
|
|
a8Best = input.float(0, "Best day this cycle", step = 1, group = "Account 8", inline = "8c", display = display.none)
|
|
a8Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 8", inline = "8c", display = display.none)
|
|
a9Name = input.string("", "Name", group = "Account 9", inline = "9a", display = display.none)
|
|
a9Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 9", inline = "9a", display = display.none)
|
|
a9Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 9", inline = "9a", display = display.none)
|
|
a9Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 9", inline = "9b", display = display.none)
|
|
a9Bal = input.float(0, "Balance", step = 1, group = "Account 9", inline = "9b", display = display.none)
|
|
a9Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 9", inline = "9b", display = display.none)
|
|
a9Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 9", inline = "9b", display = display.none)
|
|
a9C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 9", inline = "9c", display = display.none)
|
|
a9Best = input.float(0, "Best day this cycle", step = 1, group = "Account 9", inline = "9c", display = display.none)
|
|
a9Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 9", inline = "9c", display = display.none)
|
|
a10Name = input.string("", "Name", group = "Account 10", inline = "10a", display = display.none)
|
|
a10Mkt = input.string("Off", "Market", options = ["Off", "Gold", "Crude", "NQ", "Nat gas"], group = "Account 10", inline = "10a", display = display.none)
|
|
a10Stg = input.string("Eval", "Stage", options = ["Eval", "Funded"], group = "Account 10", inline = "10a", display = display.none)
|
|
a10Size = input.string("50K", "Size", options = ["50K", "25K"], group = "Account 10", inline = "10b", display = display.none)
|
|
a10Bal = input.float(0, "Balance", step = 1, group = "Account 10", inline = "10b", display = display.none)
|
|
a10Flr = input.float(0, "Drawdown limit", step = 1, group = "Account 10", inline = "10b", display = display.none)
|
|
a10Tgt = input.float(0, "Target (eval, 0 = standard)", step = 1, group = "Account 10", inline = "10b", display = display.none)
|
|
a10C0 = input.float(0, "Funded: cycle start (0 = start balance)", step = 1, group = "Account 10", inline = "10c", display = display.none)
|
|
a10Best = input.float(0, "Best day this cycle", step = 1, group = "Account 10", inline = "10c", display = display.none)
|
|
a10Pay = input.int(1, "Next payout #", minval = 1, maxval = 5, group = "Account 10", inline = "10c", display = display.none)
|
|
aName = array.from(a1Name, a2Name, a3Name, a4Name, a5Name, a6Name, a7Name, a8Name, a9Name, a10Name)
|
|
aMkt = array.from(a1Mkt, a2Mkt, a3Mkt, a4Mkt, a5Mkt, a6Mkt, a7Mkt, a8Mkt, a9Mkt, a10Mkt)
|
|
aSize = array.from(a1Size, a2Size, a3Size, a4Size, a5Size, a6Size, a7Size, a8Size, a9Size, a10Size)
|
|
aStg = array.from(a1Stg, a2Stg, a3Stg, a4Stg, a5Stg, a6Stg, a7Stg, a8Stg, a9Stg, a10Stg)
|
|
aBal = array.from(a1Bal, a2Bal, a3Bal, a4Bal, a5Bal, a6Bal, a7Bal, a8Bal, a9Bal, a10Bal)
|
|
aFlr = array.from(a1Flr, a2Flr, a3Flr, a4Flr, a5Flr, a6Flr, a7Flr, a8Flr, a9Flr, a10Flr)
|
|
aTgt = array.from(a1Tgt, a2Tgt, a3Tgt, a4Tgt, a5Tgt, a6Tgt, a7Tgt, a8Tgt, a9Tgt, a10Tgt)
|
|
aC0 = array.from(a1C0, a2C0, a3C0, a4C0, a5C0, a6C0, a7C0, a8C0, a9C0, a10C0)
|
|
aBest = array.from(a1Best, a2Best, a3Best, a4Best, a5Best, a6Best, a7Best, a8Best, a9Best, a10Best)
|
|
aPay = array.from(a1Pay, a2Pay, a3Pay, a4Pay, a5Pay, a6Pay, a7Pay, a8Pay, a9Pay, a10Pay)
|
|
|
|
// Same sizing as sizeFor, with this account's own stop and target
|
|
sizeAcct(atrD, pv, mt, comm, commM, ratio, mtM, bool forceFull, float stopU, float tgtU) =>
|
|
micro = not forceFull and stopU < 0.75 * pv * atrFrac * atrD
|
|
p = micro ? pv / ratio : pv
|
|
cap = micro ? maxC * ratio : maxC
|
|
tk = micro ? mtM : mt
|
|
cst = micro ? costUsdM : costUsd
|
|
cm = micro ? commM : comm
|
|
n = math.max(1, math.min(cap, math.round(stopU / (p * atrFrac * atrD))))
|
|
sp = math.floor(math.max(stopU - cst * n, 0) / (n * p) / tk + 1e-6) * tk
|
|
tp = math.ceil((tgtU + cm * n) / (n * p) / tk - 1e-6) * tk
|
|
[n, sp, tp, sp * n * p, tp * n * p, micro]
|
|
|
|
if barstate.islast
|
|
table.clear(t, 0, 6, 12, 16)
|
|
if barstate.islast and showAcct
|
|
hdr2 = array.from("#", "Account", "Market", "Stage", "Side", "Entry (ET)", "Risk USD", "Reward USD", "Contracts", "Stop (pts)", "Target (pts)", "Reward : risk", "Note")
|
|
for i = 0 to 12
|
|
table.cell(t, i, 6, hdr2.get(i), text_color = color.white, bgcolor = color.new(color.gray, 60), text_size = szAcc, text_halign = hAl)
|
|
int rr = 6
|
|
for k = 0 to 9
|
|
mk = aMkt.get(k)
|
|
if mk != "Off"
|
|
rr += 1
|
|
r = rr
|
|
bal = aBal.get(k)
|
|
flr = aFlr.get(k)
|
|
room = bal - flr
|
|
isF = aStg.get(k) == "Funded"
|
|
is25 = aSize.get(k) == "25K"
|
|
S0 = is25 ? 25000.0 : 50000.0
|
|
DDa = is25 ? 1000.0 : 2000.0
|
|
float tgtU = na
|
|
bool eligible = false
|
|
string note = ""
|
|
if not isF
|
|
tgtU := (aTgt.get(k) > 0 ? aTgt.get(k) : S0 + (is25 ? 1250.0 : 3000.0)) - bal
|
|
else
|
|
W = aPay.get(k) == 1 ? (is25 ? 1000.0 : 2000.0) : (is25 ? 1500.0 : 2500.0)
|
|
c0 = aC0.get(k) > 0 ? aC0.get(k) : S0
|
|
bst = aBest.get(k)
|
|
thrB = S0 + DDa + 100.0 + W
|
|
needF = math.max(thrB - c0, 500.0, bst / 0.4)
|
|
rem = c0 + needF - bal
|
|
cyc = bal - c0
|
|
eligible := bal >= thrB and cyc >= 500.0 and bst <= 0.4 * cyc
|
|
tgtU := math.max(math.min(0.4 * needF, rem), 50.0)
|
|
note := "payout " + str.tostring(aPay.get(k)) + " at " + usd(c0 + needF) + (bst / 0.4 > thrB - c0 ? " (set by the 40% rule)" : "")
|
|
float stopU = room
|
|
if not isF and acctEnd and tgtU > 0 and tgtU <= endThr
|
|
stopU := math.min(room, tgtU)
|
|
note := "endgame: 1:1 stop"
|
|
bool bad = true
|
|
if bal <= 0 or flr <= 0
|
|
note := "enter balance and drawdown limit"
|
|
else if room < 50
|
|
note := "no room left: account is done"
|
|
else if not isF and room > DDa + 0.5
|
|
note := "room over " + usd(DDa) + ": check balance / limit"
|
|
else if not isF and tgtU <= 0
|
|
note := "target reached: passed"
|
|
else if isF and eligible
|
|
note := "PAYOUT ELIGIBLE: request the payout, no trade"
|
|
else
|
|
bad := false
|
|
int side = mk == "Gold" ? goldDir : mk == "NQ" ? nqDir : clDir
|
|
string ent = mk == "Gold" ? "8:21" : mk == "Crude" ? "9:01" : mk == "Nat gas" ? "6:01 pm (prev. eve)" : nqEntry
|
|
int n = 0
|
|
float sp = na
|
|
float tp = na
|
|
float rU = na
|
|
float wU = na
|
|
bool mic = false
|
|
if not bad
|
|
if mk == "Gold"
|
|
[n1, s1, t1, r1, w1, m1] = sizeAcct(gcAtr, gcPv, gcMt, gcComm, gcCommM, 10, gcMt, false, stopU, tgtU)
|
|
n := n1
|
|
sp := s1
|
|
tp := t1
|
|
rU := r1
|
|
wU := w1
|
|
mic := m1
|
|
else if mk == "Crude"
|
|
[n1, s1, t1, r1, w1, m1] = sizeAcct(clAtr, clPv, clMt, clComm, clCommM, 10, clMt, false, stopU, tgtU)
|
|
n := n1
|
|
sp := s1
|
|
tp := t1
|
|
rU := r1
|
|
wU := w1
|
|
mic := m1
|
|
else if mk == "NQ"
|
|
[n1, s1, t1, r1, w1, m1] = sizeAcct(nqAtr, nqPv, nqMt, nqComm, nqCommM, 10, nqMt, nqFull, stopU, tgtU)
|
|
n := n1
|
|
sp := s1
|
|
tp := t1
|
|
rU := r1
|
|
wU := w1
|
|
mic := m1
|
|
else
|
|
[n1, s1, t1, r1, w1, m1] = sizeAcct(ngAtr, ngPv, ngMt, ngComm, ngCommM, 4, 0.005, false, stopU, tgtU)
|
|
n := n1
|
|
sp := s1
|
|
tp := t1
|
|
rU := r1
|
|
wU := w1
|
|
mic := m1
|
|
sfx = not mic ? "" : mk == "Gold" ? " MGC" : mk == "Crude" ? " MCL" : mk == "NQ" ? " MNQ" : " QG"
|
|
txt = bad ? color.gray : color.white
|
|
table.cell(t, 0, r, str.tostring(k + 1), text_color = color.white, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 1, r, aName.get(k), text_color = color.white, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 2, r, mk, text_color = color.white, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 3, r, aSize.get(k) + " " + aStg.get(k), text_color = isF ? color.aqua : color.white, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 4, r, bad ? "-" : sideText(side), text_color = bad ? color.gray : sideColor(side), text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 5, r, bad ? "-" : ent, text_color = txt, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 6, r, bad ? "-" : usd(rU), text_color = bad ? color.gray : color.red, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 7, r, bad ? "-" : usd(wU), text_color = bad ? color.gray : color.lime, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 8, r, bad ? "-" : str.tostring(n) + sfx, text_color = mic ? color.yellow : txt, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 9, r, bad ? "-" : pts(sp), text_color = bad ? color.gray : color.new(color.red, 40), text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 10, r, bad ? "-" : pts(tp), text_color = bad ? color.gray : color.new(color.lime, 40), text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 11, r, bad or na(rU) or rU <= 0 ? "-" : str.tostring(wU / rU, "#.##") + " : 1", text_color = txt, text_size = szAcc, text_halign = hAl)
|
|
table.cell(t, 12, r, note, text_color = bad ? color.orange : color.new(color.white, 30), text_size = szAcc, text_halign = hAl)
|
|
if rr == 6
|
|
table.cell(t, 0, 7, "No accounts entered: fill Account 1-10 in Settings (Market not Off).", text_color = color.new(color.white, 30), text_size = szAcc, text_halign = hAl)
|
|
table.merge_cells(t, 0, 7, 12, 7)
|
|
|
|
// ---------- alerts (set to "Once Per Bar") ----------
|
|
goldNew = goldDir != 0 and nz(goldDir[1]) == 0
|
|
nqNew = nqDir != 0 and nz(nqDir[1]) == 0
|
|
alertcondition(goldNew and goldDir == 1, "Gold LONG", "Gold bracket LONG at 8:21 ET")
|
|
alertcondition(goldNew and goldDir == -1, "Gold SHORT", "Gold bracket SHORT at 8:21 ET")
|
|
alertcondition(clEntryNow and clDir == 1, "Crude LONG", "Crude bracket LONG at 9:01 ET")
|
|
alertcondition(clEntryNow and clDir == -1, "Crude SHORT", "Crude bracket SHORT at 9:01 ET")
|
|
alertcondition(ngEntryNow and clDir == 1, "Nat gas LONG", "Nat gas bracket LONG at 6:01 pm ET for the next trading day (same side as crude)")
|
|
alertcondition(ngEntryNow and clDir == -1, "Nat gas SHORT", "Nat gas bracket SHORT at 6:01 pm ET for the next trading day (same side as crude)")
|
|
alertcondition(useNews and news and not news[1], "NQ news day", "NQ news day: 8:30 signal check (entry 8:31 / 8:33, else the normal 9:31 / 9:33 rule)")
|
|
alertcondition(nqNew and nqDir == 1, "NQ LONG", "NQ bracket LONG now")
|
|
alertcondition(nqNew and nqDir == -1, "NQ SHORT", "NQ bracket SHORT now")
|