EconomicCalendar

fstarcapital · library · 766 行 · 点赞 8 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © cephxs
// © fstarcapital
// Feed format and title IDs: © toodegrees, "Live Economic Calendar by toodegrees" (MPL 2.0).
 
//@version=6
 
// @description ForexFactory economic calendar for Pine (economicCalendar E1, E2). Decodes the toodegrees Pine Seeds feed into events, names them, grades them for energy, and finds the Driver Paired (DP) drivers of the chart.
library("EconomicCalendar")
 
// - - - - - - - - -
// SCOPE NOTES
//   • One library for the four toodegrees libraries (economicCalendar X1). The
//     donor files are in Redundant/.
//   • Data: the Pine Seeds feed `seed_toodegrees_toogit`, symbols
//     TOODEGREES_FOREX_FACTORY_SLOT_1 to _9. TradingView stopped new Pine Seeds
//     repositories, so this feed is the only live ForexFactory source in Pine.
//   • A library cannot hold the nine `request.seed` calls for the consumer.
//     Each consumer copies the block in SYSTEM.md and passes the strings to
//     `pull()`.
 
// - - - - - - - - -
// Types
 
// @type One ForexFactory event.
// @field t The event time, UNIX ms. An all-day event holds 00:00 New York.
// @field allDay True when the event has no time of day.
// @field cur The currency, for example "USD".
// @field impact 1 holiday, 2 low, 3 medium, 4 high. Graded for the chart market (E2).
// @field id The title ID of the toodegrees map. `title()` gives the name.
export type Event
    int    t
    bool   allDay
    string cur
    int    impact
    int    id
 
// - - - - - - - - -
// Titles
 
// @function The ForexFactory title of a title ID. The IDs are the toodegrees map: forex_factory_events_id_A (1 to 498) and forex_factory_events_id_B (499 to 610). When toodegrees adds an ID, add it here.
// @param id The title ID.
// @returns The title, or "Event <id>" for an ID that the map does not know.
export title(int id) =>
    switch id
        1   => "1-y Loan Prime Rate"
        2   => "10-y Bond Auction"
        3   => "30-y Bond Auction"
        4   => "5-y Loan Prime Rate"
        5   => "ADP Non-Farm Employment Change"
        6   => "AIG Construction Index"
        7   => "AIG Manufacturing Index"
        8   => "AIG Services Index"
        9   => "ANZ Business Confidence"
        10  => "ANZ Commodity Prices m/m"
        11  => "ANZ Job Advertisements m/m"
        12  => "Advance GDP Price Index q/q"
        13  => "Advance GDP q/q"
        14  => "All Industries Activity m/m"
        15  => "Annual Budget Release"
        16  => "Annual Pre-Budget Report"
        17  => "Asset Purchase Facility"
        18  => "Assist Treasury Sec Kashkari Speaks"
        19  => "Autumn Forecast Statement"
        20  => "Average Cash Earnings y/y"
        21  => "Average Earnings Index 3m/y"
        22  => "Average Hourly Earnings m/m"
        23  => "BOC Business Outlook Survey"
        24  => "BOC Financial System Review"
        25  => "BOC Gov Carney Speaks"
        26  => "BOC Gov Macklem Speaks"
        27  => "BOC Gov Poloz Speaks"
        28  => "BOC Monetary Policy Report"
        29  => "BOC Press Conference"
        30  => "BOC Rate Statement"
        31  => "BOC Review"
        32  => "BOC Summary of Deliberations"
        33  => "BOE Credit Conditions Survey"
        34  => "BOE Financial Stability Report"
        35  => "BOE Gov Bailey Speaks"
        36  => "BOE Gov Carney Speaks"
        37  => "BOE Gov King Speaks"
        38  => "BOE Inflation Letter"
        39  => "BOE Monetary Policy Report"
        40  => "BOE Quarterly Bulletin"
        41  => "BOJ Core CPI y/y"
        42  => "BOJ Gov Kuroda Speaks"
        43  => "BOJ Gov Shirakawa Speaks"
        44  => "BOJ Gov Ueda Speaks"
        45  => "BOJ Monthly Report"
        46  => "BOJ Outlook Report"
        47  => "BOJ Policy Rate"
        48  => "BOJ Press Conference"
        49  => "BOJ Summary of Opinions"
        50  => "BRC Retail Sales Monitor y/y"
        51  => "BRC Shop Price Index y/y"
        52  => "BRICS Summit"
        53  => "BSI Manufacturing Index"
        54  => "Bank Holiday"
        55  => "Bank Lending y/y"
        56  => "Bank Stress Test Results"
        57  => "Beige Book"
        58  => "Belgian NBB Business Climate"
        59  => "Building Approvals m/m"
        60  => "Building Consents m/m"
        61  => "Building Permits"
        62  => "Building Permits m/m"
        63  => "Business Inventories m/m"
        64  => "BusinessNZ Manufacturing Index"
        65  => "BusinessNZ Services Index"
        66  => "CB Consumer Confidence"
        67  => "CB Leading Index m/m"
        68  => "CBI Industrial Order Expectations"
        69  => "CBI Realized Sales"
        70  => "CPI Flash Estimate y/y"
        71  => "CPI m/m"
        72  => "CPI q/q"
        73  => "CPI y/y"
        74  => "Caixin Flash Manufacturing PMI"
        75  => "Caixin Manufacturing PMI"
        76  => "Caixin Services PMI"
        77  => "Capacity Utilization Rate"
        78  => "Capital Spending q/y"
        79  => "Cash Rate"
        80  => "Challenger Job Cuts y/y"
        81  => "Chancellor Darling Speaks"
        82  => "Chancellor Osborne Speaks"
        83  => "Chicago PMI"
        84  => "Claimant Count Change"
        85  => "Cleveland Fed Inflation Expectations"
        86  => "Commodity Prices y/y"
        87  => "Common CPI y/y"
        88  => "Company Operating Profits q/q"
        89  => "Congressional Elections"
        90  => "Construction Output m/m"
        91  => "Construction PMI"
        92  => "Construction Spending m/m"
        93  => "Construction Work Done q/q"
        94  => "Consumer Confidence"
        95  => "Consumer Credit m/m"
        96  => "Consumer Inflation Expectations"
        97  => "Core CPI Flash Estimate y/y"
        98  => "Core CPI m/m"
        99  => "Core CPI y/y"
        100 => "Core Durable Goods Orders m/m"
        101 => "Core Machinery Orders m/m"
        102 => "Core PCE Price Index m/m"
        103 => "Core PPI m/m"
        104 => "Core Retail Sales m/m"
        105 => "Core Retail Sales q/q"
        106 => "Corporate Profits q/q"
        107 => "Credit Card Spending y/y"
        108 => "Crude Oil Inventories"
        109 => "Current Account"
        110 => "Daylight Saving Time Shift"
        111 => "Doha Oil Summit"
        112 => "Durable Goods Orders m/m"
        113 => "Dutch Parliamentary Election"
        114 => "EBA Bank Stress Test Results"
        115 => "ECB Economic Bulletin"
        116 => "ECB Financial Stability Review"
        117 => "ECB Monetary Policy Meeting Accounts"
        118 => "ECB Monthly Bulletin"
        119 => "ECB President Draghi Speaks"
        120 => "ECB President Lagarde Speaks"
        121 => "ECB President Trichet Speaks"
        122 => "ECB Press Conference"
        123 => "ECOFIN Meetings"
        124 => "EU Economic Forecasts"
        125 => "EU Economic Summit"
        126 => "EU Membership Court Ruling"
        127 => "EU Membership Vote"
        128 => "Economic Stabilization Bill Vote"
        129 => "Economy Watchers Sentiment"
        130 => "Empire State Manufacturing Index"
        131 => "Employment Change"
        132 => "Employment Change q/q"
        133 => "Employment Cost Index q/q"
        134 => "Employment Level"
        135 => "Euro Summit"
        136 => "Eurogroup Meetings"
        137 => "European Court of Justice Ruling"
        138 => "European Parliamentary Elections"
        139 => "Existing Home Sales"
        140 => "FOMC Economic Projections"
        141 => "FOMC Financial Stability Report"
        142 => "FOMC Meeting Minutes"
        143 => "FOMC Member Barkin Speaks"
        144 => "FOMC Member Barr Speaks"
        145 => "FOMC Member Bostic Speaks"
        146 => "FOMC Member Bowman Speaks"
        147 => "FOMC Member Brainard Speaks"
        148 => "FOMC Member Bullard Speaks"
        149 => "FOMC Member Clarida Speaks"
        150 => "FOMC Member Collins Speaks"
        151 => "FOMC Member Cook Speaks"
        152 => "FOMC Member Daly Speaks"
        153 => "FOMC Member Dudley Speaks"
        154 => "FOMC Member Duke Speaks"
        155 => "FOMC Member Evans Speaks"
        156 => "FOMC Member Fischer Speaks"
        157 => "FOMC Member Fisher Speaks"
        158 => "FOMC Member Geithner Speaks"
        159 => "FOMC Member George Speaks"
        160 => "FOMC Member Goolsbee Speaks"
        161 => "FOMC Member Harker Speaks"
        162 => "FOMC Member Hoenig Speaks"
        163 => "FOMC Member Jefferson Speaks"
        164 => "FOMC Member Kaplan Speaks"
        165 => "FOMC Member Kashkari Speaks"
        166 => "FOMC Member Kocherlakota Speaks"
        167 => "FOMC Member Kohn Speaks"
        168 => "FOMC Member Kroszner Speaks"
        169 => "FOMC Member Kugler Speaks"
        170 => "FOMC Member Lacker Speaks"
        171 => "FOMC Member Lockhart Speaks"
        172 => "FOMC Member Logan Speaks"
        173 => "FOMC Member Mester Speaks"
        174 => "FOMC Member Mishkin Speaks"
        175 => "FOMC Member Musalem Speaks"
        176 => "FOMC Member Pianalto Speaks"
        177 => "FOMC Member Plosser Speaks"
        178 => "FOMC Member Powell Speaks"
        179 => "FOMC Member Quarles Speaks"
        180 => "FOMC Member Raskin Speaks"
        181 => "FOMC Member Rosengren Speaks"
        182 => "FOMC Member Stein Speaks"
        183 => "FOMC Member Stern Speaks"
        184 => "FOMC Member Tarullo Speaks"
        185 => "FOMC Member Waller Speaks"
        186 => "FOMC Member Warsh Speaks"
        187 => "FOMC Member Williams Speaks"
        188 => "FOMC Member Yellen Speaks"
        189 => "FOMC Press Conference"
        190 => "FOMC Statement"
        191 => "FPC Meeting Minutes"
        192 => "FPC Statement"
        193 => "FPI m/m"
        194 => "Factory Orders m/m"
        195 => "Fed Announcement"
        196 => "Fed Chair Powell Speaks"
        197 => "Fed Chair Powell Testifies"
        198 => "Fed Chair Yellen Speaks"
        199 => "Fed Chair Yellen Testifies"
        200 => "Fed Chairman Bernanke Speaks"
        201 => "Fed Chairman Bernanke Testifies"
        202 => "Fed Chairman Nomination Vote"
        203 => "Fed Gov Nomination Hearings"
        204 => "Fed Monetary Policy Report"
        205 => "Federal Budget Balance"
        206 => "Federal Election"
        207 => "Federal Funds Rate"
        208 => "Final CPI y/y"
        209 => "Final Core CPI y/y"
        210 => "Final Employment Change q/q"
        211 => "Final GDP Price Index q/q"
        212 => "Final GDP Price Index y/y"
        213 => "Final GDP q/q"
        214 => "Final Manufacturing PMI"
        215 => "Final Services PMI"
        216 => "Final Wholesale Inventories m/m"
        217 => "Fixed Asset Investment ytd/y"
        218 => "Flash Employment Change q/q"
        219 => "Flash GDP q/q"
        220 => "Flash Manufacturing PMI"
        221 => "Flash Services PMI"
        222 => "Foreign Currency Reserves"
        223 => "Foreign Direct Investment ytd/y"
        224 => "Foreign Securities Purchases"
        225 => "French 10-y Bond Auction"
        226 => "French Bank Holiday"
        227 => "French Consumer Spending m/m"
        228 => "French Final CPI m/m"
        229 => "French Final Manufacturing PMI"
        230 => "French Final Private Payrolls q/q"
        231 => "French Final Services PMI"
        232 => "French Flash GDP q/q"
        233 => "French Flash Manufacturing PMI"
        234 => "French Flash Services PMI"
        235 => "French Gov Budget Balance"
        236 => "French Industrial Production m/m"
        237 => "French Parliamentary Elections"
        238 => "French Prelim CPI m/m"
        239 => "French Prelim GDP q/q"
        240 => "French Prelim Private Payrolls q/q"
        241 => "French Presidential Election"
        242 => "French Trade Balance"
        243 => "G20 Meetings"
        244 => "G7 Meetings"
        245 => "G8 Meetings"
        246 => "GDP m/m"
        247 => "GDP q/q"
        248 => "GDP q/y"
        249 => "GDT Price Index"
        250 => "German 10-y Bond Auction"
        251 => "German 30-y Bond Auction"
        252 => "German Bank Holiday"
        253 => "German Buba Monthly Report"
        254 => "German Buba President Nagel Speaks"
        255 => "German Buba President Weber Speaks"
        256 => "German Buba President Weidmann Speaks"
        257 => "German Constitutional Court Ruling"
        258 => "German Factory Orders m/m"
        259 => "German Federal Elections"
        260 => "German Final CPI m/m"
        261 => "German Final GDP q/q"
        262 => "German Final Manufacturing PMI"
        263 => "German Final Services PMI"
        264 => "German Flash Manufacturing PMI"
        265 => "German Flash Services PMI"
        266 => "German GfK Consumer Climate"
        267 => "German Import Prices m/m"
        268 => "German Industrial Production m/m"
        269 => "German PPI m/m"
        270 => "German Prelim CPI m/m"
        271 => "German Prelim GDP q/q"
        272 => "German Retail Sales m/m"
        273 => "German Trade Balance"
        274 => "German Unemployment Change"
        275 => "German WPI m/m"
        276 => "German ZEW Economic Sentiment"
        277 => "German ifo Business Climate"
        278 => "GfK Consumer Confidence"
        279 => "Goods Trade Balance"
        280 => "Gov Board Member Danthine Speaks"
        281 => "Gov Board Member Hildebrand Speaks"
        282 => "Gov Board Member Jordan Speaks"
        283 => "Gov Board Member Maechler Speaks"
        284 => "Gov Board Member Martin Speaks"
        285 => "Gov Board Member Schlegel Speaks"
        286 => "Gov Board Member Zurbrugg Speaks"
        287 => "Gov Council Member Beaudry Speaks"
        288 => "Gov Council Member Boivin Speaks"
        289 => "Gov Council Member Cote Speaks"
        290 => "Gov Council Member Duguay Speaks"
        291 => "Gov Council Member Gravelle Speaks"
        292 => "Gov Council Member Jenkins Speaks"
        293 => "Gov Council Member Kennedy Speaks"
        294 => "Gov Council Member Kozicki Speaks"
        295 => "Gov Council Member Lane Speaks"
        296 => "Gov Council Member Leduc Speaks"
        297 => "Gov Council Member Longworth Speaks"
        298 => "Gov Council Member Macklem Speaks"
        299 => "Gov Council Member Mendes Speaks"
        300 => "Gov Council Member Murray Speaks"
        301 => "Gov Council Member Patterson Speaks"
        302 => "Gov Council Member Rogers Speaks"
        303 => "Gov Council Member Schembri Speaks"
        304 => "Gov Council Member Vincent Speaks"
        305 => "Gov Council Member Wilkins Speaks"
        306 => "Government Spending Review"
        307 => "Govt Confidence Vote"
        308 => "Greek Bailout Vote"
        309 => "Greek Gov Debt Crisis Vote"
        310 => "Greek Parliamentary Election"
        311 => "Greek Presidential Elections"
        312 => "HIA New Home Sales m/m"
        313 => "HPI m/m"
        314 => "HPI q/q"
        315 => "HPI y/y"
        316 => "Halifax HPI m/m"
        317 => "High Street Lending"
        318 => "Home Loans m/m"
        319 => "Household Spending y/y"
        320 => "Housing Equity Withdrawal q/q"
        321 => "Housing Starts"
        322 => "Housing Starts q/q"
        323 => "Housing Starts y/y"
        324 => "IMF Meetings"
        325 => "IPPI m/m"
        326 => "ISM Manufacturing PMI"
        327 => "ISM Manufacturing Prices"
        328 => "ISM Services PMI"
        329 => "Import Prices m/m"
        330 => "Import Prices q/q"
        331 => "Index of Services 3m/3m"
        332 => "Industrial New Orders m/m"
        333 => "Industrial Production m/m"
        334 => "Industrial Production q/q"
        335 => "Industrial Production y/y"
        336 => "Inflation Expectations q/q"
        337 => "Irish Lisbon Treaty Vote"
        338 => "Irish Stability Treaty Vote"
        339 => "Italian 10-y Bond Auction"
        340 => "Italian Bank Holiday"
        341 => "Italian Constitution Amendment Vote"
        342 => "Italian Industrial Production m/m"
        343 => "Italian Manufacturing PMI"
        344 => "Italian Monthly Unemployment Rate"
        345 => "Italian Parliamentary Election"
        346 => "Italian Prelim CPI m/m"
        347 => "Italian Prelim GDP q/q"
        348 => "Italian Quarterly Unemployment Rate"
        349 => "Italian Retail Sales m/m"
        350 => "Italian Services PMI"
        351 => "Italian Trade Balance"
        352 => "Ivey PMI"
        353 => "JOLTS Job Openings"
        354 => "Jackson Hole Symposium"
        355 => "Jeddah Oil Summit"
        356 => "KOF Economic Barometer"
        357 => "Labor Cost Index q/q"
        358 => "Labor Market Conditions Index m/m"
        359 => "Labor Productivity q/q"
        360 => "Leading Index m/m"
        361 => "Leading Indicators"
        362 => "Libor Rate"
        363 => "Loan Officer Survey"
        364 => "Long Term Refinancing Operation"
        365 => "Lower House Elections"
        366 => "M2 Money Stock y/y"
        367 => "M2 Money Supply y/y"
        368 => "M3 Money Supply y/y"
        369 => "M4 Money Supply m/m"
        370 => "MI Inflation Expectations"
        371 => "MI Inflation Gauge m/m"
        372 => "MI Leading Index m/m"
        373 => "MPC Asset Purchase Facility Votes"
        374 => "MPC Member Barker Speaks"
        375 => "MPC Member Bean Speaks"
        376 => "MPC Member Besley Speaks"
        377 => "MPC Member Blanchflower Speaks"
        378 => "MPC Member Breeden Speaks"
        379 => "MPC Member Broadbent Speaks"
        380 => "MPC Member Cunliffe Speaks"
        381 => "MPC Member Dale Speaks"
        382 => "MPC Member Dhingra Speaks"
        383 => "MPC Member Fisher Speaks"
        384 => "MPC Member Forbes Speaks"
        385 => "MPC Member Gieve Speaks"
        386 => "MPC Member Greene Speaks"
        387 => "MPC Member Haldane Speaks"
        388 => "MPC Member Haskel Speaks"
        389 => "MPC Member Hogg Speaks"
        390 => "MPC Member Mann Speaks"
        391 => "MPC Member McCafferty Speaks"
        392 => "MPC Member Miles Speaks"
        393 => "MPC Member Pill Speaks"
        394 => "MPC Member Posen Speaks"
        395 => "MPC Member Ramsden Speaks"
        396 => "MPC Member Saunders Speaks"
        397 => "MPC Member Sentance Speaks"
        398 => "MPC Member Shafik Speaks"
        399 => "MPC Member Tenreyro Speaks"
        400 => "MPC Member Tucker Speaks"
        401 => "MPC Member Vlieghe Speaks"
        402 => "MPC Member Weale Speaks"
        403 => "MPC Official Bank Rate Votes"
        404 => "MPC Rate Statement"
        405 => "Main Refinancing Rate"
        406 => "Manufacturing PMI"
        407 => "Manufacturing Production m/m"
        408 => "Manufacturing Sales m/m"
        409 => "Manufacturing Sales q/q"
        410 => "Median CPI y/y"
        411 => "Mid-Year Economic and Fiscal Outlook"
        412 => "Monetary Base y/y"
        413 => "Monetary Policy Meeting Minutes"
        414 => "Monetary Policy Report Hearings"
        415 => "Monetary Policy Statement"
        416 => "Monetary Policy Summary"
        417 => "Mortgage Approvals"
        418 => "Mortgage Delinquencies"
        419 => "NAB Business Confidence"
        420 => "NAB Quarterly Business Confidence"
        421 => "NAHB Housing Market Index"
        422 => "NBS Press Conference"
        423 => "NFIB Small Business Index"
        424 => "NHPI m/m"
        425 => "NIESR GDP Estimate"
        426 => "NZIER Business Confidence"
        427 => "National Core CPI y/y"
        428 => "Nationwide Consumer Confidence"
        429 => "Nationwide HPI m/m"
        430 => "Natural Gas Storage"
        431 => "Net Lending to Individuals m/m"
        432 => "New Home Prices m/m"
        433 => "New Home Sales"
        434 => "New Loans"
        435 => "New Motor Vehicle Sales m/m"
        436 => "Non-Farm Employment Change"
        437 => "Non-Manufacturing PMI"
        438 => "ONS HPI y/y"
        439 => "OPEC Meetings"
        440 => "OPEC-JMMC Meetings"
        441 => "Official Bank Rate"
        442 => "Official Cash Rate"
        443 => "Overnight Call Rate"
        444 => "Overnight Rate"
        445 => "Overseas Trade Index q/q"
        446 => "PPI Input m/m"
        447 => "PPI Input q/q"
        448 => "PPI Output m/m"
        449 => "PPI Output q/q"
        450 => "PPI m/m"
        451 => "PPI q/q"
        452 => "PPI y/y"
        453 => "Parliament Brexit Vote"
        454 => "Parliamentary Elections"
        455 => "Pending Home Sales m/m"
        456 => "Personal Income m/m"
        457 => "Personal Spending m/m"
        458 => "Philly Fed Manufacturing Index"
        459 => "Prelim ANZ Business Confidence"
        460 => "Prelim Business Investment q/q"
        461 => "Prelim Flash GDP q/q"
        462 => "Prelim GDP Price Index q/q"
        463 => "Prelim GDP Price Index y/y"
        464 => "Prelim GDP q/q"
        465 => "Prelim Industrial Production m/m"
        466 => "Prelim Machine Tool Orders y/y"
        467 => "Prelim Mortgage Approvals"
        468 => "Prelim Nonfarm Productivity q/q"
        469 => "Prelim Unit Labor Costs q/q"
        470 => "Prelim UoM Consumer Sentiment"
        471 => "Prelim UoM Inflation Expectations"
        472 => "Prelim Wholesale Inventories m/m"
        473 => "President Biden Speaks"
        474 => "President Bush Speaks"
        475 => "President Obama Speaks"
        476 => "President Trump Speaks"
        477 => "Presidential Election"
        478 => "Prime Minister Johnson Speaks"
        479 => "Prime Minister May Speaks"
        480 => "Prime Minister Truss Speaks"
        481 => "Private Capital Expenditure q/q"
        482 => "Private Loans y/y"
        483 => "Private Sector Credit m/m"
        484 => "Public Sector Net Borrowing"
        485 => "Quarterly Retail Sales q/q"
        486 => "RBA Annual Report"
        487 => "RBA Assist Gov Edey Speaks"
        488 => "RBA Assist Gov Ellis Speaks"
        489 => "RBA Assist Gov Hunter Speaks"
        490 => "RBA Assist Gov Kent Speaks"
        491 => "RBA Bulletin"
        492 => "RBA Deputy Gov Battellino Speaks"
        493 => "RBA Deputy Gov Debelle Speaks"
        494 => "RBA Deputy Gov Hauser Speaks"
        495 => "RBA Deputy Gov Lowe Speaks"
        496 => "RBA Financial Stability Review"
        497 => "RBA Gov Bullock Speaks"
        498 => "RBA Gov Lowe Speaks"
        499 => "RBA Gov Stevens Speaks"
        500 => "RBA Monetary Policy Statement"
        501 => "RBA Press Conference"
        502 => "RBA Rate Statement"
        503 => "RBNZ Assist Gov McDermott Speaks"
        504 => "RBNZ Financial Stability Report"
        505 => "RBNZ Gov Bollard Speaks"
        506 => "RBNZ Gov Orr Speaks"
        507 => "RBNZ Gov Spencer Speaks"
        508 => "RBNZ Gov Wheeler Speaks"
        509 => "RBNZ Monetary Policy Statement"
        510 => "RBNZ Press Conference"
        511 => "RBNZ Rate Statement"
        512 => "RBNZ Statement of Intent"
        513 => "RCM/TIPP Economic Optimism"
        514 => "REINZ HPI m/m"
        515 => "RICS House Price Balance"
        516 => "RMPI m/m"
        517 => "RPI y/y"
        518 => "Retail PMI"
        519 => "Retail Sales m/m"
        520 => "Retail Sales q/q"
        521 => "Retail Sales y/y"
        522 => "Revised Business Investment q/q"
        523 => "Revised GDP q/q"
        524 => "Revised Industrial Production m/m"
        525 => "Revised Nonfarm Productivity q/q"
        526 => "Revised Unit Labor Costs q/q"
        527 => "Revised UoM Consumer Sentiment"
        528 => "Revised UoM Inflation Expectations"
        529 => "Richmond Manufacturing Index"
        530 => "Rightmove HPI m/m"
        531 => "S&P/CS Composite-20 HPI y/y"
        532 => "SECO Consumer Climate"
        533 => "SECO Economic Forecasts"
        534 => "SNB Chairman Hildebrand Speaks"
        535 => "SNB Chairman Jordan Speaks"
        536 => "SNB Chairman Roth Speaks"
        537 => "SNB Financial Stability Report"
        538 => "SNB Monetary Policy Assessment"
        539 => "SNB Policy Rate"
        540 => "SNB Press Conference"
        541 => "SNB Quarterly Bulletin"
        542 => "SPPI y/y"
        543 => "Second Estimate GDP q/q"
        544 => "Sentix Investor Confidence"
        545 => "Spanish 10-y Bond Auction"
        546 => "Spanish Flash CPI y/y"
        547 => "Spanish Flash GDP q/q"
        548 => "Spanish Manufacturing PMI"
        549 => "Spanish Parliamentary Election"
        550 => "Spanish Services PMI"
        551 => "Spanish Unemployment Change"
        552 => "Spanish Unemployment Rate"
        553 => "Stimulus Package Announcement"
        554 => "TIC Long-Term Purchases"
        555 => "Tankan Manufacturing Index"
        556 => "Tankan Non-Manufacturing Index"
        557 => "Tertiary Industry Activity m/m"
        558 => "Tokyo Core CPI y/y"
        559 => "Total Vehicle Sales"
        560 => "Trade Balance"
        561 => "Treasury Currency Report"
        562 => "Treasury Sec Geithner Speaks"
        563 => "Treasury Sec Lew Speaks"
        564 => "Treasury Sec Mnuchin Speaks"
        565 => "Treasury Sec Paulson Speaks"
        566 => "Treasury Sec Yellen Speaks"
        567 => "Trimmed CPI y/y"
        568 => "Trimmed Mean CPI q/q"
        569 => "UBS Consumption Indicator"
        570 => "UBS Economic Expectations"
        571 => "USD-Denominated Trade Balance"
        572 => "Unconditional Basic Income Vote"
        573 => "Unemployment Claims"
        574 => "Unemployment Rate"
        575 => "Upper House Elections"
        576 => "Visitor Arrivals m/m"
        577 => "WEF Annual Meetings"
        578 => "Wage Price Index q/q"
        579 => "Wards Total Vehicle Sales"
        580 => "Westpac Consumer Sentiment"
        581 => "Wholesale Sales m/m"
        582 => "ZEW Economic Sentiment"
        583 => "FOMC Member Hammack Speaks"
        584 => "SNB Chairman Schlegel Speaks"
        585 => "FOMC Member Schmid Speaks"
        586 => "Gov Board Member Tschudin Speaks"
        587 => "MPC Member Lombardelli Speaks"
        588 => "MPC Member Taylor Speaks"
        589 => "API Weekly Statistical Bulletin"
        590 => "RBNZ Gov Hawkesby Speaks"
        591 => "RatingDog Manufacturing PMI"
        592 => "RatingDog Services PMI"
        593 => "RBA Assist Gov Jones Speaks"
        594 => "FOMC Member Miran Speaks"
        595 => "Household Spending m/m"
        596 => "FOMC Member Paulson Speaks"
        597 => "Summary of Monetary Policy Discussions"
        599 => "RBNZ Gov Breman Speaks"
        600 => "ADP Weekly Employment Change"
        601 => "Trimmed Mean CPI m/m"
        602 => "Fed Chair-Designate Warsh Testifies"
        603 => "Fed Chair-Designate Warsh Testifies"
        604 => "Gov Council Member Alexopoulos Speaks"
        605 => "Treasury Sec Bessent Speaks"
        606 => "Fed Chairman Warsh Testifies"
        607 => "Omdia Total Vehicle Sales"
        608 => "Lloyds HPI m/m"
        609 => "Fed Chairman Warsh Speaks"
        610 => "Prelim Benchmark Payrolls Revision"
        => "Event " + str.tostring(id)
 
// - - - - - - - - -
// Feed
 
// @function The request expression of one feed slot. It sends the last 8 daily rows, newest first, as "time,open,high,low,close,volume;" per row. 8 rows reach one week back, so a short chart history still gets the current week.
// @returns The rows of one slot as one string.
export feedRows() =>
    string rows = ""
    for k = 0 to 7
        rows += str.tostring(time[k]) + "," + str.tostring(open[k], "#") + "," + str.tostring(high[k], "#") + "," + str.tostring(low[k], "#") + "," + str.tostring(close[k], "#") + "," + str.tostring(volume[k], "#") + ";"
    rows
 
// @function The market of the chart symbol, for the event grades (E2). Metals keep the ForexFactory grade, so they read as forex.
// @returns "energy" or "forex".
export marketOf() =>
    array.from("CL", "MCL", "QM", "NG", "QG", "MNG", "RB", "HO", "BZ", "USOIL", "UKOIL", "WTI", "BRENT", "NATGAS", "XTIUSD", "XBRUSD", "XNGUSD").includes(syminfo.root) ? "energy" : "forex"
 
// @function The currencies of the chart: the base and the quote currency. A duplicate or a blank one matches no event.
// @returns For example ["EUR", "USD"] on EURUSD.
export chartCurrencies() =>
    array.from(syminfo.basecurrency, syminfo.currency)
 
// Decodes one feed value "DCHHMMI%T" (SYSTEM.md section 1). 999 is empty. The
// event date is the row date + 7 days, and the day digit corrects one day in
// each direction. Returns na for an empty or a bad value.
decode(int code, int rowTime, string market) =>
    Event e = na
    if not na(code) and code != 999 and not na(rowTime)
        string s = str.tostring(code)
        if str.length(s) >= 8
            int dow  = int(str.tonumber(str.substring(s, 0, 1)))
            int cIdx = int(str.tonumber(str.substring(s, 1, 2)))
            string hhmm = str.substring(s, 2, 6)
            int imp  = int(str.tonumber(str.substring(s, 6, 7)))
            int id   = int(str.tonumber(str.substring(s, 7)))
            // Three days in a row have three different day digits, so one k matches at most.
            int day = na
            for k = 6 to 8
                int d = rowTime + k * 86400000
                if na(day) and dayofweek(d, "UTC") == dow
                    day := d
            if not na(day) and cIdx >= 1 and cIdx <= 9 and imp >= 1 and imp <= 4
                bool allDay = hhmm == "9999"
                int hh = allDay ? 0 : int(str.tonumber(str.substring(hhmm, 0, 2)))
                int mm = allDay ? 0 : int(str.tonumber(str.substring(hhmm, 2, 4)))
                int t = timestamp("America/New_York", year(day, "UTC"), month(day, "UTC"), dayofmonth(day, "UTC"), hh, mm, 0)
                string cur = array.from("AUD", "CAD", "CHF", "CNY", "EUR", "GBP", "JPY", "NZD", "USD").get(cIdx - 1)
                // E2: on energy, Crude Oil Inventories (108) and Natural Gas Storage (430) are high, as Energy EXCH grades them.
                e := Event.new(t, allDay, cur, market == "energy" and (id == 108 or id == 430) ? 4 : imp, id)
    e
 
// @function Decodes the new rows of one feed slot into an event book. The script reads a row only once: `seen` holds the rows that it read before, by row time and slot.
// @param book The event book of the script. New events go to its end.
// @param seen The rows read before. Keep one map for all nine slots.
// @param rows The slot string from `request.seed(..., feedRows())`.
// @param slot The slot number, 1 to 9.
// @param market The chart market, from `marketOf()`.
// @param curs The currencies to keep. An empty array keeps all.
// @param minImpact The lowest impact to keep, 1 to 4.
// @returns The number of new events.
export method pull(array<Event> book, map<int, bool> seen, string rows, int slot, string market, array<string> curs, int minImpact) =>
    int added = 0
    int p = na(rows) ? na : str.pos(rows, ",")
    float head = na(p) ? na : str.tonumber(str.substring(rows, 0, p))
    // The newest row comes first. When the script read it, it read the older rows too.
    if not na(head) and not seen.contains(int(head) + slot)
        for row in str.split(rows, ";")
            array<string> f = str.split(row, ",")
            if f.size() == 6
                float rt = str.tonumber(f.get(0))
                if not na(rt) and not seen.contains(int(rt) + slot)
                    seen.put(int(rt) + slot, true)
                    for j = 1 to 5
                        float v = str.tonumber(f.get(j))
                        Event e = decode(na(v) ? na : int(v), int(rt), market)
                        if not na(e) and e.impact >= minImpact and (curs.size() == 0 or curs.includes(e.cur))
                            book.push(e)
                            added += 1
    added
 
// @function Removes the events before a time from an event book.
// @param book The event book.
// @param before UNIX ms. The events before this time go.
// @returns The book.
export method prune(array<Event> book, int before) =>
    if book.size() > 0
        for i = book.size() - 1 to 0
            if book.get(i).t < before
                book.remove(i)
    book
 
// - - - - - - - - -
// Drivers (feed-worker CONTRACT.md, DP)
 
// @function The DP driver at a time (feed-worker DP rule). First the 9:30 NY open: 9:30 to 10:00 NY, Monday to Friday, on NQ, ES, YM, RTY and their micros (protected-swings E8). Else a high-impact event of a chart currency, from its time to 30 minutes after it. An all-day event does not count.
// @param book The event book.
// @param t The bar open time, UNIX ms.
// @param curs The currencies of the chart, from `chartCurrencies()`.
// @returns The driver name, for example "09:30 NY open" or "08:30 USD CPI m/m", or "" when there is none.
export method driverAt(array<Event> book, int t, array<string> curs) =>
    // ponytail: market holidays count as open days, as in the worker.
    bool index = syminfo.type == "futures" and array.from("NQ", "ES", "YM", "RTY", "MNQ", "MES", "MYM", "M2K").includes(syminfo.root)
    int m = hour(t, "America/New_York") * 60 + minute(t, "America/New_York")
    int d = dayofweek(t, "America/New_York")
    string why = index and d != dayofweek.saturday and d != dayofweek.sunday and m >= 570 and m < 600 ? "09:30 NY open" : ""
    if why == ""
        for e in book
            if e.impact == 4 and not e.allDay and t >= e.t and t < e.t + 1800000 and curs.includes(e.cur)
                why := str.format_time(e.t, "HH:mm", "America/New_York") + " " + e.cur + " " + title(e.id)
                break
    why

← 返回列表