add v2
This commit is contained in:
1 parent
421050292d
commit
ce36cba8e9
2978 files changed
+35317
-85
No files matched your search
@@ -23,8 +23,9 @@
|
||||
// 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;
|
||||
// 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.
|
||||
// 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.
|
||||
@@ -70,7 +71,7 @@ ngComm = input.float(4.00, "Natural gas", step = 0.1, group = grpF, display = di
|
||||
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)
|
||||
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
|
||||
@@ -198,15 +199,16 @@ endOn = needUsd > 0
|
||||
stopEff = endOn and needUsd <= endThr ? needUsd : stopUsd
|
||||
tgtEff = endOn ? needUsd : targetUsd
|
||||
|
||||
sizeFor(atrD, pv, mt, comm, commM) =>
|
||||
sizeFor(atrD, pv, mt, comm, commM, ratio, mtM) =>
|
||||
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
|
||||
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) / 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
|
||||
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 ----------
|
||||
@@ -291,10 +293,10 @@ nqBranch = pending ? (useNews ? "waiting for the 8:30 candle (news check at 8:3
|
||||
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)
|
||||
[clN, clSp, clTp, clRiskUsd, clRewUsd, clMicro] = sizeFor(clAtr, clPv, clMt, clComm, clCommM)
|
||||
[nqN, nqSp, nqTp, nqRiskUsd, nqRewUsd, nqMicro] = sizeFor(nqAtr, nqPv, nqMt, nqComm, nqCommM)
|
||||
[ngN, ngSp, ngTp, ngRiskUsd, ngRewUsd, ngMicro] = sizeFor(ngAtr, ngPv, ngMt, ngComm, ngCommM)
|
||||
[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)
|
||||
[ngN, ngSp, ngTp, ngRiskUsd, ngRewUsd, ngMicro] = sizeFor(ngAtr, ngPv, ngMt, ngComm, ngCommM, 4, 0.005)
|
||||
|
||||
// ---------- display ----------
|
||||
|
||||
@@ -331,7 +333,7 @@ if barstate.islast
|
||||
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, 4, 3, num(ngAtr), text_color = color.white)
|
||||
table.cell(t, 5, 3, str.tostring(ngN) + (ngMicro ? " MNG" : ""), text_color = ngMicro ? color.yellow : color.white)
|
||||
table.cell(t, 5, 3, str.tostring(ngN) + (ngMicro ? " QG" : ""), text_color = ngMicro ? color.yellow : color.white)
|
||||
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, 8, 3, pts(ngSp), text_color = color.new(color.red, 40))
|
||||
|
||||
Reference in new issue
Block a user