TradeLink MNQ Opening Range Retest

bcolabella · strategy · 82 行 · 点赞 29 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// Opening-range breakout/retest strategy. Historical selection; forward performance unverified.
// Standard MNQ 1-minute candles; confirmed 5-minute signals, without lookahead.
// OR09:30-09:45 New York. Breakout then later directional boundary retest.
// Admit signal closes10:00 inclusive to10:15 exclusive. One trade/day.
// Stop half opening range; target1.5R; noon flatten order fills on next tick.
// Costs are assumptions. Gaps and actual fills can exceed the modeled risk.
// Historical settings selected on already-explored2024-2026 data.
// This code is subject to Mozilla Public License2.0: https://mozilla.org/MPL/2.0/
strategy("TradeLink MNQ Opening Range Retest",overlay=true,initial_capital=50000,pyramiding=0,default_qty_type=strategy.fixed,default_qty_value=1,commission_type=strategy.commission.cash_per_contract,commission_value=0.94,slippage=2,margin_long=20,margin_short=20,use_bar_magnifier=true,backtest_fill_limits_assumption=1,process_orders_on_close=false,calc_on_order_fills=false,calc_on_every_tick=false)
contracts=input.int(1,"Fixed contracts",minval=1,maxval=20)
startDate=input.time(timestamp("01 Jan 2024 00:00 -0500"),"Start inclusive")
endDate=input.time(timestamp("01 Jan 2099 00:00 -0500"),"End exclusive")
string z="America/New_York"
if barstate.isfirst and (not chart.is_standard or not timeframe.isminutes or timeframe.multiplier!=1 or syminfo.root!="MNQ")
    runtime.error("Use standard MNQ one-minute candles.")
signal5m()=>
    int m=hour(time,"America/New_York")*60+minute(time,"America/New_York")
    int cm=hour(time_close,"America/New_York")*60+minute(time_close,"America/New_York")
    int key=year(time,"America/New_York")*10000+month(time,"America/New_York")*100+dayofmonth(time,"America/New_York")
    bool fresh=ta.change(key)!=0
    var float oh=na
    var float ol=na
    var int built=0
    var int arm=0
    var int armedBar=na
    var int armedTime=na
    if fresh
        oh:=na
        ol:=na
        built:=0
        arm:=0
        armedBar:=na
        armedTime:=na
    if m>=570 and m<585
        oh:=na(oh)?high:math.max(oh,high)
        ol:=na(ol)?low:math.min(ol,low)
        built+=5
    bool ready=built==15 and cm>=585 and oh>ol
    bool active=ready and cm<630
    bool up=ready and close>oh and close[1]<=oh
    bool down=ready and close<ol and close[1]>=ol
    if active
        if up and arm!=1
            arm:=1
            armedBar:=bar_index
            armedTime:=time_close
        else if down and arm!=-1
            arm:=-1
            armedBar:=bar_index
            armedTime:=time_close
        if arm!=0 and time_close-armedTime>1800000
            arm:=0
    bool buy=active and arm==1 and bar_index>armedBar and low<=oh and close>oh and close>open
    bool sell=active and arm==-1 and bar_index>armedBar and high>=ol and close<ol and close<open
    float ticks=math.max(1,math.ceil((oh-ol)*0.5/syminfo.mintick))
    if buy or sell
        arm:=0
    [buy,sell,ticks,oh,ol]
[buy5,sell5,ticks5,oh5,ol5]=request.security(syminfo.tickerid,"5",signal5m(),gaps=barmerge.gaps_off,lookahead=barmerge.lookahead_off)
int key=year(time,z)*10000+month(time,z)*100+dayofmonth(time,z)
bool fresh=ta.change(key)!=0
var int dayStartClosed=0
if fresh
    dayStartClosed:=strategy.closedtrades
bool traded=strategy.closedtrades>dayStartClosed or strategy.position_size!=0
bool boundary=time_close==time_close("5")
bool allowed=barstate.isconfirmed and boundary and not traded and time>=startDate and time_close<endDate
int signalMinute=hour(time_close,z)*60+minute(time_close,z)
if allowed and signalMinute>=600 and signalMinute<615
    if buy5
        strategy.entry("LE",strategy.long,qty=contracts)
        strategy.exit("LX","LE",loss=ticks5,profit=math.round(ticks5*1.5))
    else if sell5
        strategy.entry("SE",strategy.short,qty=contracts)
        strategy.exit("SX","SE",loss=ticks5,profit=math.round(ticks5*1.5))
int cm=hour(time_close,z)*60+minute(time_close,z)
if cm>=720 or time_close>=endDate
    strategy.cancel_all()
    strategy.close_all(comment="Noon / date exit")
plot(oh5,"Five-minute OR high",color=color.lime,style=plot.style_linebr)
plot(ol5,"Five-minute OR low",color=color.red,style=plot.style_linebr)

← 返回列表