本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Camarilla Pivots - JAW Trades
//
// Camarilla levels from the prior day's high, low and close:
// CP = prior close (not the (H+L+C)/3 pivot most scripts use)
// R1/S1 = C +/- range * 1.1/12 R2/S2 = C +/- range * 1.1/6
// R3/S3 = C +/- range * 1.1/4 R4/S4 = C +/- range * 1.1/2
// R5 = R4 + 1.168 * (R4 - R3) S5 = S4 - 1.168 * (S3 - S4)
// R6 = (H / L) * C S6 = C - (R6 - C)
//
// Which data (Auto):
// The regular session (9:30am to 4pm ET) by default. If yesterday's after-hours or
// today's premarket traded beyond yesterday's regular-session high or low by more
// than 1% of the daily ATR, the extended-hours high, low and close (4am to 8pm ET)
// are used instead. The table in the top right says which one is in use.
//
// Range: Higher / Lower when today's CP is above / below yesterday's CP by more than
// 20% of the daily ATR, otherwise Neutral.
// Pivots: Wide / Narrow when today's R3 to S3 is wider / narrower than yesterday's by
// more than 5%, otherwise Similar.
//
// Built for US stocks and ETFs. Use it on an intraday chart (1m to 1h).
indicator("Camarilla Pivots - JAW Trades", shorttitle = "Camarilla Pivots - JAW Trades", overlay = true, max_labels_count = 100, max_lines_count = 100)
string TZ = "America/New_York"
// ---------- Inputs
string GL = "Levels"
string modeIn = input.string("Auto", "Prior day data", options = ["Auto", "Regular session", "Extended hours", "SPY/QQQ regular, rest extended"], group = GL, display = display.none, tooltip = "Auto: the regular session (9:30am to 4pm ET), switching to extended hours (4am to 8pm ET) when yesterday's after-hours or today's premarket traded beyond yesterday's regular-session high or low by more than the tolerance under Advanced.")
string closeIn = input.string("Auto", "Close used for CP", options = ["Auto", "Regular session close", "Extended hours close"], group = GL, display = display.none, tooltip = "Auto: the close of whichever data is in use.")
string GLV = "Daily levels: show, colour and opacity, width, style"
bool onR6 = input.bool(true, "R6 ", group = GLV, inline = "R6", display = display.none)
color cR6 = input.color(color.new(#F23645, 45), "", group = GLV, inline = "R6", display = display.none)
int lwR6 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "R6", display = display.none)
string lsR6 = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "R6", display = display.none)
bool onR5 = input.bool(false, "R5 ", group = GLV, inline = "R5", display = display.none)
color cR5 = input.color(color.new(#F23645, 45), "", group = GLV, inline = "R5", display = display.none)
int lwR5 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "R5", display = display.none)
string lsR5 = input.string("Dashed", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "R5", display = display.none)
bool onR4 = input.bool(true, "R4 ", group = GLV, inline = "R4", display = display.none)
color cR4 = input.color(#F23645, "", group = GLV, inline = "R4", display = display.none)
int lwR4 = input.int(2, "", minval = 1, maxval = 5, group = GLV, inline = "R4", display = display.none)
string lsR4 = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "R4", display = display.none)
bool onR3 = input.bool(true, "R3 ", group = GLV, inline = "R3", display = display.none)
color cR3 = input.color(#F23645, "", group = GLV, inline = "R3", display = display.none)
int lwR3 = input.int(3, "", minval = 1, maxval = 5, group = GLV, inline = "R3", display = display.none)
string lsR3 = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "R3", display = display.none)
bool onR2 = input.bool(false, "R2 ", group = GLV, inline = "R2", display = display.none)
color cR2 = input.color(color.new(#F23645, 60), "", group = GLV, inline = "R2", display = display.none)
int lwR2 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "R2", display = display.none)
string lsR2 = input.string("Dotted", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "R2", display = display.none)
bool onR1 = input.bool(false, "R1 ", group = GLV, inline = "R1", display = display.none)
color cR1 = input.color(color.new(#F23645, 60), "", group = GLV, inline = "R1", display = display.none)
int lwR1 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "R1", display = display.none)
string lsR1 = input.string("Dotted", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "R1", display = display.none)
bool onCP = input.bool(true, "CP ", group = GLV, inline = "CP", display = display.none)
color cCP = input.color(#F7C948, "", group = GLV, inline = "CP", display = display.none)
int lwCP = input.int(2, "", minval = 1, maxval = 5, group = GLV, inline = "CP", display = display.none)
string lsCP = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "CP", display = display.none, tooltip = "CP is the prior close, the centre of the day. Untick any level to hide it. The colour picker also sets opacity.")
bool onS1 = input.bool(false, "S1 ", group = GLV, inline = "S1", display = display.none)
color cS1 = input.color(color.new(#089981, 60), "", group = GLV, inline = "S1", display = display.none)
int lwS1 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "S1", display = display.none)
string lsS1 = input.string("Dotted", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "S1", display = display.none)
bool onS2 = input.bool(false, "S2 ", group = GLV, inline = "S2", display = display.none)
color cS2 = input.color(color.new(#089981, 60), "", group = GLV, inline = "S2", display = display.none)
int lwS2 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "S2", display = display.none)
string lsS2 = input.string("Dotted", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "S2", display = display.none)
bool onS3 = input.bool(true, "S3 ", group = GLV, inline = "S3", display = display.none)
color cS3 = input.color(#089981, "", group = GLV, inline = "S3", display = display.none)
int lwS3 = input.int(3, "", minval = 1, maxval = 5, group = GLV, inline = "S3", display = display.none)
string lsS3 = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "S3", display = display.none)
bool onS4 = input.bool(true, "S4 ", group = GLV, inline = "S4", display = display.none)
color cS4 = input.color(#089981, "", group = GLV, inline = "S4", display = display.none)
int lwS4 = input.int(2, "", minval = 1, maxval = 5, group = GLV, inline = "S4", display = display.none)
string lsS4 = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "S4", display = display.none)
bool onS5 = input.bool(false, "S5 ", group = GLV, inline = "S5", display = display.none)
color cS5 = input.color(color.new(#089981, 45), "", group = GLV, inline = "S5", display = display.none)
int lwS5 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "S5", display = display.none)
string lsS5 = input.string("Dashed", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "S5", display = display.none)
bool onS6 = input.bool(true, "S6 ", group = GLV, inline = "S6", display = display.none)
color cS6 = input.color(color.new(#089981, 45), "", group = GLV, inline = "S6", display = display.none)
int lwS6 = input.int(1, "", minval = 1, maxval = 5, group = GLV, inline = "S6", display = display.none)
string lsS6 = input.string("Solid", "", options = ["Solid", "Dashed", "Dotted"], group = GLV, inline = "S6", display = display.none)
string GD = "Display"
bool showHist = input.bool(true, "Show previous days", group = GD, display = display.none)
bool showLabels = input.bool(true, "Labels", group = GD, display = display.none, inline = "lab")
bool showPrices = input.bool(true, "with prices", group = GD, display = display.none, inline = "lab")
string labelSizeIn = input.string("Normal", "Label size", options = ["Small", "Normal", "Large"], group = GD, display = display.none)
int labelOffset = input.int(8, "Label offset (bars)", minval = 1, maxval = 200, group = GD, display = display.none)
bool extendRight = input.bool(false, "Extend today's levels to the right edge", group = GD, display = display.none)
bool showZones = input.bool(true, "Shade the R3 to R4 and S3 to S4 zones", group = GD, display = display.none)
string GT = "Table"
bool showInfo = input.bool(true, "Show the table: data in use, range, pivots, where price is", group = GT, display = display.none)
bool showNext = input.bool(true, "Next session levels in the table", group = GT, display = display.none, tooltip = "Once the day is done (8pm ET, or 4pm ET on regular session data) the table shows tomorrow's levels so you can plan the night before.")
string tableSizeIn = input.string("Normal", "Text size", options = ["Small", "Normal", "Large"], group = GT, display = display.none, inline = "t")
string tablePosIn = input.string("Top right", "Position", options = ["Top right", "Bottom right", "Top left", "Bottom left"], group = GT, display = display.none, inline = "t")
string GW = "Weekly levels"
bool showW = input.bool(false, "Show weekly levels", group = GW, display = display.none, tooltip = "Last week's Camarilla levels for this week, for whichever daily levels are ticked above.")
color wColR = input.color(#FF9E80, "Resistance", group = GW, inline = "wc", display = display.none)
color wColS = input.color(#4DD0E1, "Support", group = GW, inline = "wc", display = display.none)
color wColCP = input.color(#FFE082, "CP", group = GW, inline = "wc", display = display.none)
int wW = input.int(1, "Width", minval = 1, maxval = 5, group = GW, inline = "ws", display = display.none)
string wSt = input.string("Dashed", "Style", options = ["Solid", "Dashed", "Dotted"], group = GW, inline = "ws", display = display.none)
string GM = "Monthly levels"
bool showM = input.bool(false, "Show monthly levels", group = GM, display = display.none, tooltip = "Last month's Camarilla levels for this month, for whichever daily levels are ticked above.")
color mColR = input.color(#F48FB1, "Resistance", group = GM, inline = "mc", display = display.none)
color mColS = input.color(#A5D6A7, "Support", group = GM, inline = "mc", display = display.none)
color mColCP = input.color(#FFF59D, "CP", group = GM, inline = "mc", display = display.none)
int mW = input.int(2, "Width", minval = 1, maxval = 5, group = GM, inline = "ms", display = display.none)
string mSt = input.string("Dashed", "Style", options = ["Solid", "Dashed", "Dotted"], group = GM, inline = "ms", display = display.none)
string GA = "Advanced"
float tolPct = input.float(1.0, "Extended hours switch tolerance (% of daily ATR)", minval = 0, step = 0.1, group = GA, display = display.none)
float rangePct = input.float(20.0, "Neutral range threshold (% of daily ATR)", minval = 0, step = 1, group = GA, display = display.none)
float widthPct = input.float(5.0, "Similar pivot width threshold (%)", minval = 0, step = 0.5, group = GA, display = display.none)
// Solid versions of the main colours (the table, the zones)
color colR = color.new(cR3, 0)
color colS = color.new(cS3, 0)
color colCP = color.new(cCP, 0)
// ---------- Helpers
dayKey(int t) =>
year(t, TZ) * 10000 + month(t, TZ) * 100 + dayofmonth(t, TZ)
rd(float x) =>
na(x) ? na : x >= 1 ? math.round(x, 2) : math.round(x, 4)
mx(float a, float b) =>
na(a) ? b : na(b) ? a : math.max(a, b)
mn(float a, float b) =>
na(a) ? b : na(b) ? a : math.min(a, b)
sizeOf(string s) =>
s == "Small" ? size.small : s == "Large" ? size.large : size.normal
posOf(string s) =>
s == "Bottom right" ? position.bottom_right : s == "Top left" ? position.top_left : s == "Bottom left" ? position.bottom_left : position.top_right
lineStyleOf(string st) =>
st == "Dashed" ? line.style_dashed : st == "Dotted" ? line.style_dotted : line.style_solid
// Dark text on light fills (the yellow CP), white text on dark fills
inkOn(color c) =>
float lum = 0.2126 * color.r(c) + 0.7152 * color.g(c) + 0.0722 * color.b(c)
lum > 150 ? color.rgb(19, 23, 34) : color.white
// Camarilla from prior high, low, close. Order: R6 R5 R4 R3 R2 R1 CP S1 S2 S3 S4 S5 S6
cam(float h, float l, float c) =>
float rng = h - l
float r4 = c + rng * 1.1 / 2
float r3 = c + rng * 1.1 / 4
float s3 = c - rng * 1.1 / 4
float s4 = c - rng * 1.1 / 2
float r5 = r4 + 1.168 * (r4 - r3)
float s5 = s4 - 1.168 * (s3 - s4)
float r6 = l > 0 ? h / l * c : r5 * 1.01
float s6 = c - (r6 - c)
[rd(r6), rd(r5), rd(r4), rd(r3), rd(c + rng * 1.1 / 6), rd(c + rng * 1.1 / 12), rd(c), rd(c - rng * 1.1 / 12), rd(c - rng * 1.1 / 6), rd(s3), rd(s4), rd(s5), rd(s6)]
// Runs on extended-hours intraday bars, one ET calendar day at a time. For each day it keeps
// the regular session (9:30 to 16:00) and extended (4:00 to 20:00) high, low and close, the
// premarket high and low (before 9:30) and the after-hours high and low (16:00 on).
// Returns: today's key; yesterday's numbers plus "outside" = yesterday's after-hours and
// today's premarket; the day before's numbers plus its "outside"; today's running numbers.
dayStats() =>
var int curKey = na
var float eH = na
var float eL = na
var float eC = na
var float rH = na
var float rL = na
var float rC = na
var float poH = na
var float poL = na
var float prH = na
var float prL = na
var float y_eH = na
var float y_eL = na
var float y_eC = na
var float y_rH = na
var float y_rL = na
var float y_rC = na
var float y_poH = na
var float y_poL = na
var float y_prH = na
var float y_prL = na
var float yy_eH = na
var float yy_eL = na
var float yy_eC = na
var float yy_rH = na
var float yy_rL = na
var float yy_rC = na
var float yy_poH = na
var float yy_poL = na
int k = dayKey(time)
if na(curKey) or k != curKey
if not na(curKey)
yy_eH := y_eH
yy_eL := y_eL
yy_eC := y_eC
yy_rH := y_rH
yy_rL := y_rL
yy_rC := y_rC
yy_poH := y_poH
yy_poL := y_poL
y_eH := eH
y_eL := eL
y_eC := eC
y_rH := rH
y_rL := rL
y_rC := rC
y_poH := poH
y_poL := poL
y_prH := prH
y_prL := prL
curKey := k
eH := high
eL := low
eC := close
rH := na
rL := na
rC := na
poH := na
poL := na
prH := na
prL := na
else
eH := math.max(eH, high)
eL := math.min(eL, low)
eC := close
int m = hour(time, TZ) * 60 + minute(time, TZ)
if m < 570
prH := mx(prH, high)
prL := mn(prL, low)
else if m < 960
rH := mx(rH, high)
rL := mn(rL, low)
rC := close
else
poH := mx(poH, high)
poL := mn(poL, low)
[k, y_rH, y_rL, y_rC, y_eH, y_eL, y_eC, mx(y_poH, prH), mn(y_poL, prL), yy_rH, yy_rL, yy_rC, yy_eH, yy_eL, yy_eC, mx(yy_poH, y_prH), mn(yy_poL, y_prL), rH, rL, rC, eH, eL, eC, poH, poL]
// Bars that line up with 9:30 and 16:00 (1m to 30m) are read at the chart's own timeframe;
// anything else reads 5 minute bars.
int secs = timeframe.in_seconds()
string reqTf = timeframe.isintraday and secs >= 60 and secs <= 1800 and 1800 % secs == 0 ? timeframe.period : timeframe.isseconds ? "1" : "5"
string extId = ticker.modify(syminfo.tickerid, session.extended, adjustment.none)
[k, yRH, yRL, yRC, yEH, yEL, yEC, yOH, yOL, yyRH, yyRL, yyRC, yyEH, yyEL, yyEC, yyOH, yyOL, tRH, tRL, tRC, tEH, tEL, tEC, tOH, tOL] = request.security(extId, reqTf, dayStats())
// Daily ATR(14) as of yesterday's close and the day before's (offset, so no lookahead), and
// today's running ATR for the next session's levels (no lookahead: never reads a future bar)
[atr1, atr2] = request.security(syminfo.tickerid, "D", [ta.atr(14)[1], ta.atr(14)[2]], lookahead = barmerge.lookahead_on)
float atr0 = request.security(syminfo.tickerid, "D", ta.atr(14))
bool isSpyQqq = syminfo.ticker == "SPY" or syminfo.ticker == "QQQ"
// Extended-hours data for a day? rH/rL = the prior regular session, oH/oL = what traded
// outside it since (after-hours, then premarket), atr = daily ATR as of that prior close.
useEth(float rH, float rL, float oH, float oL, float atr) =>
float tol = na(atr) ? na : atr * tolPct / 100
switch modeIn
"Extended hours" => true
"Regular session" => false
"SPY/QQQ regular, rest extended" => not isSpyQqq
=> oH - rH > tol or rL - oL > tol
pickClose(bool eth, float rC, float eC) =>
closeIn == "Regular session close" ? rC : closeIn == "Extended hours close" ? eC : eth ? eC : rC
bool ethToday = useEth(yRH, yRL, yOH, yOL, atr1)
bool ethYday = useEth(yyRH, yyRL, yyOH, yyOL, atr2)
bool ethNext = useEth(tRH, tRL, tOH, tOL, atr0)
// Today's levels (from yesterday), yesterday's (for range and width), and the next session's
[R6, R5, R4, R3, R2, R1, CP, S1, S2, S3, S4, S5, S6] = cam(ethToday ? yEH : yRH, ethToday ? yEL : yRL, pickClose(ethToday, yRC, yEC))
[q6, q5, q4, q3, q2, q1, qCP, z1, z2, z3, z4, z5, z6] = cam(ethYday ? yyEH : yyRH, ethYday ? yyEL : yyRL, pickClose(ethYday, yyRC, yyEC))
[n6, n5, n4, n3, n2, n1, nCP, m1, m2, m3, m4, m5, m6] = cam(ethNext ? tEH : tRH, ethNext ? tEL : tRL, pickClose(ethNext, tRC, tEC))
// Range and pivot width
float rangeTol = na(atr1) ? na : atr1 * rangePct / 100
string rangeTxt = CP - qCP > rangeTol ? "Higher" : qCP - CP > rangeTol ? "Lower" : "Neutral"
float wNow = R3 - S3
float wPrev = q3 - z3
string widthTxt = wNow > wPrev * (1 + widthPct / 100) ? "Wide" : wNow < wPrev * (1 - widthPct / 100) ? "Narrow" : "Similar"
// ---------- Daily lines
int lastKey = dayKey(last_bar_time)
bool newDay = na(k[1]) or k != k[1]
bool visible = not na(k) and not newDay and (showHist or k == lastKey)
lv(float v, bool on) =>
visible and on ? v : na
plot(lv(R6, onR6), "R6", cR6, lwR6, plot.style_linebr, display = display.all - display.status_line, linestyle = lsR6 == "Dashed" ? plot.linestyle_dashed : lsR6 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(R5, onR5), "R5", cR5, lwR5, plot.style_linebr, display = display.all - display.status_line, linestyle = lsR5 == "Dashed" ? plot.linestyle_dashed : lsR5 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
pR4 = plot(lv(R4, onR4), "R4", cR4, lwR4, plot.style_linebr, display = display.all - display.status_line, linestyle = lsR4 == "Dashed" ? plot.linestyle_dashed : lsR4 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
pR3 = plot(lv(R3, onR3), "R3", cR3, lwR3, plot.style_linebr, display = display.all - display.status_line, linestyle = lsR3 == "Dashed" ? plot.linestyle_dashed : lsR3 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(R2, onR2), "R2", cR2, lwR2, plot.style_linebr, display = display.all - display.status_line, linestyle = lsR2 == "Dashed" ? plot.linestyle_dashed : lsR2 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(R1, onR1), "R1", cR1, lwR1, plot.style_linebr, display = display.all - display.status_line, linestyle = lsR1 == "Dashed" ? plot.linestyle_dashed : lsR1 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(CP, onCP), "CP", cCP, lwCP, plot.style_linebr, display = display.all - display.status_line, linestyle = lsCP == "Dashed" ? plot.linestyle_dashed : lsCP == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(S1, onS1), "S1", cS1, lwS1, plot.style_linebr, display = display.all - display.status_line, linestyle = lsS1 == "Dashed" ? plot.linestyle_dashed : lsS1 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(S2, onS2), "S2", cS2, lwS2, plot.style_linebr, display = display.all - display.status_line, linestyle = lsS2 == "Dashed" ? plot.linestyle_dashed : lsS2 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
pS3 = plot(lv(S3, onS3), "S3", cS3, lwS3, plot.style_linebr, display = display.all - display.status_line, linestyle = lsS3 == "Dashed" ? plot.linestyle_dashed : lsS3 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
pS4 = plot(lv(S4, onS4), "S4", cS4, lwS4, plot.style_linebr, display = display.all - display.status_line, linestyle = lsS4 == "Dashed" ? plot.linestyle_dashed : lsS4 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(S5, onS5), "S5", cS5, lwS5, plot.style_linebr, display = display.all - display.status_line, linestyle = lsS5 == "Dashed" ? plot.linestyle_dashed : lsS5 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
plot(lv(S6, onS6), "S6", cS6, lwS6, plot.style_linebr, display = display.all - display.status_line, linestyle = lsS6 == "Dashed" ? plot.linestyle_dashed : lsS6 == "Dotted" ? plot.linestyle_dotted : plot.linestyle_solid)
// R3 to R4 and S3 to S4: where the main reactions and breakouts happen
fill(pR3, pR4, showZones ? color.new(colR, 91) : na, "R3 to R4 zone")
fill(pS3, pS4, showZones ? color.new(colS, 91) : na, "S3 to S4 zone")
// ---------- Weekly and monthly lines (this week's and this month's, from the prior week and month)
[wH, wL, wC] = request.security(syminfo.tickerid, "W", [high[1], low[1], close[1]], lookahead = barmerge.lookahead_on)
[mH, mL, mC] = request.security(syminfo.tickerid, "M", [high[1], low[1], close[1]], lookahead = barmerge.lookahead_on)
[w6, w5, w4, w3, w2, w1, wCP, ws1, ws2, ws3, ws4, ws5, ws6] = cam(wH, wL, wC)
[mo6, mo5, mo4, mo3, mo2, mo1, mCP, ms1, ms2, ms3, ms4, ms5, ms6] = cam(mH, mL, mC)
// Weekly and monthly levels are drawn as lines from the start of this week / month (on the
// last bar, below), not as plots: TradingView allows 64 plots per script.
var int wStartT = na
var int mStartT = na
if bar_index == 0 or weekofyear(time) != weekofyear(time[1])
wStartT := time
if bar_index == 0 or month(time) != month(time[1])
mStartT := time
// ---------- Alerts (create them from the alert menu, condition "Camarilla Pivots - JAW Trades")
bool live = visible
alertcondition(live and ta.cross(close, R3), "Price crossed R3", "{{ticker}} crossed R3 at {{close}}")
alertcondition(live and ta.cross(close, R4), "Price crossed R4", "{{ticker}} crossed R4 at {{close}}")
alertcondition(live and ta.cross(close, S3), "Price crossed S3", "{{ticker}} crossed S3 at {{close}}")
alertcondition(live and ta.cross(close, S4), "Price crossed S4", "{{ticker}} crossed S4 at {{close}}")
alertcondition(live and ta.cross(close, CP), "Price crossed CP", "{{ticker}} crossed CP at {{close}}")
alertcondition(live and (ta.cross(close, R3) or ta.cross(close, R4) or ta.cross(close, S3) or ta.cross(close, S4)), "Price crossed R3, R4, S3 or S4", "{{ticker}} crossed a Camarilla level at {{close}}")
// ---------- Labels and table (last bar only)
var array<string> names = array.from("R6", "R5", "R4", "R3", "R2", "R1", "CP", "S1", "S2", "S3", "S4", "S5", "S6")
var array<bool> shows = array.from(onR6, onR5, onR4, onR3, onR2, onR1, onCP, onS1, onS2, onS3, onS4, onS5, onS6)
var array<bool> wmShows = array.from(onR6, onR5, onR4, onR3, false, false, onCP, false, false, onS3, onS4, onS5, onS6)
var array<color> cols = array.from(cR6, cR5, cR4, cR3, cR2, cR1, cCP, cS1, cS2, cS3, cS4, cS5, cS6)
var array<int> widths = array.from(lwR6, lwR5, lwR4, lwR3, lwR2, lwR1, lwCP, lwS1, lwS2, lwS3, lwS4, lwS5, lwS6)
var array<string> styles = array.from(lsR6, lsR5, lsR4, lsR3, lsR2, lsR1, lsCP, lsS1, lsS2, lsS3, lsS4, lsS5, lsS6)
lvlColor(int i) =>
cols.get(i)
// The tag behind a label: the level's colour, never fainter than 25% so the text stays readable
tagColor(color c) =>
color.new(c, math.min(color.t(c), 25))
wmColor(int i, color r, color cp, color sp) =>
i < 6 ? r : i == 6 ? cp : sp
string LSIZE = sizeOf(labelSizeIn)
string TSIZE = sizeOf(tableSizeIn)
// One level: a solid line from the last bar to a filled tag with the name and price
addLevel(array<label> labs, array<line> lns, int off, float y, string name, color lineCol, color fillCol, color textCol, int w, string st, bool ext) =>
if not na(y)
lns.push(line.new(bar_index, y, bar_index + off, y, xloc.bar_index, ext ? extend.right : extend.none, lineCol, lineStyleOf(st), w))
string txt = showPrices ? name + " " + str.tostring(y, format.mintick) : name
labs.push(label.new(bar_index + off, y, txt, xloc.bar_index, yloc.price, fillCol, label.style_label_left, textCol, LSIZE))
// A weekly or monthly level: a line from the start of the period to its label on the right
addPeriodLevel(array<label> labs, array<line> lns, int t0, int off, float y, string name, color c, int w, string st) =>
if not na(y) and not na(t0)
int t1 = time + off * timeframe.in_seconds() * 1000
lns.push(line.new(t0, y, t1, y, xloc.bar_time, extend.none, c, lineStyleOf(st), w))
string txt = showPrices ? name + " " + str.tostring(y, format.mintick) : name
labs.push(label.new(t1, y, txt, xloc.bar_time, yloc.price, tagColor(c), label.style_label_left, inkOn(c), LSIZE))
// Where price is right now, in Camarilla terms
zoneOf(float p) =>
na(p) or na(CP) ? "-" : p > R6 ? "Above R6" : p > R5 ? "R5 to R6" : p > R4 ? "R4 to R5" : p > R3 ? "R3 to R4" : p > CP ? "CP to R3" : p >= S3 ? "S3 to CP" : p >= S4 ? "S4 to S3" : p >= S5 ? "S5 to S4" : p >= S6 ? "S6 to S5" : "Below S6"
var array<label> labs = array.new<label>()
var array<line> lns = array.new<line>()
// The table follows the chart's own theme, light or dark
color INK = chart.fg_color
color MUTED = color.new(chart.fg_color, 50)
var table tb = table.new(posOf(tablePosIn), 2, 26, bgcolor = color.new(chart.bg_color, 4), frame_color = color.new(chart.fg_color, 82), frame_width = 1, border_color = color.new(chart.fg_color, 92), border_width = 1)
row2(int r, string l, string v, color lc, color vc) =>
tb.cell(0, r, l, text_color = lc, text_size = TSIZE, text_halign = text.align_left)
tb.cell(1, r, v, text_color = vc, text_size = TSIZE, text_halign = text.align_right)
if barstate.islast
for lb in labs
label.delete(lb)
labs.clear()
for ln in lns
line.delete(ln)
lns.clear()
if showLabels and timeframe.isintraday
array<float> today = array.from(R6, R5, R4, R3, R2, R1, CP, S1, S2, S3, S4, S5, S6)
for i = 0 to 12
if shows.get(i)
color c = lvlColor(i)
addLevel(labs, lns, labelOffset, today.get(i), names.get(i), c, tagColor(c), inkOn(c), widths.get(i), styles.get(i), extendRight)
if showW
array<float> wk = array.from(w6, w5, w4, w3, w2, w1, wCP, ws1, ws2, ws3, ws4, ws5, ws6)
for i = 0 to 12
if wmShows.get(i)
addPeriodLevel(labs, lns, wStartT, labelOffset + 14, wk.get(i), "W " + names.get(i), wmColor(i, wColR, wColCP, wColS), wW, wSt)
if showM
array<float> mo = array.from(mo6, mo5, mo4, mo3, mo2, mo1, mCP, ms1, ms2, ms3, ms4, ms5, ms6)
for i = 0 to 12
if wmShows.get(i)
addPeriodLevel(labs, lns, mStartT, labelOffset + 28, mo.get(i), "M " + names.get(i), wmColor(i, mColR, mColCP, mColS), mW, mSt)
tb.clear(0, 0, 1, 25)
int row = 0
if showInfo or showNext
row2(row, "Camarilla Pivots", showInfo ? (ethToday ? "Extended hours" : "Regular session") : "", colCP, MUTED)
row += 1
if showInfo
float wChg = wPrev > 0 ? (wNow / wPrev - 1) * 100 : na
string wTxt = widthTxt + (na(wChg) ? "" : " " + (wChg >= 0 ? "+" : "") + str.tostring(wChg, "0") + "%")
row2(row, "Range", rangeTxt == "Higher" ? "Higher ▲" : rangeTxt == "Lower" ? "Lower ▼" : "Neutral", MUTED, rangeTxt == "Higher" ? colS : rangeTxt == "Lower" ? colR : INK)
row += 1
row2(row, "Pivots", wTxt, MUTED, INK)
row += 1
if timeframe.isintraday
string z = zoneOf(close)
row2(row, "Price", z, MUTED, close > CP ? colR : close < CP ? colS : INK)
row += 1
if showNext
int nowKey = dayKey(timenow)
int nowMin = hour(timenow, TZ) * 60 + minute(timenow, TZ)
bool regOnly = modeIn == "Regular session" or (modeIn == "SPY/QQQ regular, rest extended" and isSpyQqq)
bool dayDone = nowKey > k or nowMin >= (regOnly ? 960 : 1200)
if dayDone and not na(n4)
row2(row, "Next session", ethNext ? "Extended hours" : "Regular session", colCP, MUTED)
row += 1
array<float> nxt = array.from(n6, n5, n4, n3, n2, n1, nCP, m1, m2, m3, m4, m5, m6)
for i = 0 to 12
if shows.get(i)
row2(row, names.get(i), str.tostring(nxt.get(i), format.mintick), color.new(lvlColor(i), 0), INK)
row += 1
if modeIn == "Auto" and not ethNext
row2(row, "Auto", "may switch in premarket", MUTED, MUTED)
else
row2(row, "Next session", "after " + (regOnly ? "4pm" : "8pm") + " ET", colCP, MUTED)