PINE LIBRARY
Cập nhật KeyLevels

Library "KeyLevels"
Library for common trading levels including VWAP, session levels (Asia, London, NYC, Comex IB), HTF OHLC, and Opening Ranges.
--- IMPLEMENTATION INSTRUCTIONS ---
1. Save this script as a Library named "KeyLevels".
2. In your indicator/strategy, import it: `import <YourUsername>/KeyLevels/1 as kl`
3. To get the data object, call: `levels = kl.getLevels()`
4. Access levels using dot notation: `levels.loH` (London High), `levels.nycH` (NYC High), `levels.cibH` (Comex IB High).
5. To get all levels in a single array for loops: `levelArray = kl.toArray(levels)`
--- TIMEZONE NOTE ---
The default timezone is "UTC-5" (New York). For accurate seasonal adjustments, use "America/New_York".
getLevels(vwapAnchor, vwapMult, rollingLen, htfAnchor, tz)
getLevels Calculates and returns a KeyLevelsData object with comprehensive trading levels.
Parameters:
vwapAnchor (string): Anchor condition for the main VWAP (e.g., "1D", "1W").
vwapMult (float): Standard deviation multiplier for VWAP bands.
rollingLen (int): Length for the rolling VWAP calculation.
htfAnchor (string): Anchor for the HTF VWAP (e.g., "1W", "1M").
tz (string): Timezone for session calculations (default: "UTC-5").
Returns: A `KeyLevelsData` object containing the levels.
toArray(data)
toArray Converts a KeyLevelsData object into a flat array of floats.
Parameters:
data (KeyLevelsData): The KeyLevelsData object to convert.
Returns: An array of floats containing all levels.
KeyLevelsData
KeyLevelsData Master structure to hold all calculated key levels (Flattened).
Fields:
vwapCenter (series float)
vwapUpper (series float)
vwapLower (series float)
htfVwapCenter (series float)
htfVwapUpper (series float)
htfVwapLower (series float)
rollingVwap (series float)
dailyOpen (series float)
asO (series float)
asH (series float)
asL (series float)
asC (series float)
loO (series float)
loH (series float)
loL (series float)
loC (series float)
nycO (series float)
nycH (series float)
nycL (series float)
nycC (series float)
cibO (series float)
cibH (series float)
cibL (series float)
cibC (series float)
ibO (series float)
ibH (series float)
ibL (series float)
ibC (series float)
ibMid (series float)
o5O (series float)
o5H (series float)
o5L (series float)
o5C (series float)
o15O (series float)
o15H (series float)
o15L (series float)
o15C (series float)
o30O (series float)
o30H (series float)
o30L (series float)
o30C (series float)
pdO (series float)
pdH (series float)
pdL (series float)
pdC (series float)
pwO (series float)
pwH (series float)
pwL (series float)
pwC (series float)
cwO (series float)
cwH (series float)
cwL (series float)
cwC (series float)
cmO (series float)
cmH (series float)
cmL (series float)
cmC (series float)
settlement (series float)
Library for common trading levels including VWAP, session levels (Asia, London, NYC, Comex IB), HTF OHLC, and Opening Ranges.
--- IMPLEMENTATION INSTRUCTIONS ---
1. Save this script as a Library named "KeyLevels".
2. In your indicator/strategy, import it: `import <YourUsername>/KeyLevels/1 as kl`
3. To get the data object, call: `levels = kl.getLevels()`
4. Access levels using dot notation: `levels.loH` (London High), `levels.nycH` (NYC High), `levels.cibH` (Comex IB High).
5. To get all levels in a single array for loops: `levelArray = kl.toArray(levels)`
--- TIMEZONE NOTE ---
The default timezone is "UTC-5" (New York). For accurate seasonal adjustments, use "America/New_York".
getLevels(vwapAnchor, vwapMult, rollingLen, htfAnchor, tz)
getLevels Calculates and returns a KeyLevelsData object with comprehensive trading levels.
Parameters:
vwapAnchor (string): Anchor condition for the main VWAP (e.g., "1D", "1W").
vwapMult (float): Standard deviation multiplier for VWAP bands.
rollingLen (int): Length for the rolling VWAP calculation.
htfAnchor (string): Anchor for the HTF VWAP (e.g., "1W", "1M").
tz (string): Timezone for session calculations (default: "UTC-5").
Returns: A `KeyLevelsData` object containing the levels.
toArray(data)
toArray Converts a KeyLevelsData object into a flat array of floats.
Parameters:
data (KeyLevelsData): The KeyLevelsData object to convert.
Returns: An array of floats containing all levels.
KeyLevelsData
KeyLevelsData Master structure to hold all calculated key levels (Flattened).
Fields:
vwapCenter (series float)
vwapUpper (series float)
vwapLower (series float)
htfVwapCenter (series float)
htfVwapUpper (series float)
htfVwapLower (series float)
rollingVwap (series float)
dailyOpen (series float)
asO (series float)
asH (series float)
asL (series float)
asC (series float)
loO (series float)
loH (series float)
loL (series float)
loC (series float)
nycO (series float)
nycH (series float)
nycL (series float)
nycC (series float)
cibO (series float)
cibH (series float)
cibL (series float)
cibC (series float)
ibO (series float)
ibH (series float)
ibL (series float)
ibC (series float)
ibMid (series float)
o5O (series float)
o5H (series float)
o5L (series float)
o5C (series float)
o15O (series float)
o15H (series float)
o15L (series float)
o15C (series float)
o30O (series float)
o30H (series float)
o30L (series float)
o30C (series float)
pdO (series float)
pdH (series float)
pdL (series float)
pdC (series float)
pwO (series float)
pwH (series float)
pwL (series float)
pwC (series float)
cwO (series float)
cwH (series float)
cwL (series float)
cwC (series float)
cmO (series float)
cmH (series float)
cmL (series float)
cmC (series float)
settlement (series float)
Phát hành các Ghi chú
updates Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Thư viện Pine
Theo đúng tinh thần TradingView, tác giả đã công bố mã Pine này như một thư viện mã nguồn mở để các lập trình viên Pine khác trong cộng đồng có thể tái sử dụng. Chúc mừng tác giả! Bạn có thể sử dụng thư viện này cho mục đích cá nhân hoặc trong các ấn phẩm mã nguồn mở khác, nhưng việc tái sử dụng mã này trong các ấn phẩm phải tuân theo Nội Quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.