本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// INTERNAL RESEARCH PORT. Copyright (c) 2026 EdgePilot. All rights reserved.
// Derived from bittern-hour-open-maker-scalper 1.0.0, supplied release source.
// Redistribution/republication requires prior written permission from EdgePilot.
// Pine approximates the execution model: no venue post-only/reduce-only, queue,
// partial-fill/cancel-race, restart/fault-latch, or reserved-margin emulation.
// Native reports are separate evidence, never this script's Strategy Tester result.
// Tester: uniform Maker 0.01%; custom ledger additionally deducts 0.015% on
// stop/time/end market exits. Read the ADJUSTED curve/table for split-fee results.
// Resting TP exits are Maker; a target repriced through the completed close is
// treated as Taker. This is a liquidity proxy, not exchange-verified liquidity.
strategy("Bittern Hour-Open Maker Scalper v1.0.0 Visual", overlay=false, initial_capital=100000, currency=currency.USDT, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.01, slippage=0, margin_long=100, margin_short=100, calc_on_order_fills=true, calc_on_every_tick=false, process_orders_on_close=false, max_labels_count=100)
band = input.float(1.2, "Hour-open band (%)", minval=0.01, maxval=20)
minProfit = input.float(0.1, "Minimum target distance (%)", minval=0)
stopPct = input.float(6.0, "Stop-market distance (%)", minval=0.5, maxval=50)
maxHold = input.int(120, "Maximum completed bars held", minval=1)
resize = input.float(3.0, "Quantity resize threshold (%)", minval=0.01)
requote = input.int(1, "Requote threshold (ticks)", minval=1)
allocation = input.float(95, "Current equity per entry (%)", minval=0.01, maxval=100)
qtyStep = input.float(0.1, "Quantity step (ONDO)", minval=0.000001)
allowLong = input.bool(true, "Allow long")
allowShort = input.bool(true, "Allow short")
startAt = input.time(timestamp("15 Nov 2025 00:00 +0000"), "Research start (UTC)")
endAt = input.time(timestamp("15 Nov 2026 00:00 +0000"), "Research end (UTC)")
showLevels = input.bool(true, "Show anchor and working quotes", group="Visuals")
showRisk = input.bool(true, "Show actual-position target and stop", group="Visuals")
showState = input.bool(true, "Show position background", group="Visuals")
showPanel = input.bool(true, "Show fee and performance panel", group="Visuals")
showCurves = input.bool(true, "Show adjusted equity and drawdown", group="Visuals")
if barstate.isfirst
if syminfo.tickerid != "BINANCE:ONDOUSDT.P" or timeframe.in_seconds() != 180
runtime.error("Reference market: BINANCE:ONDOUSDT.P, 3 minutes. Use standard candles.")
if endAt <= startAt
runtime.error("Research end must be after start.")
roundPrice(float v) => math.round_to_mintick(v)
varip float anchor = na
varip int anchorHour = na
varip float workingBid = na
varip float workingAsk = na
varip float workingQty = na
varip string tpRole = "TP_MAKER"
varip bool closing = false
varip float target = na
varip float stop = na
varip float seenPosition = 0.0
varip int seenClosed = 0
varip float extraTakerFees = 0.0
varip int enteredBar = na
varip int lastRegularBar = na
varip float equityPeak = 100000.0
varip float maxCloseDD = 0.0
varip int firstResearchTime = na
bool fillPass = strategy.position_size != seenPosition or strategy.closedtrades != seenClosed
// Process every closed lifecycle exactly once, including same-bar round trips.
if strategy.closedtrades > seenClosed
for i = seenClosed to strategy.closedtrades - 1
string reason = strategy.closedtrades.exit_comment(i)
if reason != "TP_MAKER"
extraTakerFees += math.abs(strategy.closedtrades.size(i)) * strategy.closedtrades.exit_price(i) * syminfo.pointvalue * 0.00015
seenClosed := strategy.closedtrades
if strategy.position_size != 0 and seenPosition == 0
enteredBar := bar_index
closing := false
strategy.cancel("L")
strategy.cancel("S")
workingBid := na
workingAsk := na
workingQty := na
if strategy.position_size == 0 and seenPosition != 0
enteredBar := na
closing := false
target := na
stop := na
seenPosition := strategy.position_size
float adjustedEquity = strategy.equity - extraTakerFees
bool regularClose = barstate.isconfirmed and not fillPass and (na(lastRegularBar) or lastRegularBar != bar_index)
// On fill recalculations, never use the full historical candle's close/high/low
// to quote an entry, update an hour anchor, resize, or expire a position.
if regularClose
lastRegularBar := bar_index
int utcHour = int(math.floor((time_close - 1) / 3600000))
if na(anchorHour) or utcHour != anchorHour
anchor := open
anchorHour := utcHour
bool active = time_close >= startAt and time_close < endAt
if active and na(firstResearchTime)
firstResearchTime := time_close
if not active
strategy.cancel_all()
if strategy.position_size != 0
closing := true
strategy.close_all(comment="END_TAKER", immediately=true)
workingBid := na
workingAsk := na
workingQty := na
else if strategy.position_size == 0
strategy.cancel("XL")
strategy.cancel("XS")
float newBid = roundPrice(math.min(anchor * (1 - band / 100), close - syminfo.mintick))
float newAsk = roundPrice(math.max(anchor * (1 + band / 100), close + syminfo.mintick))
float desiredQty = math.floor(math.max(adjustedEquity, 0) * allocation / 100 / (close * syminfo.pointvalue) / qtyStep) * qtyStep
bool resized = not na(workingQty) and workingQty > 0 and math.abs(desiredQty / workingQty - 1) > resize / 100
if resized
// Native cancels now and re-posts on the next completed bar.
strategy.cancel("L")
strategy.cancel("S")
workingBid := na
workingAsk := na
workingQty := na
else if desiredQty > 0
if na(workingQty)
workingQty := desiredQty
if na(workingBid) or math.abs(newBid - workingBid) + 1e-12 >= requote * syminfo.mintick
workingBid := newBid
if na(workingAsk) or math.abs(newAsk - workingAsk) + 1e-12 >= requote * syminfo.mintick
workingAsk := newAsk
// OCA is an emulator approximation of native cancel-after-fill.
// The supplied Python deliberately uses TWO INDEPENDENT venue orders.
if allowLong
strategy.order("L", strategy.long, qty=workingQty, limit=workingBid, oca_name="ENTRY", oca_type=strategy.oca.cancel, comment="ENTRY_MAKER")
if allowShort
strategy.order("S", strategy.short, qty=workingQty, limit=workingAsk, oca_name="ENTRY", oca_type=strategy.oca.cancel, comment="ENTRY_MAKER")
else if not na(enteredBar) and bar_index - enteredBar + 1 >= maxHold
strategy.cancel_all()
closing := true
strategy.close_all(comment="TIME_TAKER", immediately=true)
// Initial bracket attaches after entry fill; no future bar prices enter it.
// Refresh the maker target at completed bars, retaining the native hourly anchor.
if strategy.position_size != 0 and not closing
float direction = strategy.position_size > 0 ? 1 : -1
float floorTarget = strategy.position_avg_price * (1 + direction * minProfit / 100)
float desiredTarget = roundPrice(direction > 0 ? math.max(anchor, floorTarget) : math.min(anchor, floorTarget))
if na(target) or (regularClose and math.abs(desiredTarget - target) + 1e-12 >= requote * syminfo.mintick)
tpRole := regularClose and (direction > 0 ? desiredTarget <= close : desiredTarget >= close) ? "TP_TAKER" : "TP_MAKER"
target := desiredTarget
stop := roundPrice(strategy.position_avg_price * (1 - direction * stopPct / 100))
if strategy.position_size > 0
strategy.exit("XL", "L", limit=target, stop=stop, comment_profit=tpRole, comment_loss="SL_TAKER")
else
strategy.exit("XS", "S", limit=target, stop=stop, comment_profit=tpRole, comment_loss="SL_TAKER")
adjustedEquity := strategy.equity - extraTakerFees
// Curves are sampled on completed-bar passes, avoiding synthetic OHLC-fill extrema.
if regularClose
equityPeak := math.max(equityPeak, adjustedEquity)
maxCloseDD := math.max(maxCloseDD, 100 * (1 - adjustedEquity / equityPeak))
float ddPct = 100 * (adjustedEquity / equityPeak - 1)
plot(showCurves ? (adjustedEquity / 100000 - 1) * 100 : na, "Split-fee adjusted equity return (%)", color=color.teal, linewidth=2)
plot(showCurves ? ddPct : na, "Split-fee close-sampled drawdown (%)", color=color.new(color.red, 35), style=plot.style_area)
hline(0, "Zero", color=color.gray)
plot(showLevels ? anchor : na, "UTC hour open (confirmed)", color=color.orange, linewidth=2, style=plot.style_stepline, force_overlay=true)
pb = plot(showLevels ? workingBid : na, "Working maker bid", color=color.teal, linewidth=2, style=plot.style_linebr, force_overlay=true)
pa = plot(showLevels ? workingAsk : na, "Working maker ask", color=color.purple, linewidth=2, style=plot.style_linebr, force_overlay=true)
fill(pb, pa, color=showLevels ? color.new(color.blue, 95) : na, title="Working quote band")
plot(showRisk and strategy.position_size != 0 ? target : na, "Position maker take-profit", color=color.green, linewidth=2, style=plot.style_linebr, force_overlay=true)
plot(showRisk and strategy.position_size != 0 ? stop : na, "Position stop-market", color=color.red, linewidth=2, style=plot.style_linebr, force_overlay=true)
bgcolor(showState and strategy.position_size != 0 ? (strategy.position_size > 0 ? color.new(color.green, 93) : color.new(color.red, 93)) : na, force_overlay=true)
plot(adjustedEquity, "Adjusted equity (USDT)", display=display.data_window)
plot(extraTakerFees, "Additional taker fees (USDT)", display=display.data_window)
plot(maxCloseDD, "Adjusted maximum close-sampled drawdown (%)", display=display.data_window)
var table panel = table.new(position.top_right, 2, 7, bgcolor=color.new(color.white, 5), border_width=1)
if barstate.islastconfirmedhistory or barstate.islast
table.clear(panel, 0, 0, 1, 6)
if showPanel
table.cell(panel, 0, 0, "BITTERN | 3m ONDO", text_color=color.black)
table.cell(panel, 1, 0, "Split-fee research", text_color=color.black)
table.cell(panel, 0, 1, "Maker / Taker", text_color=color.black)
table.cell(panel, 1, 1, "0.01% / 0.025%", text_color=color.black)
table.cell(panel, 0, 2, "Adjusted equity", text_color=color.black)
table.cell(panel, 1, 2, str.tostring(adjustedEquity, "#.00"), text_color=color.black)
table.cell(panel, 0, 3, "Extra taker fee", text_color=color.black)
table.cell(panel, 1, 3, str.tostring(extraTakerFees, "#.00"), text_color=color.black)
table.cell(panel, 0, 4, "Close-sampled max DD", text_color=color.black)
table.cell(panel, 1, 4, str.tostring(maxCloseDD, "#.00") + "%", text_color=color.black)
table.cell(panel, 0, 5, "Tester fee", text_color=color.black)
table.cell(panel, 1, 5, "Uniform 0.01%; use adjusted curve", text_color=color.black)
table.cell(panel, 0, 6, "First loaded research bar", text_color=color.black)
table.cell(panel, 1, 6, na(firstResearchTime) ? "None" : str.format_time(firstResearchTime, "yyyy-MM-dd HH:mm", "UTC"), text_color=color.black)