PINE LIBRARY
qqq_momentum_engine

Library "qqq_momentum_engine"
exitAtrMode(atrTf)
Decide how the exit ATR must be sourced, and refuse the one
case that cannot be sourced honestly.
SPEC v3 Part VII.4, pinned:
atrTf > chart → completed-HTF-bar request (see the note above)
atrTf == chart → local ta.atr() on the confirmed bar, no request at all
atrTf < chart → runtime.error. Unsupported, and deliberately so: a
sub-chart ATR would need request.security_lower_tf
and an intrabar walk to be meaningful, and an exit
distance is not worth that machinery. Failing loudly
beats returning a number that looks like an ATR.
Parameters:
atrTf (simple string): The exit ATR timeframe, as a Pine timeframe string.
Returns: 0 = compute locally (same timeframe), 1 = request the HTF bar.
exitTicks(ex, atrRef)
Exit distances as WHOLE TICKS. The single source of exit
geometry for both strategy.pine and labeler.pine.
Quantisation lives here on purpose. strategy.exit()'s profit/loss
parameters are tick counts, so the backtest necessarily trades a rounded
distance. If the labeller measured the raw float instead, ATR mode would
diverge: a 0.9274 distance becomes a 0.93 order, and a bar reaching 0.928
would be labelled "target" for a target the strategy never had. Both sides
now derive their levels from the same integers, so that gap cannot exist.
minMoveFloor clamps BOTH legs in atr mode. 0.75 x a 5m QQQ ATR can be a few
cents; a target or a stop narrower than the option spread is not a
measurable event.
Returns [na, na] when atr mode is selected and atrRef is na (ATR warmup).
Callers must check — an na bracket is silently no bracket at all.
Parameters:
ex (Exits): Exits configuration.
atrRef (float): ATR to use in "atr" mode. Ignored in "fixed" mode.
Returns: [targetTicks, stopTicks]
ticksToPrices(entry, dir, tgtTicks, stpTicks)
Convert tick distances into absolute prices for one fill.
Used by labeler.pine to build its walk levels and by
strategy.pine only to DRAW the levels it already sent as
tick brackets.
Parameters:
entry (float): Fill price.
dir (int): +1 long, -1 short.
tgtTicks (int): Target distance in ticks, from exitTicks().
stpTicks (int): Stop distance in ticks, from exitTicks().
Returns: [target, stop]
vwapSideOf(dir, closeV, vwapV)
The VWAP side label for ONE signal, per SPEC v3 Part III.3.
"with" = the signal direction agrees with the VWAP side
(long above VWAP, short below it)
"against" = it does not
A TIE COUNTS AS "against". close == vwap is not agreement,
and the strict comparison keeps the label reproducible
instead of depending on float equality luck.
Parameters:
dir (int): +1 long, -1 short.
closeV (float): The signal bar's close.
vwapV (float): Session VWAP on the signal bar.
Returns: "with" | "against"
evaluate(cfg, bodyLen, volLen, extAtrLen)
Evaluate the QQQ Momentum Trigger for this bar.
One call per bar per script. All state (ring buffer,
cooldown marks) is per call site and mutates only on
confirmed bars.
Parameters:
cfg (Config): Every parameter of the signal definition.
bodyLen (simple int): Body baseline window. Must equal cfg.bodyLen.
volLen (simple int): Volume baseline window. Must equal cfg.volLen.
extAtrLen (simple int): Extension ATR length. Must equal cfg.extAtrLen.
Returns: Signal for this bar.
tz()
The timezone every minute-of-day calculation in this library uses.
Exposed so consuming scripts format timestamps identically.
Returns: "America/New_York"
Config
Fields:
useSlope (series bool)
useCandle (series bool)
closeLocPct (series float)
bodyMult (series float)
bodyLen (series int)
volumeMode (series string)
volMult (series float)
volLen (series int)
rvolThreshold (series float)
rvolSessions (series int)
rvolMinSessions (series int)
useStructure (series bool)
useExtension (series bool)
extMult (series float)
extAtrLen (series int)
cooldownBars (series int)
requiredTfSeconds (series int)
requireStandardChart (series bool)
requireRegularSessionChart (series bool)
regularSessionOnly (series bool)
sessionStartMin (series int)
sessionMinutes (series int)
blockLastMinutes (series int)
Signal
Fields:
long (series bool)
short (series bool)
ema9 (series float)
slopeUp (series bool)
slopeDn (series bool)
reclaimLong (series bool)
reclaimShort (series bool)
isGreen (series bool)
isRed (series bool)
closeLocLongOk (series bool)
closeLocShortOk (series bool)
bodyOk (series bool)
bodyRatio (series float)
bodyBase (series float)
candleLongOk (series bool)
candleShortOk (series bool)
volRatio (series float)
volBase (series float)
volPass (series bool)
rvol (series float)
rvolBaseline (series float)
rvolFill (series int)
rvolWarm (series bool)
rvolBucketsShort (series int)
rvolBucketsEmpty (series int)
structLongOk (series bool)
structShortOk (series bool)
atrExt (series float)
emaDistAtr (series float)
extLongOk (series bool)
extShortOk (series bool)
vwap (series float)
vwapDist (series float)
vwapAbove (series bool)
cooldownLongOk (series bool)
cooldownShortOk (series bool)
barsSinceLong (series int)
barsSinceShort (series int)
inSession (series bool)
lateBlock (series bool)
warmupOk (series bool)
minuteOfDay (series int)
bucket (series int)
bucketRows (series int)
minutesLeft (series int)
longF1Reclaim (series bool)
longF2Slope (series bool)
longF3Candle (series bool)
longF4Volume (series bool)
longF5Struct (series bool)
longF6Ext (series bool)
longF7Gate (series bool)
shortF1Reclaim (series bool)
shortF2Slope (series bool)
shortF3Candle (series bool)
shortF4Volume (series bool)
shortF5Struct (series bool)
shortF6Ext (series bool)
shortF7Gate (series bool)
Exits
Fields:
mode (series string)
fixedTarget (series float)
fixedStop (series float)
atrTargetMult (series float)
atrStopMult (series float)
minMoveFloor (series float)
maxBarsInTrade (series int)
exitAtrMode(atrTf)
Decide how the exit ATR must be sourced, and refuse the one
case that cannot be sourced honestly.
SPEC v3 Part VII.4, pinned:
atrTf > chart → completed-HTF-bar request (see the note above)
atrTf == chart → local ta.atr() on the confirmed bar, no request at all
atrTf < chart → runtime.error. Unsupported, and deliberately so: a
sub-chart ATR would need request.security_lower_tf
and an intrabar walk to be meaningful, and an exit
distance is not worth that machinery. Failing loudly
beats returning a number that looks like an ATR.
Parameters:
atrTf (simple string): The exit ATR timeframe, as a Pine timeframe string.
Returns: 0 = compute locally (same timeframe), 1 = request the HTF bar.
exitTicks(ex, atrRef)
Exit distances as WHOLE TICKS. The single source of exit
geometry for both strategy.pine and labeler.pine.
Quantisation lives here on purpose. strategy.exit()'s profit/loss
parameters are tick counts, so the backtest necessarily trades a rounded
distance. If the labeller measured the raw float instead, ATR mode would
diverge: a 0.9274 distance becomes a 0.93 order, and a bar reaching 0.928
would be labelled "target" for a target the strategy never had. Both sides
now derive their levels from the same integers, so that gap cannot exist.
minMoveFloor clamps BOTH legs in atr mode. 0.75 x a 5m QQQ ATR can be a few
cents; a target or a stop narrower than the option spread is not a
measurable event.
Returns [na, na] when atr mode is selected and atrRef is na (ATR warmup).
Callers must check — an na bracket is silently no bracket at all.
Parameters:
ex (Exits): Exits configuration.
atrRef (float): ATR to use in "atr" mode. Ignored in "fixed" mode.
Returns: [targetTicks, stopTicks]
ticksToPrices(entry, dir, tgtTicks, stpTicks)
Convert tick distances into absolute prices for one fill.
Used by labeler.pine to build its walk levels and by
strategy.pine only to DRAW the levels it already sent as
tick brackets.
Parameters:
entry (float): Fill price.
dir (int): +1 long, -1 short.
tgtTicks (int): Target distance in ticks, from exitTicks().
stpTicks (int): Stop distance in ticks, from exitTicks().
Returns: [target, stop]
vwapSideOf(dir, closeV, vwapV)
The VWAP side label for ONE signal, per SPEC v3 Part III.3.
"with" = the signal direction agrees with the VWAP side
(long above VWAP, short below it)
"against" = it does not
A TIE COUNTS AS "against". close == vwap is not agreement,
and the strict comparison keeps the label reproducible
instead of depending on float equality luck.
Parameters:
dir (int): +1 long, -1 short.
closeV (float): The signal bar's close.
vwapV (float): Session VWAP on the signal bar.
Returns: "with" | "against"
evaluate(cfg, bodyLen, volLen, extAtrLen)
Evaluate the QQQ Momentum Trigger for this bar.
One call per bar per script. All state (ring buffer,
cooldown marks) is per call site and mutates only on
confirmed bars.
Parameters:
cfg (Config): Every parameter of the signal definition.
bodyLen (simple int): Body baseline window. Must equal cfg.bodyLen.
volLen (simple int): Volume baseline window. Must equal cfg.volLen.
extAtrLen (simple int): Extension ATR length. Must equal cfg.extAtrLen.
Returns: Signal for this bar.
tz()
The timezone every minute-of-day calculation in this library uses.
Exposed so consuming scripts format timestamps identically.
Returns: "America/New_York"
Config
Fields:
useSlope (series bool)
useCandle (series bool)
closeLocPct (series float)
bodyMult (series float)
bodyLen (series int)
volumeMode (series string)
volMult (series float)
volLen (series int)
rvolThreshold (series float)
rvolSessions (series int)
rvolMinSessions (series int)
useStructure (series bool)
useExtension (series bool)
extMult (series float)
extAtrLen (series int)
cooldownBars (series int)
requiredTfSeconds (series int)
requireStandardChart (series bool)
requireRegularSessionChart (series bool)
regularSessionOnly (series bool)
sessionStartMin (series int)
sessionMinutes (series int)
blockLastMinutes (series int)
Signal
Fields:
long (series bool)
short (series bool)
ema9 (series float)
slopeUp (series bool)
slopeDn (series bool)
reclaimLong (series bool)
reclaimShort (series bool)
isGreen (series bool)
isRed (series bool)
closeLocLongOk (series bool)
closeLocShortOk (series bool)
bodyOk (series bool)
bodyRatio (series float)
bodyBase (series float)
candleLongOk (series bool)
candleShortOk (series bool)
volRatio (series float)
volBase (series float)
volPass (series bool)
rvol (series float)
rvolBaseline (series float)
rvolFill (series int)
rvolWarm (series bool)
rvolBucketsShort (series int)
rvolBucketsEmpty (series int)
structLongOk (series bool)
structShortOk (series bool)
atrExt (series float)
emaDistAtr (series float)
extLongOk (series bool)
extShortOk (series bool)
vwap (series float)
vwapDist (series float)
vwapAbove (series bool)
cooldownLongOk (series bool)
cooldownShortOk (series bool)
barsSinceLong (series int)
barsSinceShort (series int)
inSession (series bool)
lateBlock (series bool)
warmupOk (series bool)
minuteOfDay (series int)
bucket (series int)
bucketRows (series int)
minutesLeft (series int)
longF1Reclaim (series bool)
longF2Slope (series bool)
longF3Candle (series bool)
longF4Volume (series bool)
longF5Struct (series bool)
longF6Ext (series bool)
longF7Gate (series bool)
shortF1Reclaim (series bool)
shortF2Slope (series bool)
shortF3Candle (series bool)
shortF4Volume (series bool)
shortF5Struct (series bool)
shortF6Ext (series bool)
shortF7Gate (series bool)
Exits
Fields:
mode (series string)
fixedTarget (series float)
fixedStop (series float)
atrTargetMult (series float)
atrStopMult (series float)
minMoveFloor (series float)
maxBarsInTrade (series int)
ไลบรารีไพน์
ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์สไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
ไลบรารีไพน์
ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์สไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน