Payout Odds Tester
THE SOURCE FILE /code/payout-odds.pine
Read the file, copy it, or download the exact bytes served at this address. No performance figure is claimed on this page.
lines of source415
categoryOptions & evaluation
panestrategy
Pine versionv6
//@version=6
// DAAVILE PAYOUT ODDS TESTER — PROVEN KINEMATICS SIGNAL + DAAVILE SAUCE.
// Historical base evidence only: BTC PF 9.43 / ETH PF 2.43, 15m, risk 2,
// Immediately, grid 3, Positive, trail 2 (SETTINGS-SWEEP-2026-11-27.md).
// No current PF or base-retention claim is made by this source. NO PROFIT PROMISE.
// Pine strategy() is a simulator: MFP has no native tester, cannot place orders,
// and preview omits fees/slippage/funding. LABEL B is NOT EMITTED (needs T3).
// LABEL A is a CONSERVATIVE OBSERVED-EQUITY LOWER-BOUND estimate, not a tick
// certificate: signed candle extremes are used only when exposure stayed stable;
// transition bars are unresolved and count against target-first, never for it.
// Account/prop equity and idea-level returns are separate measurement bases.
strategy("DAAVILE Payout Odds Tester", overlay=true,
initial_capital = 100000,
commission_type = strategy.commission.percent,
commission_value = 0,
pyramiding = 4,
process_orders_on_close = false)
//--- THE ONLY 8 EDITABLE INPUTS — proven kinematics winners.
allowLong = input.bool(true, "Allow buys")
allowShort = input.bool(true, "Allow sells")
entryMode = input.string("Immediately", "Entry trigger", options=["Immediately", "After 1 bar", "After 2 bars", "After 3 bars", "After 10 seconds", "After 30 seconds", "After 60 seconds"])
useGrid = input.bool(true, "Grid entries (pyramid)")
gridLevels = input.int(3, "Grid levels (1 = single entry)", minval=1, maxval=4)
addMode = input.string("Positive", "Add direction", options=["Positive", "Negative"])
riskPercent = input.float(2.0, "Risk per idea, % of equity", minval=0.01, maxval=100.0)
trailATR = input.float(2.0, "Trailing step (ATR points or %)", minval=0.5)
//--- NAMED DIRECT-CODE VALUES — no settings slot, payout defaults permissive.
float minRR = 1.5
int sessionStart = 20
int sessionEnd = 21
int PIV = 5
int LOOK = 4
float DECAY = 0.9
float BREAK = 0.15
int MAXBAR = 36
int PENDMAX = 12
string SESSION_TZ = "America/New_York"
float startBalance = 10000.0
float TARGET_PCT = 10.0
float DLL_PCT = 3.0
float DLL_GUARD_MONEY = 75.0
bool dllGuardOn = false
float profitToStopPct = 100.0
float ddToStopPct = 100.0
float MAX_TOTAL_RISK = 6.0
int TRAIL_MODE = 0 // 0 = ATR-denominated price points, 1 = percent
int CLOSE_MODE = 0 // independent close trigger: 0 = points, 1 = percent
float CLOSE_STEP = 2.0 // independent ATR points or percent; not the SL line
float BASIC_SL_ATR = 2.5 // fixed disaster brake behind the active trail
//--- small helpers.
gA(x) => x > 0 ? 1 : x < 0 ? -1 : 0
levelPrice(b, step, sign, k) => b + sign * step * k
fmtPct(x) => na(x) ? "n/a" : str.tostring(x * 100.0, "#.##") + "%"
float pdh = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
float pdl = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
float pdc = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
float wH = request.security(syminfo.tickerid, "W", high[1], lookahead=barmerge.lookahead_on)
float wL = request.security(syminfo.tickerid, "W", low[1], lookahead=barmerge.lookahead_on)
float atr = ta.atr(14)
float vwap = ta.vwap(hlc3)
float pivot = (pdh + pdl + pdc) / 3.0
float swH = ta.pivothigh(high, PIV, PIV)[1]
float swL = ta.pivotlow(low, PIV, PIV)[1]
//--- structure level book, rebuilt each bar.
array<float> bpx = array.new_float()
array<int> bfam = array.new_int()
array<float> bdy = array.new_float()
addLvl(px, fam, dy) =>
if not na(px) and px > 0
array.push(bpx, px)
array.push(bfam, fam)
array.push(bdy, dy)
addLvl(pdh, 0, 1.0)
addLvl(pdl, 0, 1.0)
addLvl(pivot, 0, 0.8)
addLvl((pdh + pdl) / 2.0, 0, 0.7)
addLvl(wH, 1, 1.1)
addLvl(wL, 1, 1.1)
addLvl(vwap, 2, 1.2)
addLvl(swH, 3, 1.3)
addLvl(swL, 3, 1.3)
//--- online 7-family learner.
var array<float> win = array.new_float(7, 0.0)
var array<float> los = array.new_float(7, 0.0)
var array<int> pDir = array.new_int(7, 0)
var array<int> pBar = array.new_int(7, 0)
var array<float> pPx = array.new_float(7, na)
cB(f) => 2.0 * (array.get(win, f) + 3.0) / (array.get(win, f) + array.get(los, f) + 6.0)
if barstate.isconfirmed and not na(atr) and atr > 0
for i = 0 to 6
if array.get(pDir, i) != 0 and bar_index - array.get(pBar, i) >= LOOK
if array.get(pDir, i) == 1 ? close > array.get(pPx, i) : close < array.get(pPx, i)
array.set(win, i, array.get(win, i) * DECAY + 1.0)
else
array.set(los, i, array.get(los, i) * DECAY + 1.0)
array.set(pDir, i, 0)
if array.size(bpx) > 0
for k = 0 to array.size(bpx) - 1
float px = array.get(bpx, k)
if math.abs(close - px) >= atr * BREAK
int f = array.get(bfam, k)
if array.get(pDir, f) == 0
if close[1] <= px and close > px
array.set(pDir, f, 1)
array.set(pBar, f, bar_index)
array.set(pPx, f, px)
else if close[1] >= px and close < px
array.set(pDir, f, -1)
array.set(pBar, f, bar_index)
array.set(pPx, f, px)
//--- kinematics and conviction: signal formulas deliberately unchanged.
float v3 = (close - close[3]) / 3.0
float velN = atr > 0 ? v3 / atr : 0.0
float accN = atr > 0 ? (v3 - nz(v3[3])) / atr : 0.0
int regime = velN > 0.12 and accN > 0 ? 1 : velN < -0.12 and accN < 0 ? -1 : 0
float bestLong = 0.0
float bestShort = 0.0
float longPx = na
float shortPx = na
if atr > 0 and array.size(bpx) > 0
for k = 0 to array.size(bpx) - 1
float px = array.get(bpx, k)
float sc = array.get(bdy, k) * cB(array.get(bfam, k)) - 0.25 * math.abs(close - px) / atr
if px < close and sc > bestLong
bestLong := sc
longPx := px
if px > close and sc > bestShort
bestShort := sc
shortPx := px
float kin = 0.32 * gA(close - vwap) + 0.24 * gA(velN) + 0.22 * gA(close - pivot) + 0.22 * regime
float convLong = kin + 0.45 * bestLong - 0.30 * bestShort
float convShort = -kin + 0.45 * bestShort - 0.30 * bestLong
bool strong = math.max(convLong, convShort) >= 0.85 and math.abs(convLong - convShort) >= 0.35
//--- idea and plan state.
var int pendSide = 0
var int pendBorn = na
var int pendTime = na
var float pendEntry = na
var float pendStop = na
var float pendGoal = na
var float pendTrailDist = na
var float pendCloseDist = na
var int ideaSide = 0
var int ideaBorn = na
var float ideaGoal = na
var float ideaTrailDist = na
var float ideaCloseDist = na
var float ideaBasicStop = na
var float ideaStop = na
var int lastDay = na
var float hiSince = na
var float loSince = na
//--- prop-account reporting state (Pine uses strategy equity as its explicit proxy).
var int curNyDay = na
var float dayStartEquity = na
var float dayFloor = na
var bool dayHalted = false
var bool prevNySess = false
var bool sessHitTarget = false
var bool sessHitDll = false
var bool sessIncomplete = false
var int sessTargetFirst = 0
var int sessDllFirst = 0
var int sessInconclusive = 0
//--- idea-only realized P&L and actual initial money risk.
var float prevPosSize = 0.0
var bool ideaOpen = false
var float ideaRiskMoney = na
var float ideaRealized = 0.0
var int lastClosedTrade = 0
var int closedIdeas = 0
var int wins = 0
var int losses = 0
var float sumWinR = 0.0
var float sumLossR = 0.0
cancelEntries() =>
strategy.cancel("L1")
strategy.cancel("L2")
strategy.cancel("L3")
strategy.cancel("L4")
strategy.cancel("S1")
strategy.cancel("S2")
strategy.cancel("S3")
strategy.cancel("S4")
openRiskMoney() =>
float total = strategy.opentrades > 0 and na(ideaStop) ? 1.0e100 : 0.0
if strategy.opentrades > 0 and not na(ideaStop)
for i = 0 to strategy.opentrades - 1
float signedQty = strategy.opentrades.size(i)
float entry = strategy.opentrades.entry_price(i)
float side = signedQty >= 0 ? 1.0 : -1.0
total += math.max(0.0, side * (entry - ideaStop)) * math.abs(signedQty)
total
if barstate.isconfirmed
//--- ACCOUNT/PROP BASIS: moving NY-midnight DLL floor and permissive halts.
int nyDay = year(time, SESSION_TZ) * 10000 + month(time, SESSION_TZ) * 100 + dayofmonth(time, SESSION_TZ)
float propEquity = strategy.equity
if nyDay != curNyDay
dayStartEquity := na(dayStartEquity) ? propEquity : strategy.equity[1]
curNyDay := nyDay
dayHalted := false
sessHitTarget := false
sessHitDll := false
sessIncomplete := false
float dllMoney = startBalance * DLL_PCT / 100.0
float targetMoney = startBalance * TARGET_PCT / 100.0
dayFloor := na(dayStartEquity) ? startBalance - dllMoney : dayStartEquity - dllMoney
float dayPL = na(dayStartEquity) ? 0.0 : propEquity - dayStartEquity
bool nearFloor = dllGuardOn and propEquity - dayFloor < DLL_GUARD_MONEY
if dayPL >= startBalance * profitToStopPct / 100.0 or dayPL <= -startBalance * ddToStopPct / 100.0
dayHalted := true
float ownedRisk = openRiskMoney()
bool riskBlock = ownedRisk > propEquity * MAX_TOTAL_RISK / 100.0
bool payoutBlock = nearFloor or dayHalted
bool newExposureBlock = payoutBlock or riskBlock
//--- IDEA BASIS: closed-trade P&L / actual cash budget reserved at submission.
float posNow = strategy.position_size
int closedNow = strategy.closedtrades
int newClosed = math.max(0, closedNow - lastClosedTrade)
if closedNow > lastClosedTrade
for tr = lastClosedTrade to closedNow - 1
if ideaOpen
ideaRealized += strategy.closedtrades.profit(tr)
lastClosedTrade := closedNow
if ideaOpen and posNow == 0 and (prevPosSize != 0 or newClosed > 0)
float rIdea = not na(ideaRiskMoney) and ideaRiskMoney > 0 ? ideaRealized / ideaRiskMoney : 0.0
closedIdeas += 1
if rIdea > 0
wins += 1
sumWinR += rIdea
else
losses += 1
sumLossR += math.abs(rIdea)
ideaOpen := false
ideaRiskMoney := na
ideaRealized := 0.0
ideaSide := 0
ideaGoal := na
ideaTrailDist := na
ideaCloseDist := na
ideaBasicStop := na
ideaStop := na
//--- LABEL A: flat-after-exit close equity is observed; candle extremes are
//--- admitted only for stable exposure. Any DLL touch outranks target-first.
bool inNySess = (hour(time, SESSION_TZ) > 9 or (hour(time, SESSION_TZ) == 9 and minute(time, SESSION_TZ) >= 30)) and hour(time, SESSION_TZ) < 16
bool wasNySess = prevNySess
prevNySess := inNySess
if inNySess and not na(dayStartEquity)
if propEquity >= dayStartEquity + targetMoney
sessHitTarget := true
if propEquity <= dayFloor
sessHitDll := true
bool stableExposure = posNow == prevPosSize and newClosed == 0
if stableExposure and posNow != 0
float favorable = posNow > 0 ? high : low
float adverse = posNow > 0 ? low : high
if not sessHitTarget and propEquity + posNow * (favorable - close) >= dayStartEquity + targetMoney
sessHitTarget := true
if not sessHitDll and propEquity + posNow * (adverse - close) <= dayFloor
sessHitDll := true
else if posNow != prevPosSize or newClosed > 0
sessIncomplete := true
if wasNySess and not inNySess
if sessHitDll
sessDllFirst += 1
else if sessHitTarget and not sessIncomplete
sessTargetFirst += 1
else if sessHitTarget or sessIncomplete
sessInconclusive += 1
sessHitTarget := false
sessHitDll := false
sessIncomplete := false
//--- An actual enabled stop blocks NEW exposure only. Existing positions
//--- retain their normal basic SL, trail, goal and discretionary exits.
if newExposureBlock
pendSide := 0
cancelEntries()
//--- PROVEN BASE: NY clock, pending plan, market leg + limit grid adds.
int n = useGrid ? math.max(1, math.min(4, gridLevels)) : 1
int sg = addMode == "Negative" ? -1 : 1
bool inSess = sessionStart < sessionEnd ? hour(time, SESSION_TZ) >= sessionStart and hour(time, SESSION_TZ) < sessionEnd : hour(time, SESSION_TZ) >= sessionStart or hour(time, SESSION_TZ) < sessionEnd
if ideaSide == 0 and pendSide == 0 and strong and (na(lastDay) or nyDay != lastDay) and inSess and not newExposureBlock
int side = convLong >= convShort ? 1 : -1
float entry = side == 1 ? longPx : shortPx
if (side == 1 ? allowLong : allowShort) and not na(entry) and not na(atr) and atr > 0
float recent = side == 1 ? ta.lowest(low, 6)[1] : ta.highest(high, 6)[1]
float signalStopDist = math.max(atr * 1.5, side == 1 ? entry - recent : recent - entry)
float stopDist = math.max(signalStopDist, BASIC_SL_ATR * atr)
float goal = na
if array.size(bpx) > 0
for k = 0 to array.size(bpx) - 1
float px = array.get(bpx, k)
if side * (px - entry) >= minRR * signalStopDist and (na(goal) or side * (px - goal) < 0)
goal := px
if na(goal)
goal := entry + side * minRR * signalStopDist
pendSide := side
pendBorn := bar_index
pendTime := time_close
pendEntry := entry
pendStop := entry - side * stopDist
pendGoal := goal
pendTrailDist := trailATR * atr
pendCloseDist := CLOSE_STEP * atr
lastDay := nyDay
if pendSide != 0 and (bar_index - pendBorn > PENDMAX or not inSess or (pendSide == 1 and convLong < 0) or (pendSide == -1 and convShort < 0))
pendSide := 0
int delayBars = entryMode == "After 1 bar" ? 1 : entryMode == "After 2 bars" ? 2 : entryMode == "After 3 bars" ? 3 : 0
int delaySecs = entryMode == "After 10 seconds" ? 10 : entryMode == "After 30 seconds" ? 30 : entryMode == "After 60 seconds" ? 60 : 0
bool fired = delayBars > 0 ? bar_index - pendBorn >= delayBars : delaySecs > 0 ? (not na(pendTime) and time - pendTime >= delaySecs * 1000) : true
if pendSide != 0 and fired and ideaSide == 0 and strategy.position_size == 0 and not na(atr) and atr > 0 and not newExposureBlock
float riskDist = math.abs(pendEntry - pendStop)
float riskCash = strategy.equity * riskPercent / 100.0
float qty = riskDist > 0 ? math.floor(riskCash / riskDist) : 0.0
float perQty = n > 0 ? qty / n : 0.0
float gStep = n > 0 ? riskDist / n : 0.0
if perQty > 0 and ownedRisk + riskCash <= strategy.equity * MAX_TOTAL_RISK / 100.0
int sign = pendSide * sg
if pendSide == 1
strategy.entry("L1", strategy.long, qty = perQty)
if n >= 2
strategy.entry("L2", strategy.long, qty = perQty, limit = levelPrice(pendEntry, gStep, sign, 1))
if n >= 3
strategy.entry("L3", strategy.long, qty = perQty, limit = levelPrice(pendEntry, gStep, sign, 2))
if n >= 4
strategy.entry("L4", strategy.long, qty = perQty, limit = levelPrice(pendEntry, gStep, sign, 3))
else
strategy.entry("S1", strategy.short, qty = perQty)
if n >= 2
strategy.entry("S2", strategy.short, qty = perQty, limit = levelPrice(pendEntry, gStep, -sign, 1))
if n >= 3
strategy.entry("S3", strategy.short, qty = perQty, limit = levelPrice(pendEntry, gStep, -sign, 2))
if n >= 4
strategy.entry("S4", strategy.short, qty = perQty, limit = levelPrice(pendEntry, gStep, -sign, 3))
ideaSide := pendSide
ideaBorn := bar_index
ideaGoal := pendGoal
ideaTrailDist := pendTrailDist
ideaCloseDist := pendCloseDist
ideaBasicStop := pendStop
ideaStop := pendStop
ideaRiskMoney := riskCash
ideaRealized := 0.0
ideaOpen := true
hiSince := high
loSince := low
pendSide := 0
if strategy.position_size == 0 and ideaSide == 0
cancelEntries()
ideaStop := na
hiSince := na
loSince := na
else if strategy.position_size > 0
strategy.cancel("S1")
strategy.cancel("S2")
strategy.cancel("S3")
strategy.cancel("S4")
else if strategy.position_size < 0
strategy.cancel("L1")
strategy.cancel("L2")
strategy.cancel("L3")
strategy.cancel("L4")
bool independentClose = false
if strategy.position_size > 0 and not na(ideaTrailDist)
hiSince := na(hiSince) ? high : math.max(hiSince, high)
float trailDist = TRAIL_MODE == 1 ? hiSince * trailATR / 100.0 : ideaTrailDist
float trailLong = hiSince - trailDist
ideaStop := math.max(nz(ideaStop, ideaBasicStop), math.max(ideaBasicStop, trailLong))
strategy.exit("LX1", "L1", stop = ideaStop, limit = ideaGoal)
if n >= 2
strategy.exit("LX2", "L2", stop = ideaStop, limit = ideaGoal)
if n >= 3
strategy.exit("LX3", "L3", stop = ideaStop, limit = ideaGoal)
if n >= 4
strategy.exit("LX4", "L4", stop = ideaStop, limit = ideaGoal)
float closeDist = CLOSE_MODE == 1 ? hiSince * CLOSE_STEP / 100.0 : ideaCloseDist
independentClose := close <= hiSince - closeDist
if strategy.position_size < 0 and not na(ideaTrailDist)
loSince := na(loSince) ? low : math.min(loSince, low)
float trailDist = TRAIL_MODE == 1 ? loSince * trailATR / 100.0 : ideaTrailDist
float trailShort = loSince + trailDist
ideaStop := math.min(nz(ideaStop, ideaBasicStop), math.min(ideaBasicStop, trailShort))
strategy.exit("SX1", "S1", stop = ideaStop, limit = ideaGoal)
if n >= 2
strategy.exit("SX2", "S2", stop = ideaStop, limit = ideaGoal)
if n >= 3
strategy.exit("SX3", "S3", stop = ideaStop, limit = ideaGoal)
if n >= 4
strategy.exit("SX4", "S4", stop = ideaStop, limit = ideaGoal)
float closeDist = CLOSE_MODE == 1 ? loSince * CLOSE_STEP / 100.0 : ideaCloseDist
independentClose := close >= loSince + closeDist
bool closeIdea = ideaSide != 0 and (bar_index - ideaBorn > MAXBAR or not inSess or (ideaSide == 1 and convLong < 0) or (ideaSide == -1 and convShort < 0))
if closeIdea or independentClose
cancelEntries()
strategy.close_all()
prevPosSize := posNow
float measuredW = closedIdeas > 0 ? float(wins) / float(closedIdeas) : na
float measuredRR = wins > 0 and losses > 0 ? (sumWinR / float(wins)) / math.abs(sumLossR / float(losses)) : na
float sessTotal = sessTargetFirst + sessDllFirst + sessInconclusive
float rateA = sessTotal > 0 ? float(sessTargetFirst) / float(sessTotal) : na
plot(strategy.position_size, "Net position", display = display.data_window)
plot(dayFloor, "DLL floor (MOVING from start-of-day prop-equity proxy)", display = display.data_window)
plot(openRiskMoney(), "Actual owned open risk to protective stop", display = display.data_window)
plot(measuredW, "Measured win rate w (idea closed-trade P&L)", display = display.data_window)
plot(measuredRR, "Measured R:R (idea P&L / actual initial cash risk)", display = display.data_window)
plot(rateA, "LABEL A: conservative target-first lower-bound estimate", display = display.data_window)
plot(na, "LABEL B: evaluation payout odds (NOT EMITTED - needs T3 trace)", display = display.data_window)
if barstate.islast
string msg = "PAYOUT ODDS | historical base PF only; current retention UNMEASURED" +
" | A conservative target-first estimate = " + fmtPct(rateA) +
" | unresolved sessions = " + str.tostring(sessInconclusive) +
" | B = NOT EMITTED (needs T3)" +
" | measured idea w = " + fmtPct(measuredW) + " R:R = " + (na(measuredRR) ? "n/a" : str.tostring(measuredRR, "#.##")) +
" | no tick certificate, no profit promise"
label.new(bar_index, high, text = msg, style = label.style_label_down, textcolor = color.white, color = color.new(color.navy, 15), size = size.tiny)
#THE CLAIM
This pass wrote source only.
#SOURCE
Pine v6 · 415 lines · /code/payout-odds.pine · category Options & evaluation.
#NOTES FROM THE REPO
Date: 2026-11-28. Scope: `PayoutOddsTester.v2.strategy.pine` and
Scripts are provided for research; publication is not a performance claim. No backtest result is implied by this file. Not financial advice.
Source is provided for research, not as a performance claim. Paste into a Pine editor before use. Not financial advice.