PINE LIBRARY
Zaktualizowano key_level_alerts_lib

Library "key_level_alerts_lib"
shouldFireAlertAbove(level, acceptableRange, filterEnabled)
Detects if price crossed above and closed above a level on this bar
Parameters:
level (float): The price level to check for cross
acceptableRange (float): The maximum distance from level for close to be considered valid (used when filterEnabled=true)
filterEnabled (bool): When true, checks that close is within acceptable range above level
Returns: true if price crossed and closed above the level (optionally within acceptable range)
Detection logic:
Condition A: Opened below level AND closed above level (direct cross up)
Condition B: Opened above level, low touched/dipped to level (low <= level), closed above level
shouldFireAlertBelow(level, acceptableRange, filterEnabled)
Detects if price crossed below and closed below a level on this bar
Parameters:
level (float): The price level to check for cross
acceptableRange (float): The maximum distance from level for close to be considered valid (used when filterEnabled=true)
filterEnabled (bool): When true, checks that close is within acceptable range below level
Returns: true if price crossed and closed below the level (optionally within acceptable range)
Detection logic:
Condition A: Opened above level AND closed below level (direct cross down)
Condition B: Opened below level, high touched/spiked to level (high >= level), closed below level
processAlertAbove(level, acceptableRange, currentState, alertEnabled, filterEnabled)
Process "crossed above" alert for a level - fires alert if transitioning from below/unknown to above
Parameters:
level (float): The price level to check
acceptableRange (float): The acceptable range threshold for filtering
currentState (int): Current alert state (-1=below, 0=unknown, 1=above)
alertEnabled (bool): Whether the alert is enabled
filterEnabled (bool): Whether to apply acceptable range filtering
Returns: [newState, shouldFire] tuple where newState is updated alert state and shouldFire indicates if alert should trigger
State behavior:
- Alert fires when: state was -1 or 0 AND cross above detected AND alert enabled
- State updates to 1 (above) on any cross above
- State updates to -1 (below) on any cross below (resets for next above alert)
processAlertBelow(level, acceptableRange, currentState, alertEnabled, filterEnabled)
Process "crossed below" alert for a level - fires alert if transitioning from above/unknown to below
Parameters:
level (float): The price level to check
acceptableRange (float): The acceptable range threshold for filtering
currentState (int): Current alert state (-1=below, 0=unknown, 1=above)
alertEnabled (bool): Whether the alert is enabled
filterEnabled (bool): Whether to apply acceptable range filtering
Returns: [newState, shouldFire] tuple where newState is updated alert state and shouldFire indicates if alert should trigger
State behavior:
- Alert fires when: state was 1 or 0 AND cross below detected AND alert enabled
- State updates to -1 (below) on any cross below
- State updates to 1 (above) on any cross above (resets for next below alert)
calculateAcceptableRange(atrValue, acceptableRangePct)
Calculates the acceptable range threshold for alert filtering based on ATR
Parameters:
atrValue (float): The daily ATR value
acceptableRangePct (float): The acceptable range percentage (e.g., 85 for 85%)
Returns: The acceptable range threshold in price units
Calculation: oneFullLevel = ATR × 0.24 (24% of daily ATR = one standard key level spacing)
acceptableRange = (acceptableRangePct / 100) × oneFullLevel
getAlertLabelTextSize(sizeStr)
Converts a size string to Pine Script size constant for labels
Parameters:
sizeStr (string): The size string ("tiny", "small", "normal", "large", "huge")
Returns: The corresponding Pine Script size constant
shouldFireAlertAbove(level, acceptableRange, filterEnabled)
Detects if price crossed above and closed above a level on this bar
Parameters:
level (float): The price level to check for cross
acceptableRange (float): The maximum distance from level for close to be considered valid (used when filterEnabled=true)
filterEnabled (bool): When true, checks that close is within acceptable range above level
Returns: true if price crossed and closed above the level (optionally within acceptable range)
Detection logic:
Condition A: Opened below level AND closed above level (direct cross up)
Condition B: Opened above level, low touched/dipped to level (low <= level), closed above level
shouldFireAlertBelow(level, acceptableRange, filterEnabled)
Detects if price crossed below and closed below a level on this bar
Parameters:
level (float): The price level to check for cross
acceptableRange (float): The maximum distance from level for close to be considered valid (used when filterEnabled=true)
filterEnabled (bool): When true, checks that close is within acceptable range below level
Returns: true if price crossed and closed below the level (optionally within acceptable range)
Detection logic:
Condition A: Opened above level AND closed below level (direct cross down)
Condition B: Opened below level, high touched/spiked to level (high >= level), closed below level
processAlertAbove(level, acceptableRange, currentState, alertEnabled, filterEnabled)
Process "crossed above" alert for a level - fires alert if transitioning from below/unknown to above
Parameters:
level (float): The price level to check
acceptableRange (float): The acceptable range threshold for filtering
currentState (int): Current alert state (-1=below, 0=unknown, 1=above)
alertEnabled (bool): Whether the alert is enabled
filterEnabled (bool): Whether to apply acceptable range filtering
Returns: [newState, shouldFire] tuple where newState is updated alert state and shouldFire indicates if alert should trigger
State behavior:
- Alert fires when: state was -1 or 0 AND cross above detected AND alert enabled
- State updates to 1 (above) on any cross above
- State updates to -1 (below) on any cross below (resets for next above alert)
processAlertBelow(level, acceptableRange, currentState, alertEnabled, filterEnabled)
Process "crossed below" alert for a level - fires alert if transitioning from above/unknown to below
Parameters:
level (float): The price level to check
acceptableRange (float): The acceptable range threshold for filtering
currentState (int): Current alert state (-1=below, 0=unknown, 1=above)
alertEnabled (bool): Whether the alert is enabled
filterEnabled (bool): Whether to apply acceptable range filtering
Returns: [newState, shouldFire] tuple where newState is updated alert state and shouldFire indicates if alert should trigger
State behavior:
- Alert fires when: state was 1 or 0 AND cross below detected AND alert enabled
- State updates to -1 (below) on any cross below
- State updates to 1 (above) on any cross above (resets for next below alert)
calculateAcceptableRange(atrValue, acceptableRangePct)
Calculates the acceptable range threshold for alert filtering based on ATR
Parameters:
atrValue (float): The daily ATR value
acceptableRangePct (float): The acceptable range percentage (e.g., 85 for 85%)
Returns: The acceptable range threshold in price units
Calculation: oneFullLevel = ATR × 0.24 (24% of daily ATR = one standard key level spacing)
acceptableRange = (acceptableRangePct / 100) × oneFullLevel
getAlertLabelTextSize(sizeStr)
Converts a size string to Pine Script size constant for labels
Parameters:
sizeStr (string): The size string ("tiny", "small", "normal", "large", "huge")
Returns: The corresponding Pine Script size constant
Informacje o Wersji
v2Informacje o Wersji
v3Biblioteka Pine
W zgodzie z duchem TradingView autor opublikował ten kod Pine jako bibliotekę open-source, aby inni programiści Pine z naszej społeczności mogli go ponownie wykorzystać. Ukłony dla autora. Można korzystać z tej biblioteki prywatnie lub w innych publikacjach open-source, jednak ponowne wykorzystanie tego kodu w publikacjach podlega Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Biblioteka Pine
W zgodzie z duchem TradingView autor opublikował ten kod Pine jako bibliotekę open-source, aby inni programiści Pine z naszej społeczności mogli go ponownie wykorzystać. Ukłony dla autora. Można korzystać z tej biblioteki prywatnie lub w innych publikacjach open-source, jednak ponowne wykorzystanie tego kodu w publikacjach podlega Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.