PINE LIBRARY
emaStackCore

Library "emaStackCore"
emaCalc(source, length)
Calculate EMA
Parameters:
source (float): Price source (close, hl2, etc.)
length (simple int): EMA period
Returns: EMA value
emaSlope(emaValue, lookback)
Calculate EMA slope (% change over lookback period)
Parameters:
emaValue (float): Current EMA value
lookback (int): Number of bars to look back
Returns: Slope in percentage
emaDist(ema1, ema2, mode, atrVal, price)
Calculate distance between 2 EMAs (normalized)
Parameters:
ema1 (float): First EMA value
ema2 (float): Second EMA value
mode (string): Normalization mode ("ATR" or "%")
atrVal (float): ATR value for ATR mode
price (float): Reference price for % mode
Returns: Normalized distance
slopeClass(slope, thresholdFlat)
Classify EMA slope
Parameters:
slope (float): EMA slope in %
thresholdFlat (float): Threshold to consider slope as flat
Returns: +1 (rising), 0 (flat), -1 (falling)
slopeScore5(slope10, slope20, slope50, slope100, slope200, threshold)
Calculate combined slope score for 5 EMAs
Parameters:
slope10 (float): EMA10 slope
slope20 (float): EMA20 slope
slope50 (float): EMA50 slope
slope100 (float): EMA100 slope
slope200 (float): EMA200 slope
threshold (float): Flat threshold
Returns: Sum of slope classes (-5 to +5)
emaStack5Score(e10, e20, e50, e100, e200, tolEq)
Calculate EMA stack score (5 EMAs)
Parameters:
e10 (float): EMA 10 value
e20 (float): EMA 20 value
e50 (float): EMA 50 value
e100 (float): EMA 100 value
e200 (float): EMA 200 value
tolEq (float): Tolerance for equality (%)
Returns: Stack score (-4 to +4)
emaStack5ScoreWithSlope(e10, e20, e50, e100, e200, slope10, slope20, slope50, slope100, slope200, tolEq, slopeThreshold)
Enhanced EMA stack with slope
Parameters:
e10 (float)
e20 (float)
e50 (float)
e100 (float)
e200 (float)
slope10 (float)
slope20 (float)
slope50 (float)
slope100 (float)
slope200 (float)
tolEq (float)
slopeThreshold (float)
Returns: [score, slopeScore]
emaRegimeChange(currentScore, previousScore, threshold)
Detect regime change in EMA stack
Parameters:
currentScore (int): Current stack score
previousScore (int): Previous stack score
threshold (int): Minimum change to consider significant
Returns: [changed, direction, delta]
emaCompressed(e10, e20, e50, e100, e200, threshold)
Detect EMA compression (squeeze)
Parameters:
e10 (float): EMA 10 value
e20 (float): EMA 20 value
e50 (float): EMA 50 value
e100 (float): EMA 100 value
e200 (float): EMA 200 value
threshold (float): Max spread % to consider compressed
Returns: [compressed, spread]
emaConfluence9(price, e10_tf1, e20_tf1, e50_tf1, e10_tf2, e20_tf2, e50_tf2, e10_tf3, e20_tf3, e50_tf3, threshold)
Calculate confluence score (how many EMAs are near price)
Parameters:
price (float): Current price
e10_tf1 (float): EMA10 on timeframe 1
e20_tf1 (float): EMA20 on timeframe 1
e50_tf1 (float): EMA50 on timeframe 1
e10_tf2 (float): EMA10 on timeframe 2
e20_tf2 (float): EMA20 on timeframe 2
e50_tf2 (float): EMA50 on timeframe 2
e10_tf3 (float): EMA10 on timeframe 3
e20_tf3 (float): EMA20 on timeframe 3
e50_tf3 (float): EMA50 on timeframe 3
threshold (float): Max distance % to consider "near"
Returns: Confluence count (0-9)
emaConfluence3(price, e10, e20, e50, threshold)
Simplified confluence for 3 EMAs on single TF
Parameters:
price (float)
e10 (float)
e20 (float)
e50 (float)
threshold (float)
Returns: Confluence count (0-3)
emaLeadLag(score15m, score1H, score4H, lookback)
Determine which timeframe is leading the move
Parameters:
score15m (int): Stack score on 15m
score1H (int): Stack score on 1H
score4H (int): Stack score on 4H
lookback (int): Bars to look back for change detection
Returns: Leader timeframe ("15m", "1H", "4H", "ALIGNED", "MIXED")
emaPriceDivergence(price, emaValue, lookback)
Detect divergence between price and EMA direction
Parameters:
price (float): Current price
emaValue (float): EMA value (typically EMA20)
lookback (int): Bars to compare
Returns: [divergence, priceChange%, emaChange%]
emaOrderStrength(e10, e20, e50, e100, e200)
Calculate EMA order strength (weighted by distance)
Parameters:
e10 (float): EMA 10
e20 (float): EMA 20
e50 (float): EMA 50
e100 (float): EMA 100
e200 (float): EMA 200
Returns: Strength score (higher = stronger trend)
emaPriceZone(price, e10, e20, e50, e100, e200)
Determine which EMA zone price is in
Parameters:
price (float): Current price
e10 (float): EMA 10
e20 (float): EMA 20
e50 (float): EMA 50
e100 (float): EMA 100
e200 (float): EMA 200
Returns: Zone code (5=above all, 0=below all, -1=mixed)
emaCalc(source, length)
Calculate EMA
Parameters:
source (float): Price source (close, hl2, etc.)
length (simple int): EMA period
Returns: EMA value
emaSlope(emaValue, lookback)
Calculate EMA slope (% change over lookback period)
Parameters:
emaValue (float): Current EMA value
lookback (int): Number of bars to look back
Returns: Slope in percentage
emaDist(ema1, ema2, mode, atrVal, price)
Calculate distance between 2 EMAs (normalized)
Parameters:
ema1 (float): First EMA value
ema2 (float): Second EMA value
mode (string): Normalization mode ("ATR" or "%")
atrVal (float): ATR value for ATR mode
price (float): Reference price for % mode
Returns: Normalized distance
slopeClass(slope, thresholdFlat)
Classify EMA slope
Parameters:
slope (float): EMA slope in %
thresholdFlat (float): Threshold to consider slope as flat
Returns: +1 (rising), 0 (flat), -1 (falling)
slopeScore5(slope10, slope20, slope50, slope100, slope200, threshold)
Calculate combined slope score for 5 EMAs
Parameters:
slope10 (float): EMA10 slope
slope20 (float): EMA20 slope
slope50 (float): EMA50 slope
slope100 (float): EMA100 slope
slope200 (float): EMA200 slope
threshold (float): Flat threshold
Returns: Sum of slope classes (-5 to +5)
emaStack5Score(e10, e20, e50, e100, e200, tolEq)
Calculate EMA stack score (5 EMAs)
Parameters:
e10 (float): EMA 10 value
e20 (float): EMA 20 value
e50 (float): EMA 50 value
e100 (float): EMA 100 value
e200 (float): EMA 200 value
tolEq (float): Tolerance for equality (%)
Returns: Stack score (-4 to +4)
emaStack5ScoreWithSlope(e10, e20, e50, e100, e200, slope10, slope20, slope50, slope100, slope200, tolEq, slopeThreshold)
Enhanced EMA stack with slope
Parameters:
e10 (float)
e20 (float)
e50 (float)
e100 (float)
e200 (float)
slope10 (float)
slope20 (float)
slope50 (float)
slope100 (float)
slope200 (float)
tolEq (float)
slopeThreshold (float)
Returns: [score, slopeScore]
emaRegimeChange(currentScore, previousScore, threshold)
Detect regime change in EMA stack
Parameters:
currentScore (int): Current stack score
previousScore (int): Previous stack score
threshold (int): Minimum change to consider significant
Returns: [changed, direction, delta]
emaCompressed(e10, e20, e50, e100, e200, threshold)
Detect EMA compression (squeeze)
Parameters:
e10 (float): EMA 10 value
e20 (float): EMA 20 value
e50 (float): EMA 50 value
e100 (float): EMA 100 value
e200 (float): EMA 200 value
threshold (float): Max spread % to consider compressed
Returns: [compressed, spread]
emaConfluence9(price, e10_tf1, e20_tf1, e50_tf1, e10_tf2, e20_tf2, e50_tf2, e10_tf3, e20_tf3, e50_tf3, threshold)
Calculate confluence score (how many EMAs are near price)
Parameters:
price (float): Current price
e10_tf1 (float): EMA10 on timeframe 1
e20_tf1 (float): EMA20 on timeframe 1
e50_tf1 (float): EMA50 on timeframe 1
e10_tf2 (float): EMA10 on timeframe 2
e20_tf2 (float): EMA20 on timeframe 2
e50_tf2 (float): EMA50 on timeframe 2
e10_tf3 (float): EMA10 on timeframe 3
e20_tf3 (float): EMA20 on timeframe 3
e50_tf3 (float): EMA50 on timeframe 3
threshold (float): Max distance % to consider "near"
Returns: Confluence count (0-9)
emaConfluence3(price, e10, e20, e50, threshold)
Simplified confluence for 3 EMAs on single TF
Parameters:
price (float)
e10 (float)
e20 (float)
e50 (float)
threshold (float)
Returns: Confluence count (0-3)
emaLeadLag(score15m, score1H, score4H, lookback)
Determine which timeframe is leading the move
Parameters:
score15m (int): Stack score on 15m
score1H (int): Stack score on 1H
score4H (int): Stack score on 4H
lookback (int): Bars to look back for change detection
Returns: Leader timeframe ("15m", "1H", "4H", "ALIGNED", "MIXED")
emaPriceDivergence(price, emaValue, lookback)
Detect divergence between price and EMA direction
Parameters:
price (float): Current price
emaValue (float): EMA value (typically EMA20)
lookback (int): Bars to compare
Returns: [divergence, priceChange%, emaChange%]
emaOrderStrength(e10, e20, e50, e100, e200)
Calculate EMA order strength (weighted by distance)
Parameters:
e10 (float): EMA 10
e20 (float): EMA 20
e50 (float): EMA 50
e100 (float): EMA 100
e200 (float): EMA 200
Returns: Strength score (higher = stronger trend)
emaPriceZone(price, e10, e20, e50, e100, e200)
Determine which EMA zone price is in
Parameters:
price (float): Current price
e10 (float): EMA 10
e20 (float): EMA 20
e50 (float): EMA 50
e100 (float): EMA 100
e200 (float): EMA 200
Returns: Zone code (5=above all, 0=below all, -1=mixed)
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
파인 라이브러리
트레이딩뷰의 진정한 정신에 따라, 작성자는 이 파인 코드를 오픈소스 라이브러리로 게시하여 커뮤니티의 다른 파인 프로그래머들이 재사용할 수 있도록 했습니다. 작성자에게 경의를 표합니다! 이 라이브러리는 개인적으로 사용하거나 다른 오픈소스 게시물에서 사용할 수 있지만, 이 코드의 게시물 내 재사용은 하우스 룰에 따라 규제됩니다.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.