ORB-PreDay_PerM_Levels

sskcharts · study · 196 行 · 点赞 682 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ssksubam
//@version=5
indicator(title='ORB-PreDay_PerM_Levels', shorttitle='ORB-PreDay_PerM_Levels', overlay=true)
 
//User Input
showORB = input(true, title='Show ORB', inline='1')
showORBExt = input(true, title='Show ORB Ext', inline='1')
showPMHL = input(true, title='Show Pre-Market H/L', inline='2') 
aftermarket = input(title='Include After-Market', defval=false, inline='2')
showPrevDayHighLow = input(true, title='Show previous day\'s High & Low')
showPrev2DayHighLow = input(false, title='Show previous 2+ days High & Low')
showPrevDayClose = input(true, title='Show previous day\'s Close')
orbTimeFrame = input.timeframe('10', title='ORB timeframe')
sessSpec = input.session('0930-1600', title='Session time')
ORBHColor = input.color(title='ORBH Color', defval=color.new(#0bd68a, 30), inline='10')
ORBLColor = input.color(title='ORBL Color', defval=color.new(#d3396d, 30), inline='10')
PDHColor = input.color(title='PDH Color', defval=color.new(#81c784, 70), inline='11')
PDLColor = input.color(title='PDL Color', defval=color.new(#f06292, 75), inline='11')
PDCColor = input.color(title='PDC Color', defval=color.new(#2196f3, 20), inline='12')
P2DHLColor = input.color(title='P2DHL/ORBExt Color', defval=color.new(#5d606b, 50), inline='13')
plotSignals = input(false, title='Show Buy/Sell Signal')
 
ORBWidth = input.int(title='', defval=1, minval=1, inline='10')
PDHLWidth = input.int(title='', defval=3, minval=1, inline='11')
PDCWidth = input.int(title='', defval=1, minval=1, inline='12')
P2DHLWidth = input.int(title='', defval=2, minval=1, inline='13')
ORBOption = input.string(title='', options=['solid', 'dotted', 'dashed'], defval='solid', inline='10')
PDHLOption = input.string(title='', options=['solid', 'dotted', 'dashed'], defval='solid', inline='11')
PDCOption = input.string(title='', options=['solid', 'dotted', 'dashed'], defval='dashed', inline='12')
P2DHLOption = input.string(title='', options=['solid', 'dotted', 'dashed'], defval='solid', inline='13')
ORBStyle = ORBOption == 'dotted' ? line.style_dotted : ORBOption == 'dashed' ? line.style_dashed : line.style_solid
PDHLStyle = PDHLOption == 'dotted' ? line.style_dotted : PDHLOption == 'dashed' ? line.style_dashed : line.style_solid
PDCStyle = PDCOption == 'dotted' ? line.style_dotted : PDCOption == 'dashed' ? line.style_dashed : line.style_solid
P2DHLStyle = P2DHLOption == 'dotted' ? line.style_dotted : P2DHLOption == 'dashed' ? line.style_dashed : line.style_solid
 
// Get ORB
t = ticker.new(syminfo.prefix, syminfo.ticker)
getSeries(_e, _timeFrame) =>
    request.security(t, _timeFrame, _e, lookahead=barmerge.lookahead_on)
 
is_newbar(res, sess) =>
    t1 = time(res, sess)
    na(t1[1]) and not na(t1) or t1[1] < t1
 
newbar = is_newbar('1440', sessSpec)
 
var float orbH = na
var float orbL = na
if newbar
    orbH := getSeries(high[0], orbTimeFrame)
    orbL := getSeries(low[0], orbTimeFrame)
    orbL
 
// Get ORB Extension
OrbExt1 = 0.618 //1.382
OrbExt2 = 1.618 
 
ORWidth = orbH-orbL
orb_ext_up1 = orbH + ORWidth*OrbExt1
orb_ext_down1 = orbL - ORWidth*OrbExt1
orb_ext_up2= orbH + ORWidth*OrbExt2
orb_ext_down2 = orbL - ORWidth*OrbExt2
 
//Previous  Days High Low
PrevDayHigh = getSeries(high[1], 'D')
PrevDayLow = getSeries(low[1], 'D')
PrevDayOpen = getSeries(open[1], 'D')
PrevDayClose = getSeries(close[1], 'D')
 
//Previous 2 Days High Low
PrevDayHigh1 = getSeries(high[2], 'D') > PrevDayHigh ? getSeries(high[2], 'D') : getSeries(high[3], 'D') > PrevDayHigh ? getSeries(high[3], 'D') : na
PrevDayLow1 = getSeries(low[2], 'D') < PrevDayLow ? getSeries(low[2], 'D') : getSeries(low[3], 'D') < PrevDayLow ? getSeries(low[3], 'D') : na
PrevDayHigh2 = PrevDayHigh1 == getSeries(high[2], 'D') ? getSeries(high[3], 'D') > getSeries(high[2], 'D') ? getSeries(high[3], 'D') : getSeries(high[4], 'D') > getSeries(high[3], 'D') ? getSeries(high[4], 'D') : na : na
PrevDayLow2 = PrevDayLow1 == getSeries(low[2], 'D') ? getSeries(low[3], 'D') < getSeries(low[2], 'D') ? getSeries(low[3], 'D') : getSeries(low[4], 'D') < getSeries(low[3], 'D') ? getSeries(low[4], 'D') : na : na
 
 
//PM High Low
ending_hour = 9
ending_minute = 30
// LastOnly = input(title="Last only", type=input.bool, defval=false)
 
PMHLColor = input.color(title='PMHL Color', defval=color.new(#ff9800, 0), inline='15')
PMHLWidth = input.int(title='', defval=1, minval=1, inline='15')
PMHLOption = input.string(title='', options=['solid', 'dotted', 'dashed'], defval='dashed', inline='15')
PMHLStyle = PMHLOption == 'dotted' ? line.style_dotted : PMHLOption == 'dashed' ? line.style_dashed : line.style_solid
 
pmt = aftermarket == false ? time('1440', '0000-1530:23456') : time('1440', '1600-0000:23456')  // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
is_first = na(pmt[1]) and not na(pmt) or pmt[1] < pmt
 
pm_high = float(na)
pm_low = float(na)
k = int(na)
 
if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    pm_high := high
    pm_low := low
    pm_low
else
    pm_high := pm_high[1]
    pm_low := pm_low[1]
    pm_low
 
if high > pm_high and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    pm_high := high
    pm_high
 
if low < pm_low and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
    pm_low := low
    pm_low
    
    
// Today's Session Start timestamp
y = year(timenow)
m = month(timenow)
d = dayofmonth(timenow)
 
d1 = d - 4
 
 
// Start & End time for Today
start = timestamp(y, m, d, 09, 00)
pmstart = timestamp(y, m, d, 06, 30)
start1 = timestamp(y, m, d1, 09, 30)
end = start + 86400000
orbend = start + 25200000
pmend = start + 7200000
 
// Plot only if session started
isToday = timenow > start
 
// Plot selected timeframe's High, Low & Avg
// Plot lines
if isToday
    if showORB
        _h = line.new(start, orbH, orbend, orbH, xloc.bar_time, color=ORBHColor, style=ORBStyle, width=ORBWidth)
        line.delete(_h[1])
        _l = line.new(start, orbL, orbend, orbL, xloc.bar_time, color=ORBLColor, style=ORBStyle, width=ORBWidth)
        line.delete(_l[1])
    if showORBExt
        _orb_ext_up1 = line.new(start, orb_ext_up1, orbend, orb_ext_up1, xloc.bar_time, color=P2DHLColor, style=line.style_solid, width=2)
        line.delete(_orb_ext_up1[1])
        _orb_ext_down1 = line.new(start, orb_ext_down1, orbend, orb_ext_down1, xloc.bar_time, color=P2DHLColor, style=line.style_solid, width=2)
        line.delete(_orb_ext_down1[1])
        _orb_ext_up2 = line.new(start, orb_ext_up2, orbend, orb_ext_up2, xloc.bar_time, color=P2DHLColor, style=line.style_solid, width=2)
        line.delete(_orb_ext_up2[1])
        _orb_ext_down2 = line.new(start, orb_ext_down2, orbend, orb_ext_down2, xloc.bar_time, color=P2DHLColor, style=line.style_solid, width=2)
        line.delete(_orb_ext_down2[1])
        
    if showPrevDayHighLow
        _pdh = line.new(start1, PrevDayHigh, end, PrevDayHigh, xloc.bar_time, color=PDHColor, style=PDHLStyle, width=PDHLWidth)
        line.delete(_pdh[1])
        _pdl = line.new(start1, PrevDayLow, end, PrevDayLow, xloc.bar_time, color=PDLColor, style=PDHLStyle, width=PDHLWidth)
        line.delete(_pdl[1])
    if showPrevDayClose
        _pdc = line.new(start, PrevDayClose, end, PrevDayClose, xloc.bar_time, color=PDCColor, style=PDCStyle, width=PDCWidth)
        line.delete(_pdc[1])
 
    if showPrev2DayHighLow
        _p2dh1 = line.new(start1, PrevDayHigh1, end, PrevDayHigh1, xloc.bar_time, color=P2DHLColor, style=P2DHLStyle, width=P2DHLWidth)
        line.delete(_p2dh1[1])
    if showPrev2DayHighLow
        _p2dl1 = line.new(start1, PrevDayLow1, end, PrevDayLow1, xloc.bar_time, color=P2DHLColor, style=P2DHLStyle, width=P2DHLWidth)
        line.delete(_p2dl1[1])
    if showPrev2DayHighLow
        _p2dh2 = line.new(start1, PrevDayHigh2, end, PrevDayHigh2, xloc.bar_time, color=P2DHLColor, style=P2DHLStyle, width=P2DHLWidth)
        line.delete(_p2dh2[1])
    if showPrev2DayHighLow
        _p2dl2 = line.new(start1, PrevDayLow2, end, PrevDayLow2, xloc.bar_time, color=P2DHLColor, style=P2DHLStyle, width=P2DHLWidth)
        line.delete(_p2dl2[1])
 
if timenow > pmstart 
    if showPMHL
        _pmh = line.new(pmstart, pm_high, pmend, pm_high, xloc.bar_time, color=PMHLColor, style=PMHLStyle, width=PMHLWidth)
        line.delete(_pmh[1])
        _pml = line.new(pmstart, pm_low, pmend, pm_low, xloc.bar_time, color=PMHLColor, style=PMHLStyle, width=PMHLWidth)
        line.delete(_pml[1])
 
// Plot labels
//if isToday
//    if showORB
//        l_h = label.new(start, orbH, text="High", xloc=xloc.bar_time, textcolor=ORBColor, style=label.style_none)
//        label.delete(l_h[1])
//        l_l = label.new(start, orbL, text="Low", xloc=xloc.bar_time, textcolor=ORBColor, style=label.style_none)
//        label.delete(l_l[1]) 
//    if showPrevDayHighLow
//        l_pdh = label.new(start1, PrevDayHigh, text="PD High", xloc=xloc.bar_time, textcolor=PDHColor, style=label.style_none)
//        label.delete(l_pdh[1])
//        l_pdl = label.new(start1, PrevDayLow, text="PD Low", xloc=xloc.bar_time, textcolor=PDLColor, style=label.style_none)
//        label.delete(l_pdl[1])
//    if showPrevDayClose
//        l_pdc = label.new(start1, PrevDayClose, text="PD Close", xloc=xloc.bar_time, textcolor=PDCColor, style=label.style_none)
//        label.delete(l_pdc[1])
 
plotshape(plotSignals ? ta.crossover(close, orbH) : na, style=shape.triangleup, location=location.belowbar, color=color.new(color.blue, 0), text='Buy', textcolor=color.new(color.blue, 0))
plotshape(plotSignals ? ta.crossover(orbL, close) : na, style=shape.triangledown, location=location.abovebar, color=color.new(color.blue, 0), text='Sell', textcolor=color.new(color.blue, 0))

← 返回列表