This commit is contained in:
wvr committed 2026-11-20 19:22:54 -06:00
1 parent a6d6c012f0
commit 4eedcc7e26
1 file changed
+36 -14
+36 -14
View File
@@ -22,6 +22,10 @@
// 4. Otherwise (9:33): the old rule. 9:30 close vs yesterday's 4:00 pm close: above -> SHORT, below -> LONG. // 4. Otherwise (9:33): the old rule. 9:30 close vs yesterday's 4:00 pm close: above -> SHORT, below -> LONG.
// Sizing: contracts = round(stop $ / ($ per point x 0.20 x daily ATR(14))), min 1, max 4; // Sizing: contracts = round(stop $ / ($ per point x 0.20 x daily ATR(14))), min 1, max 4;
// stop pts = (stop $ - $20 x contracts) / (contracts x $ per point); target pts = (target $ + commission x contracts) / (contracts x $ per point). // stop pts = (stop $ - $20 x contracts) / (contracts x $ per point); target pts = (target $ + commission x contracts) / (contracts x $ per point).
// Micros (MGC / MCL / MNQ / MNG, 1/10 size, max 40) when the stop $ is under 75% of one full contract's risk at
// the ATR stop distance; then $3 allowance per micro and micro commissions.
// 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. // 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). // 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. // Exact months (e.g. NQZ2026) avoid even that, if you prefer.
@@ -52,11 +56,19 @@ targetUsd = input.float(3000, "Target $", step = 50, group = grpS, display = dis
atrFrac = input.float(0.20, "Stop as share of daily ATR", step = 0.01, 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) maxC = input.int(4, "Max contracts (full-size)", minval = 1, group = grpS, display = display.none)
costUsd = input.float(20, "Stop: cost allowance per contract, round trip ($)", step = 1, group = grpS, tooltip = "Commission plus slippage. Taken off the stop, which can slip.", display = display.none) costUsd = input.float(20, "Stop: cost allowance per contract, round trip ($)", step = 1, group = grpS, tooltip = "Commission plus slippage. Taken off the stop, which can slip.", display = display.none)
costUsdM = input.float(3, "Stop: cost allowance per micro, round trip ($)", step = 0.5, group = grpS, 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." 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) 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) 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) 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) 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(1.00, "Micro nat gas (MNG)", step = 0.1, group = grpF, display = display.none)
// ---------- helpers (evaluated in each symbol's own context via request.security) ---------- // ---------- 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 endsAt(h, m) => hour(time_close, tz) == h and minute(time_close, tz) == m
@@ -180,11 +192,20 @@ clSignal() =>
dailyInfo() => [ta.atr(14)[1], syminfo.pointvalue, syminfo.mintick] // yesterday's ATR, completed days only dailyInfo() => [ta.atr(14)[1], syminfo.pointvalue, syminfo.mintick] // yesterday's ATR, completed days only
sizeFor(atrD, pv, mt, comm) => endOn = needUsd > 0
n = math.max(1, math.min(maxC, math.round(stopUsd / (pv * atrFrac * atrD)))) stopEff = endOn and needUsd <= endThr ? needUsd : stopUsd
sp = math.floor(math.max(stopUsd - costUsd * n, 0) / (n * pv) / mt + 1e-6) * mt // 1e-6 guards against float error (1.18 / 0.01 = 117.999...) tgtEff = endOn ? needUsd : targetUsd
tp = math.ceil((targetUsd + comm * n) / (n * pv) / mt - 1e-6) * mt
[n, sp, tp, sp * n * pv, tp * n * pv] // last two: what to type as Risk USD / Reward USD (whole position) sizeFor(atrD, pv, mt, comm, commM) =>
micro = stopEff < 0.75 * pv * atrFrac * atrD // stop too small for one full contract at the ATR stop distance
p = micro ? pv / 10 : pv
cap = micro ? maxC * 10 : maxC
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) / mt + 1e-6) * mt // 1e-6 guards against float error (1.18 / 0.01 = 117.999...)
tp = math.ceil((tgtEff + cm * n) / (n * p) / mt - 1e-6) * mt
[n, sp, tp, sp * n * p, tp * n * p, micro] // Risk USD / Reward USD = whole position
// ---------- display helpers ---------- // ---------- display helpers ----------
sideText(d) => d == 1 ? "LONG" : d == -1 ? "SHORT" : "waiting" sideText(d) => d == 1 ? "LONG" : d == -1 ? "SHORT" : "waiting"
@@ -267,10 +288,10 @@ nqBranch = pending ? "waiting for the 8:30 candle (news check at 8:31)" :
nqEntry = pending ? "8:31 / 8:33 / 9:31 / 9:33" : newsWait ? "8:33 (or 9:31 / 9:33)" : newsTrade ? (aDisp != 0 ? "8:31" : "8:33") : hEntry nqEntry = pending ? "8:31 / 8:33 / 9:31 / 9:33" : newsWait ? "8:33 (or 9:31 / 9:33)" : newsTrade ? (aDisp != 0 ? "8:31" : "8:33") : hEntry
// ---------- sizing ---------- // ---------- sizing ----------
[gcN, gcSp, gcTp, gcRiskUsd, gcRewUsd] = sizeFor(gcAtr, gcPv, gcMt, gcComm) [gcN, gcSp, gcTp, gcRiskUsd, gcRewUsd, gcMicro] = sizeFor(gcAtr, gcPv, gcMt, gcComm, gcCommM)
[clN, clSp, clTp, clRiskUsd, clRewUsd] = sizeFor(clAtr, clPv, clMt, clComm) [clN, clSp, clTp, clRiskUsd, clRewUsd, clMicro] = sizeFor(clAtr, clPv, clMt, clComm, clCommM)
[nqN, nqSp, nqTp, nqRiskUsd, nqRewUsd] = sizeFor(nqAtr, nqPv, nqMt, nqComm) [nqN, nqSp, nqTp, nqRiskUsd, nqRewUsd, nqMicro] = sizeFor(nqAtr, nqPv, nqMt, nqComm, nqCommM)
[ngN, ngSp, ngTp, ngRiskUsd, ngRewUsd] = sizeFor(ngAtr, ngPv, ngMt, ngComm) [ngN, ngSp, ngTp, ngRiskUsd, ngRewUsd, ngMicro] = sizeFor(ngAtr, ngPv, ngMt, ngComm, ngCommM)
// ---------- display ---------- // ---------- display ----------
@@ -285,7 +306,7 @@ if barstate.islast
table.cell(t, 2, 1, sideText(goldDir), text_color = sideColor(goldDir)) table.cell(t, 2, 1, sideText(goldDir), text_color = sideColor(goldDir))
table.cell(t, 3, 1, "gap " + num(goldGap) + "% vs " + num(thr) + "%" + (liveMed ? " (live median)" : " (input)") + " | now " + num(gap) + "%", text_color = color.white) table.cell(t, 3, 1, "gap " + num(goldGap) + "% vs " + num(thr) + "%" + (liveMed ? " (live median)" : " (input)") + " | now " + num(gap) + "%", text_color = color.white)
table.cell(t, 4, 1, num(gcAtr), text_color = color.white) table.cell(t, 4, 1, num(gcAtr), text_color = color.white)
table.cell(t, 5, 1, num(gcN), text_color = color.white) table.cell(t, 5, 1, str.tostring(gcN) + (gcMicro ? " MGC" : ""), text_color = gcMicro ? color.yellow : color.white)
table.cell(t, 6, 1, usd(gcRiskUsd), text_color = color.red) table.cell(t, 6, 1, usd(gcRiskUsd), text_color = color.red)
table.cell(t, 7, 1, usd(gcRewUsd), text_color = color.lime) table.cell(t, 7, 1, usd(gcRewUsd), text_color = color.lime)
table.cell(t, 8, 1, pts(gcSp), text_color = color.new(color.red, 40)) table.cell(t, 8, 1, pts(gcSp), text_color = color.new(color.red, 40))
@@ -296,7 +317,7 @@ if barstate.islast
table.cell(t, 2, 2, sideText(clDir), text_color = sideColor(clDir)) table.cell(t, 2, 2, sideText(clDir), text_color = sideColor(clDir))
table.cell(t, 3, 2, "yesterday: settle " + num(clSettle) + " vs 9:00 close " + num(clOpen), text_color = color.white) table.cell(t, 3, 2, "yesterday: settle " + num(clSettle) + " vs 9:00 close " + num(clOpen), text_color = color.white)
table.cell(t, 4, 2, num(clAtr), text_color = color.white) table.cell(t, 4, 2, num(clAtr), text_color = color.white)
table.cell(t, 5, 2, num(clN), text_color = color.white) table.cell(t, 5, 2, str.tostring(clN) + (clMicro ? " MCL" : ""), text_color = clMicro ? color.yellow : color.white)
table.cell(t, 6, 2, usd(clRiskUsd), text_color = color.red) table.cell(t, 6, 2, usd(clRiskUsd), text_color = color.red)
table.cell(t, 7, 2, usd(clRewUsd), text_color = color.lime) table.cell(t, 7, 2, usd(clRewUsd), text_color = color.lime)
table.cell(t, 8, 2, pts(clSp), text_color = color.new(color.red, 40)) table.cell(t, 8, 2, pts(clSp), text_color = color.new(color.red, 40))
@@ -307,7 +328,7 @@ if barstate.islast
table.cell(t, 2, 3, sideText(clDir), text_color = sideColor(clDir)) table.cell(t, 2, 3, sideText(clDir), text_color = sideColor(clDir))
table.cell(t, 3, 3, "crude's side for the trading day that opens at 6 pm (no hedging)", text_color = color.white) table.cell(t, 3, 3, "crude's side for the trading day that opens at 6 pm (no hedging)", text_color = color.white)
table.cell(t, 4, 3, num(ngAtr), text_color = color.white) table.cell(t, 4, 3, num(ngAtr), text_color = color.white)
table.cell(t, 5, 3, num(ngN), text_color = color.white) table.cell(t, 5, 3, str.tostring(ngN) + (ngMicro ? " MNG" : ""), text_color = ngMicro ? color.yellow : color.white)
table.cell(t, 6, 3, usd(ngRiskUsd), text_color = color.red) table.cell(t, 6, 3, usd(ngRiskUsd), text_color = color.red)
table.cell(t, 7, 3, usd(ngRewUsd), text_color = color.lime) table.cell(t, 7, 3, usd(ngRewUsd), text_color = color.lime)
table.cell(t, 8, 3, pts(ngSp), text_color = color.new(color.red, 40)) table.cell(t, 8, 3, pts(ngSp), text_color = color.new(color.red, 40))
@@ -318,13 +339,14 @@ if barstate.islast
table.cell(t, 2, 4, sideText(nqDir), text_color = sideColor(nqDir)) table.cell(t, 2, 4, sideText(nqDir), text_color = sideColor(nqDir))
table.cell(t, 3, 4, nqBranch, text_color = color.white) table.cell(t, 3, 4, nqBranch, text_color = color.white)
table.cell(t, 4, 4, num(nqAtr), text_color = color.white) table.cell(t, 4, 4, num(nqAtr), text_color = color.white)
table.cell(t, 5, 4, num(nqN), text_color = color.white) table.cell(t, 5, 4, str.tostring(nqN) + (nqMicro ? " MNQ" : ""), text_color = nqMicro ? color.yellow : color.white)
table.cell(t, 6, 4, usd(nqRiskUsd), text_color = color.red) table.cell(t, 6, 4, usd(nqRiskUsd), text_color = color.red)
table.cell(t, 7, 4, usd(nqRewUsd), text_color = color.lime) table.cell(t, 7, 4, usd(nqRewUsd), text_color = color.lime)
table.cell(t, 8, 4, pts(nqSp), text_color = color.new(color.red, 40)) table.cell(t, 8, 4, pts(nqSp), text_color = color.new(color.red, 40))
table.cell(t, 9, 4, pts(nqTp), text_color = color.new(color.lime, 40)) table.cell(t, 9, 4, pts(nqTp), text_color = color.new(color.lime, 40))
note = "USD amounts include costs (stop: slippage + commission; target: commission): type as shown. Per-account sizes: tracker. Skip holidays and early closes." 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 + "USD amounts include costs (stop: slippage + commission; target: commission): type as shown. Yellow = micros. Per-account sizes: tracker. Skip holidays and early closes."
table.cell(t, 0, 5, note, text_color = color.new(color.white, 30), text_size = size.small) table.cell(t, 0, 5, note, text_color = color.new(color.white, 30), text_size = size.small)
table.merge_cells(t, 0, 5, 9, 5) table.merge_cells(t, 0, 5, 9, 5)