PINE LIBRARY
מעודכן 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
הערות שחרור
v2הערות שחרור
v3ספריית Pine
ברוח האמיתית של TradingView, המחבר לפרסם את הקוד של Pine הזה כספרייה בקוד פתוח, כך שמתכנתים אחרים בקהילתנו יעשו שימוש חוזר. כל הכבוד למחבר! ניתן להשתמש בספרייה הזו באופן פרטי או בומים בקוד פתוח, אך השימוש בחוזר בקוד הזה בפרסומים כפוף ל-כללי הבית.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
ספריית Pine
ברוח האמיתית של TradingView, המחבר לפרסם את הקוד של Pine הזה כספרייה בקוד פתוח, כך שמתכנתים אחרים בקהילתנו יעשו שימוש חוזר. כל הכבוד למחבר! ניתן להשתמש בספרייה הזו באופן פרטי או בומים בקוד פתוח, אך השימוש בחוזר בקוד הזה בפרסומים כפוף ל-כללי הבית.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.