Apostle CRT MTF + HTF

hiddenriches · study · 808 行 · 点赞 18 · TradingView 原页

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

Pine Script

//@version=6
 
indicator("Apostle CRT MTF + HTF Candles v1.04a", shorttitle="Apostle CRT MTF v1.04a", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500)
 
// ============================================================================
 
// APOSTLE CRT MTF + HTF CANDLES v1.04
 
// Optimized edition: only THREE unique request.security() calls are used.
 
// This avoids TradingView runtime error RE10137 (40 unique request limit).
 
// ============================================================================
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 1. CRT
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupCRT = "1. CRT"
 
showCRTSignals      = input.bool(true,  "Show Buy / Sell Signals", group=groupCRT)
 
showCRT             = input.bool(true,  "Show CRT", group=groupCRT)
 
showOnlyCompleted   = input.bool(false, "Show only Completed CRT", group=groupCRT)
 
showInvalid         = input.bool(false, "Show INVALID CRTs", group=groupCRT)
 
showPending         = input.bool(false, "Show PENDING CRTs", group=groupCRT)
 
use50Filter         = input.bool(false, "Filter by 50% Level", group=groupCRT)
 
crtPrevLinesWidth   = input.int(2, "CRT Prev Lines Width", minval=1, maxval=5, group=groupCRT)
 
maxCRTsVisible      = input.int(2, "Max CRTs visible", minval=1, maxval=2, group=groupCRT)
 
pendingOffset       = input.int(0, "Pending CRTs Offset (bars based on HTF)", minval=-20, maxval=20, group=groupCRT)
 
crtTFLabelSize      = input.string("small", "TF Label Text Size", options=["tiny","small","normal","large"], group=groupCRT)
 
showPendingMinutes  = input.bool(false, "Show remaining minutes in pending CRTs", group=groupCRT)
 
showCRTText         = input.bool(true, "Show text on CRTs", group=groupCRT)
 
showReferenceRanges = input.bool(true, "Show Active HTF Reference Range", group=groupCRT)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 2. CRT LINE COLORS
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupCRTColors = "2. CRT Line Colors"
 
pendingBearColor    = input.color(color.rgb(190, 45, 55), "Pending BEAR", group=groupCRTColors)
 
pendingBullColor    = input.color(color.rgb(48, 145, 73), "Pending BULL", group=groupCRTColors)
 
completedBearColor  = input.color(color.rgb(242, 147, 151), "Completed BEAR", group=groupCRTColors)
 
completedBullColor  = input.color(color.rgb(120, 191, 133), "Completed BULL", group=groupCRTColors)
 
invalidColor        = input.color(color.rgb(128, 128, 128), "Invalid", group=groupCRTColors)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 3. DAILY LIMIT CALCULATION
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupDaily = "3. Daily Limit Calculation"
 
daysToCalculate = input.int(100, "Days to calculate", minval=1, maxval=1000, group=groupDaily)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 4. CRT HIGHER TIMEFRAMES TO SHOW
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupTF = "4. CRT Higher Timeframes To Show"
 
useTF1 = input.bool(true,  "Show TF1", inline="tf1", group=groupTF)
 
tf1    = input.timeframe("60", "TF1", inline="tf1", group=groupTF)
 
useTF2 = input.bool(false, "Show TF2", inline="tf2", group=groupTF)
 
tf2    = input.timeframe("240", "TF2", inline="tf2", group=groupTF)
 
useTF3 = input.bool(false, "Show TF3", inline="tf3", group=groupTF)
 
tf3    = input.timeframe("D", "TF3", inline="tf3", group=groupTF)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 5. HTF CANDLES
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupHTF = "5. HTF Candles"
 
showHTFCandlesTF1 = input.bool(true, "TF 1", inline="hc1", group=groupHTF)
 
candlesTF1        = input.int(3, "", minval=1, maxval=5, inline="hc1", group=groupHTF)
 
showHTFCandlesTF2 = input.bool(false, "TF 2", inline="hc2", group=groupHTF)
 
candlesTF2        = input.int(3, "", minval=1, maxval=5, inline="hc2", group=groupHTF)
 
maxTFDisplayed    = input.int(2, "Maximum Timeframes Displayed", minval=1, maxval=2, group=groupHTF)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 6. CANDLE COLOR
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupCandle = "6. Candle Color"
 
bullBodyColor    = input.color(color.rgb(35, 165, 55), "Bull Body", inline="body", group=groupCandle)
 
bearBodyColor    = input.color(color.rgb(242, 51, 67), "Bear Body", inline="body", group=groupCandle)
 
bullBorderColor  = input.color(color.rgb(99, 180, 113), "Bull Border", inline="border", group=groupCandle)
 
bearBorderColor  = input.color(color.rgb(242, 51, 67), "Bear Border", inline="border", group=groupCandle)
 
bullWickColor    = input.color(color.rgb(99, 180, 113), "Bull Wick", inline="wick", group=groupCandle)
 
bearWickColor    = input.color(color.rgb(242, 51, 67), "Bear Wick", inline="wick", group=groupCandle)
 
rightOffset      = input.int(25, "Padding from Current Bars", minval=2, maxval=100, group=groupCandle)
 
candleGap        = input.int(1, "Space Between Candles", minval=1, maxval=10, group=groupCandle)
 
groupGap         = input.int(5, "Space Between Timeframes", minval=1, maxval=20, group=groupCandle)
 
candleWidth      = input.int(1, "Candle Width", minval=1, maxval=8, group=groupCandle)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 7. LABEL SETTINGS
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupLabels = "7. Label Settings"
 
showTFLabel     = input.bool(true, "Timeframe Label", group=groupLabels)
 
tfLabelColor    = input.color(color.rgb(255, 228, 70), "Timeframe Label Color", group=groupLabels)
 
tfLabelSize     = input.string("normal", "Timeframe Label Size", options=["tiny","small","normal","large"], group=groupLabels)
 
tfLabelBold     = input.bool(false, "Bold Text", group=groupLabels)
 
labelPosition   = input.string("Top", "Label Positions", options=["Top","Bottom"], group=groupLabels)
 
showTimer       = input.bool(false, "Remaining Time", group=groupLabels)
 
timerColor      = input.color(color.rgb(25, 25, 25), "Remaining Time Color", group=groupLabels)
 
timerSize       = input.string("small", "Remaining Time Size", options=["tiny","small","normal","large"], group=groupLabels)
 
showCandleTime  = input.bool(false, "Candle Time Display", group=groupLabels)
 
candleTimeColor = input.color(color.rgb(10, 10, 10), "Candle Time Color", group=groupLabels)
 
candleTimeSize  = input.string("small", "Candle Time Size", options=["tiny","small","normal","large"], group=groupLabels)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 8. IMBALANCE
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupImbalance = "8. Imbalance (FVG & VI)"
 
showFVG  = input.bool(false, "Fair Value Gaps", group=groupImbalance)
 
fvgColor = input.color(color.new(color.gray, 85), "FVG Color", group=groupImbalance)
 
showVI   = input.bool(false, "Volume Imbalances", group=groupImbalance)
 
viColor  = input.color(color.new(color.rgb(230, 95, 110), 75), "VI Color", group=groupImbalance)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 9. SWING SWEEP LINE
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupSweep = "9. Swing Sweep Line"
 
showSweepLines     = input.bool(true, "Display Swing Lines", group=groupSweep)
 
swingLineThickness = input.int(1, "Line Thickness", minval=1, maxval=5, group=groupSweep)
 
confirmedStyle     = input.string("Solid", "Confirmed Swing Style", options=["Solid","Dashed","Dotted"], group=groupSweep)
 
potentialStyle     = input.string("Dashed", "Potential Swing Style", options=["Solid","Dashed","Dotted"], group=groupSweep)
 
highLineColor      = input.color(color.rgb(111, 196, 132), "High Line Color", inline="slc", group=groupSweep)
 
lowLineColor       = input.color(color.rgb(244, 58, 71), "Low Line Color", inline="slc", group=groupSweep)
 
extendSwingLine    = input.int(1, "Extend Line", minval=0, maxval=100, group=groupSweep)
 
showMidpoint       = input.bool(true, "Show Equilibrium Line (0.5)", group=groupSweep)
 
midColor           = input.color(color.rgb(55, 60, 70), "EQ Line Color", inline="eq", group=groupSweep)
 
eqLineWidth        = input.int(1, "Width", minval=1, maxval=5, inline="eq", group=groupSweep)
 
eqLineStyle        = input.string("Dotted", "Style", options=["Solid","Dashed","Dotted"], inline="eq", group=groupSweep)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 10. BUY / SELL SIGNAL STYLE
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupSignals = "10. Buy / Sell Signal Style"
 
bullSignalColor = input.color(color.lime, "Bullish CRT Signal", inline="sig", group=groupSignals)
 
bearSignalColor = input.color(color.red, "Bearish CRT Signal", inline="sig", group=groupSignals)
 
// ─────────────────────────────────────────────────────────────────────────────
 
// 11. DASHBOARD
 
// ─────────────────────────────────────────────────────────────────────────────
 
groupDash = "11. Dashboard"
 
showDashboard = input.bool(true, "Show CRT Dashboard", group=groupDash)
 
dashPos = input.string("Top Right", "Position", options=["Top Right","Top Left","Bottom Right","Bottom Left"], group=groupDash)
 
// ============================================================================
 
// HELPERS
 
// ============================================================================
 
f_tfName(string tf) =>
 
    tf == "1" ? "1m" :
 
     tf == "3" ? "3m" :
 
     tf == "5" ? "5m" :
 
     tf == "15" ? "15m" :
 
     tf == "30" ? "30m" :
 
     tf == "60" ? "1H" :
 
     tf == "120" ? "2H" :
 
     tf == "240" ? "4H" :
 
     tf == "D" ? "1D" :
 
     tf == "W" ? "1W" : tf
 
f_timer(int closeTime) =>
 
    int rem = math.max(0, closeTime - timenow)
 
    int sec = int(math.floor(rem / 1000))
 
    int hh = int(math.floor(sec / 3600))
 
    int mm = int(math.floor((sec % 3600) / 60))
 
    int ss = sec % 60
 
    string sh = hh < 10 ? "0" + str.tostring(hh) : str.tostring(hh)
 
    string sm = mm < 10 ? "0" + str.tostring(mm) : str.tostring(mm)
 
    string sx = ss < 10 ? "0" + str.tostring(ss) : str.tostring(ss)
 
    hh > 0 ? sh + ":" + sm + ":" + sx : sm + ":" + sx
 
f_lineStyle(string s) =>
 
    s == "Dotted" or s == "dotted" ? line.style_dotted :
 
     s == "Dashed" or s == "dashed" ? line.style_dashed : line.style_solid
 
f_size(string s) =>
 
    s == "tiny" ? size.tiny :
 
     s == "small" ? size.small :
 
     s == "large" ? size.large : size.normal
 
f_state(float h, float l, float c, float prevH, float prevL) =>
 
    bool swLow = l < prevL
 
    bool swHigh = h > prevH
 
    int st = 0
 
    if swLow and h >= prevH
 
        st := 2
 
    else if swHigh and l <= prevL
 
        st := -2
 
    else if swLow and c < prevL
 
        st := 3
 
    else if swHigh and c > prevH
 
        st := -3
 
    else if swLow
 
        st := 1
 
    else if swHigh
 
        st := -1
 
    st
 
f_stateColor(int st) =>
 
    st == 1 ? pendingBullColor :
 
     st == -1 ? pendingBearColor :
 
     st == 2 ? completedBullColor :
 
     st == -2 ? completedBearColor : invalidColor
 
f_stateText(int st) =>
 
    st == 1 ? "Pending Bull" :
 
     st == -1 ? "Pending Bear" :
 
     st == 2 ? "Completed Bull" :
 
     st == -2 ? "Completed Bear" :
 
     st == 3 ? "Invalid Bull" :
 
     st == -3 ? "Invalid Bear" : "No CRT"
 
f_canShow(int st) =>
 
    bool completed = math.abs(st) == 2
 
    showCRT and st != 0 and (
 
      (showOnlyCompleted and completed) or
 
      (not showOnlyCompleted and (
 
        completed or
 
        (math.abs(st) == 1 and (showPending or showReferenceRanges)) or
 
        (math.abs(st) == 3 and showInvalid)
 
      ))
 
    )
 
var box[] gBoxes = array.new_box()
 
var line[] gLines = array.new_line()
 
var label[] gLabels = array.new_label()
 
f_clear() =>
 
    while array.size(gBoxes) > 0
 
        box.delete(array.pop(gBoxes))
 
    while array.size(gLines) > 0
 
        line.delete(array.pop(gLines))
 
    while array.size(gLabels) > 0
 
        label.delete(array.pop(gLabels))
 
f_addLine(int x1, float y1, int x2, float y2, color col, int width, string sty) =>
 
    line ln = line.new(x1, y1, x2, y2, xloc=xloc.bar_index, color=col, width=width, style=f_lineStyle(sty))
 
    array.push(gLines, ln)
 
f_addTimeLine(int t1, float y1, int t2, float y2, color col, int width, string sty) =>
 
    line ln = line.new(t1, y1, t2, y2, xloc=xloc.bar_time, color=col, width=width, style=f_lineStyle(sty))
 
    array.push(gLines, ln)
 
f_addLabel(int x, float y, string txt, color txtCol, st, string sz) =>
 
    label lb = label.new(x, y, txt, xloc=xloc.bar_index, yloc=yloc.price, style=st, color=color.new(color.black, 100), textcolor=txtCol, size=f_size(sz))
 
    array.push(gLabels, lb)
 
f_addBox(int x1, float top, int x2, float bot, color borderCol, color fillCol) =>
 
    if top > bot
 
        box bx = box.new(x1, top, x2, bot, xloc=xloc.bar_index, border_color=borderCol, bgcolor=fillCol)
 
        array.push(gBoxes, bx)
 
f_drawCandle(int x, float o, float h, float l, float c) =>
 
    bool bull = c >= o
 
    color bodyCol = bull ? bullBodyColor : bearBodyColor
 
    color borderCol = bull ? bullBorderColor : bearBorderColor
 
    color wickCol = bull ? bullWickColor : bearWickColor
 
    int left = x - candleWidth
    int right = x + candleWidth
 
    float top = math.max(o, c)
 
    float bot = math.min(o, c)
 
    float bodyTop = top == bot ? top + syminfo.mintick * 0.25 : top
 
    float bodyBot = top == bot ? bot - syminfo.mintick * 0.25 : bot
 
    line wk = line.new(x, l, x, h, xloc=xloc.bar_index, color=wickCol, width=1)
 
    array.push(gLines, wk)
 
    box bx = box.new(left, bodyTop, right, bodyBot, xloc=xloc.bar_index, border_color=borderCol, bgcolor=bodyCol)
 
    array.push(gBoxes, bx)
 
f_drawRange(string tfName, int st, int tStart, int tEnd, float hi, float lo, bool txt) =>
 
    if f_canShow(st)
 
        color col = f_stateColor(st)
 
        f_addTimeLine(tStart, hi, tEnd, hi, col, crtPrevLinesWidth, "Solid")
 
        f_addTimeLine(tStart, lo, tEnd, lo, col, crtPrevLinesWidth, "Solid")
 
        if showMidpoint
 
            f_addTimeLine(tStart, (hi + lo) / 2.0, tEnd, (hi + lo) / 2.0, midColor, eqLineWidth, eqLineStyle)
 
        if showCRTText and txt
 
            f_addLabel(bar_index + pendingOffset, st > 0 ? hi : lo, tfName, col, st > 0 ? label.style_label_down : label.style_label_up, crtTFLabelSize)
 
f_drawGroup(
 
    int startX, string tfName, int timerClose, int count,
 
    float o0, float h0, float l0, float c0,
 
    float o1, float h1, float l1, float c1,
 
    float o2, float h2, float l2, float c2,
 
    float o3, float h3, float l3, float c3,
 
    float o4, float h4, float l4, float c4) =>
 
    int step = math.max(2 * candleWidth + candleGap + 1, 3)
 
    int x4 = startX
 
    int x3 = startX + step
 
    int x2 = startX + step * 2
 
    int x1 = startX + step * 3
 
    int x0 = startX + step * 4
 
    if count >= 5
 
        f_drawCandle(x4, o4,h4,l4,c4)
 
    if count >= 4
 
        f_drawCandle(x3, o3,h3,l3,c3)
 
    if count >= 3
 
        f_drawCandle(x2, o2,h2,l2,c2)
 
    if count >= 2
 
        f_drawCandle(x1, o1,h1,l1,c1)
 
    if count >= 1
 
        f_drawCandle(x0, o0,h0,l0,c0)
 
    if showSweepLines and count >= 2
 
        if h0 > h1 and c0 < h1
 
            f_addLine(x1, h1, x0 + extendSwingLine, h1, highLineColor, swingLineThickness, confirmedStyle)
 
        if l0 < l1 and c0 > l1
 
            f_addLine(x1, l1, x0 + extendSwingLine, l1, lowLineColor, swingLineThickness, confirmedStyle)
 
    if showFVG and count >= 3
 
        if l0 > h2
 
            f_addBox(x2, l0, x0, h2, color.new(fvgColor, 25), fvgColor)
 
        if h0 < l2
 
            f_addBox(x2, l2, x0, h0, color.new(fvgColor, 25), fvgColor)
 
    if showVI and count >= 2
 
        float bh1 = math.max(o1,c1)
 
        float bl1 = math.min(o1,c1)
 
        float bh0 = math.max(o0,c0)
 
        float bl0 = math.min(o0,c0)
 
        if bl0 > bh1
 
            f_addBox(x1, bl0, x0, bh1, color.new(viColor,25), viColor)
 
        if bh0 < bl1
 
            f_addBox(x1, bl1, x0, bh0, color.new(viColor,25), viColor)
 
    if showTFLabel
 
        float hi = math.max(h0, math.max(h1, math.max(h2, math.max(h3,h4))))
 
        float lo = math.min(l0, math.min(l1, math.min(l2, math.min(l3,l4))))
 
        float y = labelPosition == "Top" ? hi + ta.atr(14) * 0.10 : lo - ta.atr(14) * 0.10
 
        string txt = tfName + (showTimer ? "\n" + f_timer(timerClose) : "")
 
        f_addLabel(x0, y, txt, tfLabelColor, label.style_none, tfLabelSize)
 
// ============================================================================
 
// CONSOLIDATED MTF DATA
 
// Exactly ONE request.security() call per timeframe.
 
// ============================================================================
 
[o10,h10,l10,c10,o11,h11,l11,c11,o12,h12,l12,c12,o13,h13,l13,c13,o14,h14,l14,c14,t10,t11,t12,tc10,tc11] = request.security(syminfo.tickerid, tf1,
 
        [open,high,low,close,
 
         open[1],high[1],low[1],close[1],
 
         open[2],high[2],low[2],close[2],
 
         open[3],high[3],low[3],close[3],
 
         open[4],high[4],low[4],close[4],
 
         time,time[1],time[2],time_close,time_close[1]],
 
        gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
 
[o20,h20,l20,c20,o21,h21,l21,c21,o22,h22,l22,c22,o23,h23,l23,c23,o24,h24,l24,c24,t20,t21,t22,tc20,tc21] = request.security(syminfo.tickerid, tf2,
 
        [open,high,low,close,
 
         open[1],high[1],low[1],close[1],
 
         open[2],high[2],low[2],close[2],
 
         open[3],high[3],low[3],close[3],
 
         open[4],high[4],low[4],close[4],
 
         time,time[1],time[2],time_close,time_close[1]],
 
        gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
 
[o30,h30,l30,c30,o31,h31,l31,c31,o32,h32,l32,c32,o33,h33,l33,c33,o34,h34,l34,c34,t30,t31,t32,tc30,tc31] = request.security(syminfo.tickerid, tf3,
 
        [open,high,low,close,
 
         open[1],high[1],low[1],close[1],
 
         open[2],high[2],low[2],close[2],
 
         open[3],high[3],low[3],close[3],
 
         open[4],high[4],low[4],close[4],
 
         time,time[1],time[2],time_close,time_close[1]],
 
        gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
 
// ============================================================================
 
// CRT STATES AND SIGNALS - computed locally from the consolidated data
 
// ============================================================================
 
state1 = f_state(h10,l10,c10,h11,l11)
 
state2 = f_state(h20,l20,c20,h21,l21)
 
state3 = f_state(h30,l30,c30,h31,l31)
 
prevState1 = f_state(h11,l11,c11,h12,l12)
 
prevState2 = f_state(h21,l21,c21,h22,l22)
 
prevState3 = f_state(h31,l31,c31,h32,l32)
 
newTF1 = ta.change(t10) != 0
 
newTF2 = ta.change(t20) != 0
 
newTF3 = ta.change(t30) != 0
 
bullTrap1 = l11 < l12 and c11 > l12 and (not use50Filter or c11 > (h12+l12)/2.0)
 
bearTrap1 = h11 > h12 and c11 < h12 and (not use50Filter or c11 < (h12+l12)/2.0)
 
bullTrap2 = l21 < l22 and c21 > l22 and (not use50Filter or c21 > (h22+l22)/2.0)
 
bearTrap2 = h21 > h22 and c21 < h22 and (not use50Filter or c21 < (h22+l22)/2.0)
 
bullTrap3 = l31 < l32 and c31 > l32 and (not use50Filter or c31 > (h32+l32)/2.0)
 
bearTrap3 = h31 > h32 and c31 < h32 and (not use50Filter or c31 < (h32+l32)/2.0)
 
bullSignal1 = useTF1 and newTF1 and bullTrap1
 
bearSignal1 = useTF1 and newTF1 and bearTrap1
 
bullSignal2 = useTF2 and newTF2 and bullTrap2
 
bearSignal2 = useTF2 and newTF2 and bearTrap2
 
bullSignal3 = useTF3 and newTF3 and bullTrap3
 
bearSignal3 = useTF3 and newTF3 and bearTrap3
 
anyBull = bullSignal1 or bullSignal2 or bullSignal3
 
anyBear = bearSignal1 or bearSignal2 or bearSignal3
 
plotshape(showCRTSignals and anyBull, title="Bullish CRT", style=shape.labelup, location=location.belowbar,
 
     color=bullSignalColor, text="CRT\nBUY", textcolor=color.black, size=size.tiny)
 
plotshape(showCRTSignals and anyBear, title="Bearish CRT", style=shape.labeldown, location=location.abovebar,
 
     color=bearSignalColor, text="CRT\nSELL", textcolor=color.white, size=size.tiny)
 
alertcondition(anyBull, "Bullish CRT Confirmed", "Bullish CRT confirmed on an enabled timeframe.")
 
alertcondition(anyBear, "Bearish CRT Confirmed", "Bearish CRT confirmed on an enabled timeframe.")
 
// ============================================================================
 
// DRAWING
 
// ============================================================================
 
if barstate.islast
 
    f_clear()
 
    int step = math.max(2 * candleWidth + candleGap + 1, 3)
 
    int span = step * 5 + groupGap
 
    int enabledBefore2 = showHTFCandlesTF1 ? 1 : 0
 
    int start1 = bar_index + rightOffset
 
    int start2 = bar_index + rightOffset + span * enabledBefore2
 
    if showHTFCandlesTF1 and useTF1
 
        f_drawGroup(start1, f_tfName(tf1), tc10, candlesTF1,
 
             o10,h10,l10,c10,o11,h11,l11,c11,o12,h12,l12,c12,o13,h13,l13,c13,o14,h14,l14,c14)
 
    if showHTFCandlesTF2 and useTF2 and maxTFDisplayed >= 2
 
        f_drawGroup(start2, f_tfName(tf2), tc20, candlesTF2,
 
             o20,h20,l20,c20,o21,h21,l21,c21,o22,h22,l22,c22,o23,h23,l23,c23,o24,h24,l24,c24)
 
    // Current CRT range: previous HTF candle boundaries through current HTF candle close.
 
    if useTF1
 
        f_drawRange(f_tfName(tf1), state1, t11, tc10, h11, l11, true)
 
        if maxCRTsVisible >= 2
 
            f_drawRange(f_tfName(tf1), prevState1, t12, tc11, h12, l12, false)
 
    if useTF2
 
        f_drawRange(f_tfName(tf2), state2, t21, tc20, h21, l21, true)
 
        if maxCRTsVisible >= 2
 
            f_drawRange(f_tfName(tf2), prevState2, t22, tc21, h22, l22, false)
 
    if useTF3
 
        f_drawRange(f_tfName(tf3), state3, t31, tc30, h31, l31, true)
 
        if maxCRTsVisible >= 2
 
            f_drawRange(f_tfName(tf3), prevState3, t32, tc31, h32, l32, false)
 
// ============================================================================
 
// DASHBOARD
 
// ============================================================================
 
f_pos(string p) =>
 
    p == "Top Left" ? position.top_left :
 
     p == "Bottom Right" ? position.bottom_right :
 
     p == "Bottom Left" ? position.bottom_left : position.top_right
 
var table dash = table.new(position.top_right, 2, 4, border_width=1)
 
if barstate.islast
 
    table.set_position(dash, f_pos(dashPos))
 
    if showDashboard
 
        table.cell(dash, 0, 0, "CRT TF", text_color=color.white, bgcolor=color.new(color.black, 10))
 
        table.cell(dash, 1, 0, "STATE", text_color=color.white, bgcolor=color.new(color.black, 10))
 
        table.cell(dash, 0, 1, useTF1 ? f_tfName(tf1) : "OFF", text_color=tfLabelColor)
 
        table.cell(dash, 1, 1, useTF1 ? f_stateText(state1) : "Disabled", text_color=useTF1 ? f_stateColor(state1) : color.gray)
 
        table.cell(dash, 0, 2, useTF2 ? f_tfName(tf2) : "OFF", text_color=tfLabelColor)
 
        table.cell(dash, 1, 2, useTF2 ? f_stateText(state2) : "Disabled", text_color=useTF2 ? f_stateColor(state2) : color.gray)
 
        table.cell(dash, 0, 3, useTF3 ? f_tfName(tf3) : "OFF", text_color=tfLabelColor)
 
        table.cell(dash, 1, 3, useTF3 ? f_stateText(state3) : "Disabled", text_color=useTF3 ? f_stateColor(state3) : color.gray)
 
    else
 
        table.clear(dash, 0, 0, 1, 3)
 
// ============================================================================
 
// REQUEST LIMIT NOTE
 
// This edition deliberately uses only 3 request.security() calls:
 
//   1 x TF1
 
//   1 x TF2
 
//   1 x TF3
 
// All OHLC, candle history, timestamps, CRT states and signals are derived
 
// from those consolidated tuples.
 
// ============================================================================

← 返回列表