DAAVILE Atlas Combined v2
THE SOURCE FILE /code/atlas.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 source318
categoryStructure
panestrategy
Pine versionv6
//@version=6
// =============================================================================
// DAAVILE ATLAS Combined v2 — structure confluence on the proven breakout base
// -----------------------------------------------------------------------------
// All logic in this file is DAAVILE-designed. No outside strategy is reused.
// The engine: trade the break of the previous completed candle with a one-tick
// buffer in the exchange-time session. One fixed risk budget is split into equal
// grid legs, and every leg exits at the basket's average price.
// Four optional structure overlays sit on top:
// 1. Session range - recent candles give a high, low and midpoint map.
// 2. Initial balance + VWAP - the first daily candles set the opening area,
// and VWAP is the volume-weighted average price since the day began.
// 3. Order blocks - the candle facing a confirmed swing. A close past its far
// side retires the zone, and the active count is capped.
// 4. Liquidity sweeps - a poke past a swing that closes back, graded A/B/C.
// Overlays are soft. Missing data passes, and an enabled overlay can only say
// "no" to a base entry. It never creates an entry, widens risk or moves an exit.
// All four are OFF in code, so the default trade is the untouched base trade.
// NOT backtest-validated. No profit factor or performance figure is claimed.
// Check the exact bytes in the target editor before letting this trade.
// =============================================================================
strategy("DAAVILE ATLAS Combined v2", 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. Defaults are the proven settings.
riskPercent = input.float(5.0, "Risk per trade, % of equity", minval=0.01, maxval=100.0)
sessionStart = input.int(20, "Session start hour (exchange time)", minval=0, maxval=23)
sessionEnd = input.int(21, "Session end hour (exchange time)", minval=0, maxval=23)
useGrid = input.bool(true, "Grid entries (pyramid)")
gridLevels = input.int(4, "Grid levels (1 = single entry)", minval=1, maxval=4)
addMode = input.string("Positive", "Add direction", options=["Positive", "Negative"])
stopAtr = input.float(0.5, "Stop loss, in ATRs", minval=0.01)
targetAtr = input.float(1.0, "Take profit, in ATRs (0 = none)", minval=0.0)
// Operator values: named constants in code, no settings slot.
bufferPoints = 1.0 // extra ticks past the prior high/low so a break is real
oneTradeDay = false // proven setting: allow more than one idea per day
atrLen = 3 // short ATR keeps the stop close to current volatility
//------------------------------------------------------------------------------
// Overlay master switches. All OFF means the base runs untouched.
//------------------------------------------------------------------------------
enableRangeFilter = false
enableIbVwapFilter = false
enableOrderBlockFilter = false
enableSweepFilter = false
showOverlayVisuals = true // plotting only, never touches an order
//------------------------------------------------------------------------------
// Overlay tuning. All named in code so the panel stays at 8 knobs.
//------------------------------------------------------------------------------
rangeBars = 1 // one completed candle defines the session range
initialBalanceBars = 1 // first daily candle sets the opening area
obPivotLeft = 3 // bars each side needed to confirm an order-block swing
obPivotRight = 3
obSearchBars = 10 // how far back to look for the block candle
maxActiveBlocks = 6 // cap so old zones cannot pile up forever
obTouchAtr = 0.20 // how close price must be to count as "at" a block
sweepPivotLeft = 3 // bars each side needed to confirm a sweep swing
sweepPivotRight = 3
sweepVolumeLen = 20 // baseline for the relative-volume grade
sweepAAtr = 0.25 // rejection depth for an A grade
sweepBAtr = 0.10 // rejection depth for a B grade
sweepAVolume = 1.20 // relative volume needed for A
sweepMemoryBars = 5 // how long a fresh A grade stays usable
//------------------------------------------------------------------------------
// Base engine and small helpers.
//------------------------------------------------------------------------------
inSession(h) =>
// A session that crosses midnight wraps around instead of going empty.
sessionStart < sessionEnd ? h >= sessionStart and h < sessionEnd : h >= sessionStart or h < sessionEnd
atrVal = ta.atr(atrLen)
minDist = syminfo.mintick
buf = bufferPoints * syminfo.mintick
stopDist = stopAtr * atrVal
tgtDist = targetAtr * atrVal
signalHigh = high[1] // previous completed candle, never the forming one
signalLow = low[1]
buyStop = signalHigh + buf
sellStop = signalLow - buf
riskMoney = strategy.equity * riskPercent / 100.0
qtyRaw = stopDist > 0 ? riskMoney / stopDist : 0.0
qty = math.floor(qtyRaw)
activeLvls = useGrid ? gridLevels : 1
perQty = activeLvls > 0 ? qty / activeLvls : 0.0 // split the budget, do not multiply it
gridStep = activeLvls > 0 ? stopDist / activeLvls : 0.0
dirSign = addMode == "Negative" ? -1 : 1 // chase (+) or average in (-)
dayKey = math.floor(time / 86400000)
var float lastTradeDay = na
// Drop stale breakout orders on one side so a moved market cannot fill them.
cancelSide(side) =>
for i = 1 to 4
strategy.cancel(side + str.tostring(i))
// Every leg shares one exit pinned to the basket's average price.
setExits(side, isLong) =>
avgPx = strategy.position_avg_price
stopPx = isLong ? avgPx - stopDist : avgPx + stopDist
limitPx = targetAtr > 0 ? (isLong ? avgPx + tgtDist : avgPx - tgtDist) : na
for i = 1 to 4
if i <= activeLvls
strategy.exit(side + "X" + str.tostring(i), side + str.tostring(i), stop = stopPx, limit = limitPx)
// Equal legs, evenly spaced from the first stop price.
placeEntries(side, isLong, firstPrice) =>
for i = 0 to activeLvls - 1
legPrice = firstPrice + dirSign * gridStep * i * (isLong ? 1 : -1)
strategy.entry(side + str.tostring(i + 1), isLong ? strategy.long : strategy.short, qty = perQty, stop = legPrice)
//------------------------------------------------------------------------------
// Overlay 1 + 5: completed-candle range and its merged high/low/midpoint box.
//------------------------------------------------------------------------------
rangeHigh = ta.highest(high, rangeBars)[1]
rangeLow = ta.lowest(low, rangeBars)[1]
rangeMid = (rangeHigh + rangeLow) / 2.0
//------------------------------------------------------------------------------
// Overlay 2: exchange-day opening range and a manually anchored daily VWAP.
//------------------------------------------------------------------------------
newDay = ta.change(time("D")) != 0
var float ibHigh = na
var float ibLow = na
var int dayBars = 0
var float dayPv = 0.0
var float dayVolume = 0.0
if barstate.isconfirmed
if newDay or na(ibHigh)
ibHigh := na
ibLow := na
dayBars := 0
dayPv := 0.0
dayVolume := 0.0
if dayBars < initialBalanceBars
ibHigh := na(ibHigh) ? high : math.max(ibHigh, high)
ibLow := na(ibLow) ? low : math.min(ibLow, low)
dayBars := dayBars + 1
barVol = nz(volume, 0.0)
dayPv := dayPv + hlc3 * barVol
dayVolume := dayVolume + barVol
ibMid = (ibHigh + ibLow) / 2.0
ibComplete = dayBars >= initialBalanceBars
dailyVwap = dayVolume > 0.0 ? dayPv / dayVolume : na
//------------------------------------------------------------------------------
// Overlay 3: pivot-derived opposite-candle blocks, newest last, capped.
//------------------------------------------------------------------------------
var obTops = array.new_float()
var obBottoms = array.new_float()
var obSides = array.new_int()
addBlock(top, bottom, side) =>
if array.size(obSides) >= maxActiveBlocks
array.remove(obTops, 0) // drop the oldest so the count stays capped
array.remove(obBottoms, 0)
array.remove(obSides, 0)
array.push(obTops, top)
array.push(obBottoms, bottom)
array.push(obSides, side)
obPivotHigh = ta.pivothigh(high, obPivotLeft, obPivotRight)
obPivotLow = ta.pivotlow(low, obPivotLeft, obPivotRight)
if barstate.isconfirmed
if not na(obPivotHigh)
found = -1
for i = obPivotRight to obPivotRight + obSearchBars - 1
if found == -1 and close[i] > open[i] // candle facing into the high
found := i
if found >= 0
addBlock(high[found], low[found], -1) // supply sits above price
if not na(obPivotLow)
found = -1
for i = obPivotRight to obPivotRight + obSearchBars - 1
if found == -1 and close[i] < open[i] // candle facing into the low
found := i
if found >= 0
addBlock(high[found], low[found], 1) // demand sits below price
// Demand dies below its low, supply above its high.
i = array.size(obSides) - 1
while i >= 0
s = array.get(obSides, i)
top = array.get(obTops, i)
bot = array.get(obBottoms, i)
if s == 1 ? close < bot : close > top
array.remove(obTops, i)
array.remove(obBottoms, i)
array.remove(obSides, i)
i := i - 1
bullBlockNear = false
bearBlockNear = false
blockTol = obTouchAtr * atrVal
if array.size(obSides) > 0
for i = 0 to array.size(obSides) - 1
top = array.get(obTops, i)
bot = array.get(obBottoms, i)
if close >= bot - blockTol and close <= top + blockTol
if array.get(obSides, i) == 1
bullBlockNear := true
else
bearBlockNear := true
//------------------------------------------------------------------------------
// Overlay 4: fresh pokes through confirmed swings, graded by close and volume.
//------------------------------------------------------------------------------
sweepPivotHigh = ta.pivothigh(high, sweepPivotLeft, sweepPivotRight)
sweepPivotLow = ta.pivotlow(low, sweepPivotLeft, sweepPivotRight)
swingHigh = ta.valuewhen(not na(sweepPivotHigh), sweepPivotHigh, 0)
swingLow = ta.valuewhen(not na(sweepPivotLow), sweepPivotLow, 0)
volumeBase = ta.sma(volume, sweepVolumeLen)
relativeVolume = na(volumeBase) or volumeBase <= 0.0 ? 1.0 : nz(volume, 0.0) / volumeBase
bullSweep = not na(swingLow) and low < swingLow and low[1] >= swingLow and close > swingLow
bearSweep = not na(swingHigh) and high > swingHigh and high[1] <= swingHigh and close < swingHigh
bullDepth = atrVal > 0.0 ? (close - swingLow) / atrVal : 0.0
bearDepth = atrVal > 0.0 ? (swingHigh - close) / atrVal : 0.0
// A needs depth and volume, B needs either, C is a plain rejection.
sweepGrade(depth, relVol) =>
depth >= sweepAAtr and relVol >= sweepAVolume ? "A" : depth >= sweepBAtr or relVol >= sweepAVolume ? "B" : "C"
var string bullGrade = ""
var string bearGrade = ""
var int lastBullA = na
var int lastBearA = na
if barstate.isconfirmed
if bullSweep
bullGrade := sweepGrade(bullDepth, relativeVolume)
if bullGrade == "A"
lastBullA := bar_index
if bearSweep
bearGrade := sweepGrade(bearDepth, relativeVolume)
if bearGrade == "A"
lastBearA := bar_index
//------------------------------------------------------------------------------
// Soft confluence gates. Missing data always passes, an enabled overlay can
// only veto. This is the one rule every overlay shares.
//------------------------------------------------------------------------------
rangeLongOk = not enableRangeFilter or na(rangeMid) or close >= rangeMid
rangeShortOk = not enableRangeFilter or na(rangeMid) or close <= rangeMid
ibLongOk = not ibComplete or na(ibMid) or close >= ibMid
ibShortOk = not ibComplete or na(ibMid) or close <= ibMid
vwapLongOk = na(dailyVwap) or close >= dailyVwap
vwapShortOk = na(dailyVwap) or close <= dailyVwap
ibVwapLongOk = not enableIbVwapFilter or (ibLongOk and vwapLongOk)
ibVwapShortOk = not enableIbVwapFilter or (ibShortOk and vwapShortOk)
obLongOk = not enableOrderBlockFilter or bullBlockNear
obShortOk = not enableOrderBlockFilter or bearBlockNear
freshBullA = not na(lastBullA) and bar_index - lastBullA <= sweepMemoryBars
freshBearA = not na(lastBearA) and bar_index - lastBearA <= sweepMemoryBars
sweepLongOk = not enableSweepFilter or freshBullA
sweepShortOk = not enableSweepFilter or freshBearA
longOk = rangeLongOk and ibVwapLongOk and obLongOk and sweepLongOk
shortOk = rangeShortOk and ibVwapShortOk and obShortOk and sweepShortOk
//------------------------------------------------------------------------------
// Execution: confirmed bars only, base engine with the soft gates appended.
//------------------------------------------------------------------------------
if barstate.isconfirmed
// Opposite-side orders go stale the moment a position exists.
if strategy.position_size == 0
cancelSide("L")
cancelSide("S")
else if strategy.position_size > 0
cancelSide("S")
else
cancelSide("L")
if not inSession(hour(time))
strategy.close_all()
else
if strategy.position_size > 0
setExits("L", true)
if strategy.position_size < 0
setExits("S", false)
dayIsFree = not oneTradeDay or na(lastTradeDay) or dayKey != lastTradeDay
distOk = not na(stopDist) and stopDist >= minDist and (targetAtr == 0 or tgtDist >= minDist)
if strategy.position_size == 0 and dayIsFree and distOk and qty > 0
if buyStop > close + minDist and longOk
placeEntries("L", true, buyStop)
lastTradeDay := dayKey
if sellStop < close - minDist and shortOk
placeEntries("S", false, sellStop)
lastTradeDay := dayKey
//------------------------------------------------------------------------------
// Visuals: base stops plus the optional structure overlays.
//------------------------------------------------------------------------------
plot(buyStop, "Buy stop", color=color.teal, linewidth=1)
plot(sellStop, "Sell stop", color=color.red, linewidth=1)
plot(showOverlayVisuals ? rangeHigh : na, "Range high", color=color.new(color.blue, 45))
plot(showOverlayVisuals ? rangeLow : na, "Range low", color=color.new(color.blue, 45))
plot(showOverlayVisuals ? rangeMid : na, "Range midpoint", color=color.blue)
plot(showOverlayVisuals and ibComplete ? ibHigh : na, "IB high", color=color.new(color.orange, 45))
plot(showOverlayVisuals and ibComplete ? ibLow : na, "IB low", color=color.new(color.orange, 45))
plot(showOverlayVisuals ? dailyVwap : na, "Daily VWAP", color=color.purple, linewidth=2)
plotshape(showOverlayVisuals and bullGrade == "A", "A bull sweep", shape.triangleup, location.belowbar, color.teal, size=size.tiny)
plotshape(showOverlayVisuals and bearGrade == "A", "A bear sweep", shape.triangledown, location.abovebar, color.red, size=size.tiny)
#THE CLAIM
Both files are DAAVILE-owned.
#SOURCE
Pine v6 · 318 lines · /code/atlas.pine · category Structure.
#NOTES FROM THE REPO
- `AtlasCombined.v2.strategy.pine` — Pine v6, 318 lines
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.