本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Tipo de apertura", shorttitle = "Tipo apertura", overlay = true, max_labels_count = 100, max_boxes_count = 100)
// Open type of the regular session, classified on the data of THIS chart with the same mechanical rules as our open
// type table, and what the same session did afterwards after that open type in this market since 2022, against all
// sessions of the market in the same period.
//
// The rules (the first 30 minutes of the regular session, period A):
// R = the median range (high - low) of the 20 previous sessions, known before the open. O = the first price.
// Tolerance = 0.05 R, never less than one tick. Drive = 0.20 R.
// Open-Drive: the near side stays within the tolerance of O, the far side travels at least the drive and minute 30
// closes at least half of that excursion away from O.
// Open-Test-Drive: the near side printed first and travelled more than the tolerance but at most the drive (a short
// test), the far side travels at least the drive and minute 30 closes at least half of that excursion away.
// Open-Rejection-Reverse: both sides travel more than the tolerance, the side that printed first is not the side
// where minute 30 closes, and that close sits more than the tolerance away from O.
// Open-Auction: everything else, split by whether O sat inside the prior session's high-low range.
// Fewer than 10 traded minutes in the window, or fewer than 20 previous sessions: no label.
// The label never says which way the move went: no colour, arrow or side is drawn, and none is stored.
//
// The table: for today's open type (or the one chosen), what the same session did afterwards since 2022 (range above
// its recent median, initial balance traded beyond on one side only or on both, close inside the prior value area,
// session high or low in the first or in the last hour), each with its n, its 95% interval and the value over all
// sessions. A cell whose interval holds the all-sessions value, or that does not pass the false-discovery control of
// its table, reads "igual al azar". Size, frequency, location and time only: not a signal.
//
// Data: 1-minute bars as our table (the chart's own on a 1-minute chart, 1-minute intrabars otherwise). R, the prior
// range and the prior value area come from a fixed 15-minute view of the chart's symbol. A continuous chart's contract
// changes are not adjusted, so the first session after a roll can read differently from our table.
// --- BEGIN GENERATED CONSTANTS
// Written by scripts/build_tradingview_constants.py. Do not edit by hand.
// 29 markets, sessions through 2026-10-16. Rates, intervals, counts and session hours only.
string DATA_THROUGH = "2026-10-16"
f_parent(string r) =>
switch r
"MES" => "ES"
"MNQ" => "NQ"
"M2K" => "RTY"
"MYM" => "YM"
"MGC" => "GC"
"SIL" => "SI"
"MHG" => "HG"
"MCL" => "CL"
"QM" => "CL"
"MNG" => "NG"
"QG" => "NG"
"MBT" => "BTC"
"MET" => "ETH"
"M6E" => "6E"
"M6A" => "6A"
"M6B" => "6B"
"E7" => "6E"
"J7" => "6J"
"XC" => "ZC"
"XK" => "ZS"
"XW" => "ZW"
"10Y" => "ZN"
"MTN" => "ZN"
"MWN" => "ZB"
=> r
f_lvSess(string r) =>
switch r
"NKD" => "0900-1515"
=> "0930-1600"
f_lvTz(string r) =>
switch r
"NKD" => "Asia/Tokyo"
=> "America/New_York"
f_ownSess(string r) =>
switch r
"6A" => "0820-1500"
"6B" => "0820-1500"
"6C" => "0820-1500"
"6E" => "0820-1500"
"6J" => "0820-1500"
"6M" => "0820-1500"
"6N" => "0820-1500"
"6S" => "0820-1500"
"CL" => "0900-1430"
"GC" => "0820-1330"
"HG" => "0810-1300"
"NG" => "0900-1430"
"NKD" => "0900-1515"
"PA" => "0830-1300"
"PL" => "0820-1305"
"SI" => "0820-1330"
"ZB" => "0820-1500"
"ZC" => "0930-1420"
"ZF" => "0820-1500"
"ZN" => "0820-1500"
"ZS" => "0930-1420"
"ZT" => "0820-1500"
"ZW" => "0930-1420"
=> "0930-1600"
f_ownTz(string r) =>
switch r
"NKD" => "Asia/Tokyo"
=> "America/New_York"
f_ot(string r) =>
switch r
"6A" => "OT1|6A|S|2022-01-03|2026-10-16|1239|30|1239,49.6;1239,70.1;1239,25.1;1239,16.9;1239,74.9;1239,27.3|288,57.6,51.9,63.2,D;288,68.4,62.8,73.5,S;288,26.4,21.6,31.8,S;288,15.6,11.9,20.3,S;288,73.6,68.2,78.4,S;288,25.7,21,31,S|266,52.3,46.3,58.2,S;266,70.3,64.6,75.5,S;266,22.2,17.6,27.5,S;266,17.3,13.2,22.3,S;266,77.8,72.5,82.4,S;266,29.3,24.2,35.1,S|276,55.8,49.9,61.5,U;276,72.8,67.3,77.7,S;276,23.2,18.6,28.5,S;276,18.8,14.7,23.9,S;276,76.8,71.5,81.4,S;276,28.3,23.3,33.8,S|168,42.9,35.6,50.4,S;168,71.4,64.2,77.7,S;168,25.6,19.6,32.7,S;168,31,24.5,38.3,D;168,74.4,67.3,80.4,S;168,26.2,20.1,33.3,S|241,34.9,29.1,41.1,D;241,67.6,61.5,73.2,S;241,28.6,23.3,34.6,S;241,6.2,3.8,10,D;241,71.4,65.4,76.7,S;241,26.6,21.4,32.5,S"
"6B" => "OT1|6B|S|2022-01-03|2026-10-16|1239|30|1239,49;1239,71.6;1239,23.6;1239,19.1;1239,76.4;1239,23.9|253,53.4,47.2,59.4,S;253,72.3,66.5,77.5,S;253,22.5,17.8,28.1,S;253,18.2,13.9,23.4,S;253,77.5,71.9,82.2,S;253,25.7,20.7,31.4,S|282,58.5,52.7,64.1,D;282,75.9,70.6,80.5,S;282,17.7,13.7,22.6,D;282,16.7,12.8,21.5,S;282,82.3,77.4,86.3,D;282,23.4,18.8,28.7,S|305,48.2,42.6,53.8,S;305,70.8,65.5,75.6,S;305,24.9,20.4,30.1,S;305,18,14.1,22.7,S;305,75.1,69.9,79.6,S;305,23,18.6,28,S|194,39.7,33.1,46.7,D;194,65.5,58.5,71.8,S;194,30.4,24.4,37.2,D;194,35.6,29.2,42.5,D;194,69.6,62.8,75.6,D;194,24.2,18.7,30.7,S|205,40.5,34,47.3,D;205,71.7,65.2,77.4,S;205,24.9,19.5,31.2,S;205,9.8,6.4,14.6,D;205,75.1,68.8,80.5,S;205,23.4,18.1,29.7,S"
"6C" => "OT1|6C|S|2022-01-03|2026-10-16|1239|30|1239,49.2;1239,73;1239,22;1239,19.9;1239,78;1239,29.7|302,51.7,46,57.2,S;302,77.5,72.4,81.8,S;302,19.2,15.2,24,S;302,17.9,14,22.6,S;302,80.8,76,84.8,S;302,28.5,23.7,33.8,S|278,54,48.1,59.7,S;278,73,67.5,77.9,S;278,19.4,15.2,24.5,S;278,23,18.5,28.3,S;278,80.6,75.5,84.8,S;278,28.4,23.4,34,S|296,51.4,45.7,57,S;296,71.6,66.2,76.5,S;296,23,18.5,28.1,S;296,17.6,13.7,22.3,S;296,77,71.9,81.5,S;296,28,23.2,33.4,S|187,42.2,35.4,49.4,S;187,71.1,64.3,77.1,S;187,25.7,19.9,32.4,S;187,30.5,24.3,37.4,D;187,74.3,67.6,80.1,S;187,33.2,26.8,40.2,S|176,41.5,34.5,48.9,U;176,69.9,62.7,76.2,S;176,25,19.2,31.9,S;176,10.8,7,16.2,D;176,75,68.1,80.8,S;176,33,26.4,40.2,S"
"6E" => "OT1|6E|S|2022-01-03|2026-10-16|1239|30|1239,49.7;1239,70.6;1239,23.9;1239,19.5;1239,76.1;1239,24.1|239,54.4,48.1,60.6,S;239,72.4,66.4,77.7,S;239,20.5,15.9,26.1,S;239,16.3,12.2,21.5,S;239,79.5,73.9,84.1,S;239,25.9,20.8,31.8,S|284,51.1,45.3,56.8,S;284,76.1,70.8,80.7,U;284,18.7,14.6,23.6,U;284,19,14.9,24,S;284,81.3,76.4,85.4,U;284,19,14.9,24,U|305,49.8,44.3,55.4,S;305,66.2,60.7,71.3,S;305,26.9,22.2,32.1,S;305,17.7,13.8,22.4,S;305,73.1,67.9,77.8,S;305,25.2,20.7,30.4,S|190,43.2,36.3,50.3,S;190,71.6,64.8,77.5,S;190,24.7,19.1,31.3,S;190,36.3,29.8,43.4,D;190,75.3,68.7,80.9,S;190,27.4,21.5,34.1,S|221,48.4,41.9,55,S;221,67,60.5,72.8,S;221,29.4,23.8,35.7,S;221,11.8,8.2,16.7,D;221,70.6,64.3,76.2,S;221,24,18.8,30,S"
"6J" => "OT1|6J|S|2022-01-03|2026-10-16|1239|30|1239,49.2;1239,71.6;1239,22.3;1239,14.6;1239,77.7;1239,22.9|215,50.2,43.6,56.9,S;215,70.7,64.3,76.4,S;215,22.8,17.7,28.8,S;215,11.2,7.6,16.1,S;215,77.2,71.2,82.3,S;215,22.8,17.7,28.8,S|294,59.2,53.5,64.6,D;294,74.5,69.2,79.1,S;294,17.3,13.4,22.1,U;294,15.3,11.6,19.9,S;294,82.7,77.9,86.6,U;294,21.1,16.8,26.1,S|327,53.8,48.4,59.2,S;327,73.7,68.7,78.2,S;327,20.5,16.5,25.2,S;327,14.4,11,18.6,S;327,79.5,74.8,83.5,S;327,22.3,18.1,27.1,S|164,32.9,26.2,40.4,D;164,64,56.4,71,U;164,30.5,24,37.9,D;164,29.3,22.8,36.6,D;164,69.5,62.1,76,D;164,23.8,17.9,30.8,S|239,41,35,47.3,D;239,71.1,65.1,76.5,S;239,24.7,19.6,30.5,S;239,7.1,4.5,11.1,D;239,75.3,69.5,80.4,S;239,25.5,20.4,31.4,S"
"6M" => "OT1|6M|S|2022-01-03|2026-10-16|1234|30|1234,48.9;1234,74.5;1234,21.8;1234,21.6;1234,78.2;1234,22.3|292,49.7,44,55.4,S;292,70.9,65.4,75.8,S;292,25,20.4,30.3,S;292,20.2,16,25.2,S;292,75,69.7,79.6,S;292,22.9,18.5,28.1,S|253,54.9,48.8,61,S;253,77.5,71.9,82.2,S;253,18.6,14.3,23.8,S;253,20.2,15.7,25.5,S;253,81.4,76.2,85.7,S;253,20.6,16,26,S|279,53.4,47.5,59.2,S;279,77.4,72.2,81.9,S;279,19,14.8,24,S;279,21.9,17.4,27.1,S;279,81,76,85.2,S;279,19.7,15.5,24.8,S|229,40.2,34,46.6,D;229,77.7,71.9,82.6,S;229,19.7,15,25.3,S;229,31.4,25.8,37.7,D;229,80.3,74.7,85,S;229,25.3,20.1,31.3,S|181,43.6,36.6,50.9,S;181,67.4,60.3,73.8,U;181,28.2,22.1,35.1,U;181,12.7,8.6,18.3,D;181,71.8,64.9,77.9,U;181,23.8,18.1,30.5,S"
"6N" => "OT1|6N|S|2022-01-03|2026-10-16|1238|30|1238,49.5;1238,70.5;1238,24.2;1238,17.9;1238,75.8;1238,28.5|281,54.8,49,60.5,S;281,71.5,66,76.5,S;281,21.7,17.3,26.9,S;281,18.5,14.4,23.5,S;281,78.3,73.1,82.7,S;281,27.4,22.5,32.9,S|266,59.8,53.8,65.5,D;266,72.9,67.3,77.9,S;266,18.4,14.2,23.5,U;266,15,11.2,19.8,S;266,81.6,76.5,85.8,U;266,30.1,24.9,35.8,S|295,48.5,42.8,54.2,S;295,67.8,62.3,72.9,S;295,28.5,23.6,33.9,S;295,16.3,12.5,20.9,S;295,71.5,66.1,76.4,S;295,28.8,23.9,34.2,S|172,35.5,28.7,42.9,D;172,70.9,63.7,77.2,S;172,26.2,20.2,33.2,S;172,34.9,28.2,42.3,D;172,73.8,66.8,79.8,S;172,27.3,21.2,34.4,S|224,42.9,36.6,49.4,U;224,69.6,63.3,75.3,S;224,27.2,21.8,33.4,S;224,9.8,6.6,14.4,D;224,72.8,66.6,78.2,S;224,28.6,23.1,34.8,S"
"6S" => "OT1|6S|S|2022-01-03|2026-10-16|1239|30|1239,50.3;1239,70.3;1239,23.3;1239,17.4;1239,76.7;1239,24.9|268,55.2,49.2,61.1,S;268,69.4,63.6,74.6,S;268,21.6,17.1,27,S;268,16,12.1,20.9,S;268,78.4,73,82.9,S;268,23.1,18.5,28.5,S|260,55,48.9,60.9,S;260,75.8,70.2,80.6,S;260,16.9,12.9,22,D;260,15.4,11.5,20.3,S;260,83.1,78,87.1,D;260,26.2,21.2,31.8,S|284,50.7,44.9,56.5,S;284,70.8,65.2,75.8,S;284,23.2,18.7,28.5,S;284,14.1,10.5,18.6,S;284,76.8,71.5,81.3,S;284,25.4,20.6,30.7,S|204,41.2,34.6,48,D;204,71.6,65,77.3,S;204,25.5,20,31.9,S;204,35.8,29.5,42.6,D;204,74.5,68.1,80,S;204,28.4,22.7,35,S|223,46.6,40.2,53.2,S;223,63.2,56.7,69.3,D;223,30.9,25.2,37.3,D;223,9,5.9,13.4,D;223,69.1,62.7,74.8,D;223,22,17,27.9,S"
"BTC" => "OT1|BTC|S|2022-01-03|2026-10-16|1234|30|1234,50.2;1234,72.9;1234,24.2;1234,20.5;1234,75.8;1234,31.8|281,49.5,43.7,55.3,S;281,73.3,67.8,78.1,S;281,22.1,17.6,27.3,S;281,19.9,15.7,25,S;281,77.9,72.7,82.4,S;281,32.7,27.5,38.4,S|256,56.2,50.1,62.2,S;256,77,71.4,81.7,S;256,19.5,15.1,24.8,S;256,17.2,13.1,22.3,S;256,80.5,75.2,84.9,S;256,34.8,29.2,40.8,S|306,53.3,47.7,58.8,S;306,76.5,71.4,80.9,S;306,20.3,16.1,25.1,S;306,20.9,16.7,25.8,S;306,79.7,74.9,83.9,S;306,30.7,25.8,36.1,S|218,40.8,34.5,47.5,D;218,67,60.5,72.9,S;218,31.7,25.8,38.1,D;218,32.6,26.7,39,D;218,68.3,61.9,74.2,D;218,29.4,23.7,35.7,S|173,49.1,41.8,56.5,S;173,67.1,59.7,73.6,S;173,32.4,25.8,39.7,D;173,10.4,6.7,15.8,D;173,67.6,60.3,74.2,D;173,30.6,24.2,37.9,S"
"CL" => "OT1|CL|S|2022-01-03|2026-10-16|1237|30|1237,50.1;1237,65.7;1237,31.8;1237,22.2;1237,68.2;1237,18.6|274,51.5,45.6,57.3,S;274,66.4,60.6,71.8,S;274,30.7,25.5,36.4,S;274,20.4,16.1,25.6,S;274,69.3,63.6,74.5,S;274,19.3,15.1,24.4,S|299,61.5,55.9,66.9,D;299,69.9,64.5,74.8,S;299,26.4,21.7,31.7,U;299,20.7,16.5,25.7,S;299,73.6,68.3,78.3,U;299,18.1,14.1,22.8,S|248,49.2,43,55.4,S;248,62.1,55.9,67.9,S;248,34.7,29,40.8,S;248,18.5,14.2,23.9,S;248,65.3,59.2,71,S;248,18.5,14.2,23.9,S|207,39.1,32.7,45.9,D;207,62.8,56,69.1,S;207,36.2,30,43,S;207,39.1,32.7,45.9,D;207,63.8,57,70,S;207,14.5,10.3,19.9,S|209,44,37.5,50.8,S;209,66,59.4,72.1,S;209,33,27,39.6,S;209,13.9,9.8,19.2,D;209,67,60.4,73,S;209,22.5,17.4,28.6,S"
"ES" => "OT1|ES|S|2022-01-03|2026-10-16|1236|30|1236,49;1236,69.5;1236,28.3;1236,19.9;1236,71.7;1236,49.1|271,47.2,41.4,53.2,S;271,70.1,64.4,75.2,S;271,27.7,22.7,33.3,S;271,17.3,13.3,22.3,S;271,72.3,66.7,77.3,S;271,50.2,44.3,56.1,S|292,58.6,52.8,64.1,D;292,77.4,72.3,81.8,D;292,19.9,15.7,24.8,D;292,17.5,13.5,22.2,S;292,80.1,75.2,84.3,D;292,52.4,46.7,58.1,S|287,55.1,49.3,60.7,U;287,64.5,58.8,69.8,S;287,33.1,27.9,38.7,S;287,19.9,15.7,24.9,S;287,66.9,61.3,72.1,S;287,47,41.3,52.8,S|253,37.2,31.4,43.3,D;253,64.8,58.8,70.4,S;253,33.2,27.7,39.2,S;253,30,24.7,36,D;253,66.8,60.8,72.3,S;253,45.5,39.4,51.6,S|133,41.4,33.3,49.9,S;133,70.7,62.4,77.7,S;133,28.6,21.6,36.8,S;133,11.3,7,17.8,D;133,71.4,63.2,78.4,S;133,51.1,42.7,59.5,S"
"ETH" => "OT1|ETH|S|2022-01-03|2026-10-16|1233|30|1233,49.2;1233,70;1233,26.4;1233,23.3;1233,73.6;1233,31.1|278,48.2,42.4,54.1,S;278,70.9,65.3,75.9,S;278,24.5,19.8,29.8,S;278,20.5,16.2,25.6,S;278,75.5,70.2,80.2,S;278,29.9,24.8,35.5,S|234,60.3,53.9,66.3,D;234,73.1,67.1,78.4,S;234,21.4,16.6,27.1,S;234,15.8,11.7,21,D;234,78.6,72.9,83.4,S;234,31.6,26,37.8,S|274,56.9,51,62.7,D;274,72.6,67.1,77.6,S;274,23.4,18.7,28.7,S;274,29.9,24.8,35.6,D;274,76.6,71.3,81.3,S;274,34.7,29.3,40.5,S|221,40.7,34.5,47.3,D;221,63.8,57.3,69.9,U;221,33.5,27.6,39.9,D;221,38.9,32.7,45.5,D;221,66.5,60.1,72.4,D;221,28.5,23,34.8,S|226,38.1,32,44.5,D;226,68.6,62.3,74.3,S;226,30.5,24.9,36.8,S;226,11.1,7.6,15.8,D;226,69.5,63.2,75.1,S;226,30.1,24.5,36.4,S"
"GC" => "OT1|GC|S|2022-01-03|2026-10-16|1237|30|1237,49.3;1237,76.9;1237,15.3;1237,18.8;1237,84.7;1237,23.6|228,48.7,42.3,55.1,S;228,74.1,68.1,79.4,S;228,17.1,12.8,22.5,S;228,18,13.5,23.5,S;228,82.9,77.5,87.2,S;228,28.1,22.6,34.2,S|344,54.9,49.7,60.1,U;344,77.9,73.2,82,S;344,11.9,8.9,15.8,S;344,16.9,13.3,21.2,S;344,88.1,84.2,91.1,S;344,26.2,21.8,31.1,S|318,55,49.5,60.4,U;318,75.5,70.5,79.9,S;318,15.4,11.9,19.8,S;318,18.9,14.9,23.5,S;318,84.6,80.2,88.1,S;318,20.8,16.7,25.5,S|170,35.3,28.5,42.7,D;170,80,73.4,85.3,S;170,15.9,11.2,22.1,S;170,36.5,29.6,43.9,D;170,84.1,77.9,88.8,S;170,20.6,15.2,27.3,S|177,42.4,35.3,49.7,S;177,78,71.3,83.4,S;177,18.6,13.6,25,S;177,6.8,3.9,11.5,D;177,81.4,75,86.4,S;177,20.9,15.6,27.5,S"
"HG" => "OT1|HG|S|2022-01-03|2026-10-16|1237|30|1237,48.7;1237,72.7;1237,21.9;1237,17.7;1237,78.1;1237,23.9|238,47.9,41.6,54.2,S;238,72.7,66.7,78,S;238,18.5,14.1,23.9,S;238,18.5,14.1,23.9,S;238,81.5,76.1,85.9,S;238,24.8,19.7,30.6,S|336,48.8,43.5,54.1,S;336,77.7,72.9,81.8,U;336,17.3,13.6,21.7,U;336,19.3,15.5,23.9,S;336,82.7,78.3,86.4,U;336,20.8,16.8,25.5,S|321,54.5,49,59.9,U;321,72.3,67.1,76.9,S;321,21.5,17.4,26.3,S;321,14.6,11.2,18.9,S;321,78.5,73.7,82.6,S;321,23.7,19.4,28.6,S|150,44,36.3,52,S;150,62.7,54.7,70,D;150,34,26.9,41.9,D;150,33.3,26.3,41.2,D;150,66,58.1,73.1,D;150,28,21.4,35.7,S|192,43.2,36.4,50.3,S;192,72.4,65.7,78.2,S;192,25.5,19.9,32.1,S;192,6.8,4,11.2,D;192,74.5,67.9,80.1,S;192,25.5,19.9,32.1,S"
"NG" => "OT1|NG|S|2022-01-03|2026-10-16|1237|30|1237,49.2;1237,64.5;1237,33.6;1237,17.7;1237,66.4;1237,20.5|284,51.8,46,57.5,S;284,69.7,64.1,74.8,S;284,27.5,22.6,32.9,D;284,15.1,11.4,19.8,S;284,72.5,67.1,77.4,D;284,21.1,16.8,26.2,S|270,61.5,55.6,67.1,D;270,75.2,69.7,80,D;270,22.2,17.7,27.6,D;270,16.7,12.7,21.6,S;270,77.8,72.4,82.3,D;270,21.5,17,26.8,S|263,45.6,39.7,51.7,S;263,62.4,56.4,68,S;263,36.1,30.6,42.1,S;263,21.7,17.1,27,S;263,63.9,57.9,69.4,S;263,19.8,15.4,25,S|203,42.4,35.8,49.2,S;203,51.7,44.9,58.5,D;203,48.3,41.5,55.1,D;203,27.6,21.9,34.1,D;203,51.7,44.9,58.5,D;203,21.2,16.1,27.3,S|217,41.5,35.1,48.1,D;217,59,52.3,65.3,S;217,39.2,32.9,45.8,S;217,8.3,5.3,12.7,D;217,60.8,54.2,67.1,S;217,18.9,14.2,24.6,S"
"NKD" => "OT1|NKD|S|2022-01-03|2026-10-16|1238|30|1238,51;1238,78.8;1238,15.6;1238,18.1;1238,84.4;1238,35.3|323,47.4,42,52.8,S;323,78.9,74.2,83,S;323,14.2,10.8,18.5,S;323,18.9,15,23.5,S;323,85.8,81.5,89.2,S;323,32.5,27.6,37.8,S|322,59.6,54.2,64.8,D;322,85.1,80.8,88.6,D;322,9.9,7.1,13.7,D;322,14.9,11.4,19.2,S;322,90.1,86.3,92.9,D;322,33.2,28.3,38.5,S|287,57.8,52.1,63.4,D;287,79.1,74,83.4,S;287,14.6,11,19.2,S;287,16,12.2,20.7,S;287,85.4,80.8,89,S;287,37.3,31.9,43,S|144,32.6,25.5,40.7,D;144,72.9,65.1,79.5,S;144,21.5,15.6,28.9,S;144,34,26.8,42.1,D;144,78.5,71.1,84.4,S;144,35.4,28.1,43.5,S|162,45.1,37.6,52.7,S;162,70.4,62.9,76.9,D;162,25.9,19.8,33.2,D;162,12.3,8.1,18.3,S;162,74.1,66.8,80.2,D;162,41.4,34.1,49.1,S"
"NQ" => "OT1|NQ|S|2022-01-03|2026-10-16|1236|30|1236,49.9;1236,75.8;1236,20.6;1236,19.8;1236,79.4;1236,45.1|277,47.3,41.5,53.2,S;277,77.3,72,81.8,S;277,17.3,13.3,22.2,S;277,15.5,11.7,20.3,S;277,82.7,77.8,86.7,S;277,44.8,39,50.7,S|343,58.6,53.3,63.7,D;343,78.1,73.5,82.2,S;343,17.5,13.8,21.9,S;343,17.8,14.1,22.2,S;343,82.5,78.1,86.2,S;343,43.1,38,48.4,S|304,51.6,46,57.2,S;304,73,67.8,77.7,S;304,24,19.6,29.1,S;304,21.4,17.1,26.3,S;304,76,70.9,80.4,S;304,48.4,42.8,54,S|196,39.8,33.2,46.8,D;196,75,68.5,80.5,S;196,24.5,19,31,S;196,32.1,26,39,D;196,75.5,69,81,S;196,41.3,34.7,48.3,S|116,43.1,34.5,52.2,S;116,74.1,65.5,81.2,S;116,21.6,15,29.9,S;116,11.2,6.7,18.2,U;116,78.4,70.1,85,S;116,50,41,59,S"
"PA" => "OT1|PA|S|2022-01-03|2026-10-16|1222|30|1222,49;1222,74.1;1222,18.8;1222,17.4;1222,81.2;1222,15.1|294,45.2,39.6,51,S;294,71.8,66.4,76.6,S;294,17.3,13.4,22.1,S;294,21.4,17.1,26.5,S;294,82.7,77.9,86.6,S;294,12.6,9.3,16.9,S|256,54.7,48.6,60.7,S;256,76.2,70.6,81,S;256,15.2,11.3,20.1,S;256,13.7,10,18.4,S;256,84.8,79.9,88.7,S;256,14.1,10.3,18.9,S|303,52.8,47.2,58.4,S;303,78.2,73.2,82.5,S;303,16.2,12.5,20.7,S;303,16.2,12.5,20.7,S;303,83.8,79.3,87.5,S;303,12.9,9.6,17.1,S|169,43.8,36.5,51.3,S;169,74.6,67.5,80.5,S;169,21.3,15.8,28.1,S;169,28.4,22.1,35.6,D;169,78.7,71.9,84.2,S;169,17.8,12.7,24.2,S|200,46,39.2,52.9,S;200,68,61.2,74.1,S;200,27.5,21.8,34.1,D;200,9,5.8,13.8,D;200,72.5,65.9,78.2,D;200,21.5,16.4,27.7,U"
"PL" => "OT1|PL|S|2022-01-03|2026-10-16|1237|30|1237,50;1237,76.1;1237,16.7;1237,16.7;1237,83.3;1237,20.5|260,51.2,45.1,57.2,S;260,76.5,71,81.3,S;260,15.4,11.5,20.3,S;260,15.4,11.5,20.3,S;260,84.6,79.7,88.5,S;260,15.4,11.5,20.3,U|343,55.1,49.8,60.3,S;343,80.8,76.3,84.6,U;343,10.5,7.7,14.2,D;343,17.2,13.6,21.6,S;343,89.5,85.8,92.3,D;343,22.4,18.4,27.2,S|299,52.2,46.5,57.8,S;299,75.3,70.1,79.8,S;299,17.4,13.5,22.1,S;299,15.7,12,20.3,S;299,82.6,77.9,86.5,S;299,18.7,14.7,23.5,S|134,38.8,31,47.3,D;134,70.1,61.9,77.2,S;134,23.1,16.8,31,U;134,29.9,22.8,38.1,D;134,76.9,69,83.2,U;134,18.7,13,26.1,S|201,44.3,37.6,51.2,S;201,72.6,66.1,78.3,S;201,23.9,18.5,30.2,D;201,10,6.5,14.9,D;201,76.1,69.8,81.5,D;201,27.9,22.1,34.4,D"
"RTY" => "OT1|RTY|S|2022-01-03|2026-10-16|1236|30|1236,50.2;1236,77.7;1236,16.3;1236,22.3;1236,83.7;1236,39.7|246,48,41.8,54.2,S;246,76,70.3,80.9,S;246,17.1,12.9,22.3,S;246,22,17.2,27.5,S;246,82.9,77.7,87.1,S;246,37.4,31.6,43.6,S|370,58.1,53,63,D;370,79.7,75.3,83.5,S;370,12.4,9.5,16.2,U;370,20,16.2,24.4,S;370,87.6,83.8,90.5,U;370,39.7,34.9,44.8,S|339,54.6,49.3,59.8,S;339,77.9,73.2,82,S;339,16.8,13.2,21.2,S;339,23.9,19.7,28.7,S;339,83.2,78.8,86.8,S;339,39.8,34.8,45.1,S|176,35.8,29.1,43.1,D;176,76.7,69.9,82.3,S;176,19.3,14.2,25.8,S;176,32.4,25.9,39.6,D;176,80.7,74.2,85.8,S;176,44.3,37.2,51.7,S|105,38.1,29.4,47.6,D;105,75.2,66.2,82.5,S;105,21.9,15.1,30.7,S;105,9.5,5.3,16.6,D;105,78.1,69.3,84.9,S;105,37.1,28.5,46.7,S"
"SI" => "OT1|SI|S|2022-01-03|2026-10-16|1237|30|1237,51.1;1237,76;1237,15.4;1237,19.2;1237,84.6;1237,26.4|245,53.1,46.8,59.2,S;245,74.3,68.5,79.4,S;245,15.5,11.5,20.6,S;245,20,15.5,25.5,S;245,84.5,79.4,88.5,S;245,30.6,25.2,36.6,S|362,55,49.8,60,S;362,75.4,70.7,79.6,S;362,12.7,9.7,16.5,S;362,18.8,15.1,23.1,S;362,87.3,83.5,90.3,S;362,24,19.9,28.7,S|306,53.3,47.7,58.8,S;306,80.4,75.6,84.5,S;306,11.8,8.6,15.9,S;306,19.6,15.5,24.4,S;306,88.2,84.1,91.4,S;306,23.9,19.4,28.9,S|149,40.9,33.4,49,D;149,71.8,64.1,78.4,S;149,24.8,18.6,32.3,D;149,29.5,22.8,37.3,D;149,75.2,67.7,81.4,D;149,27.5,21,35.2,S|175,45.1,38,52.5,S;175,75.4,68.5,81.2,S;175,18.9,13.8,25.3,S;175,9.1,5.7,14.3,D;175,81.1,74.7,86.2,S;175,29.1,22.9,36.3,S"
"YM" => "OT1|YM|S|2022-01-03|2026-10-16|1236|30|1236,50;1236,72.3;1236,23.6;1236,21.7;1236,76.4;1236,45|250,50.4,44.2,56.5,S;250,71.2,65.3,76.5,S;250,22.4,17.7,28,S;250,21.2,16.6,26.7,S;250,77.6,72,82.3,S;250,44.8,38.8,51,S|316,59.2,53.7,64.5,D;316,78.2,73.3,82.4,D;316,17.4,13.6,22,D;316,19,15,23.7,S;316,82.6,78,86.4,D;316,41.5,36.2,47,S|309,55,49.4,60.5,S;309,72.2,66.9,76.9,S;309,24.3,19.8,29.3,S;309,18.8,14.8,23.5,S;309,75.7,70.7,80.2,S;309,45,39.5,50.6,S|234,36.3,30.4,42.7,D;234,67.9,61.7,73.6,S;234,29.5,24,35.6,U;234,32.1,26.4,38.3,D;234,70.5,64.4,76,U;234,50,43.6,56.4,S|127,39.4,31.3,48.1,D;127,68.5,60,75.9,S;127,29.1,21.9,37.6,S;127,17.3,11.7,24.8,S;127,70.9,62.4,78.1,S;127,44.9,36.5,53.6,S"
"ZB" => "OT1|ZB|S|2022-01-03|2026-10-16|1239|30|1239,48.6;1239,72.8;1239,20.6;1239,19;1239,79.4;1239,27.9|350,50.9,45.6,56.1,S;350,78.3,73.7,82.3,U;350,16.3,12.8,20.5,U;350,18,14.3,22.4,S;350,83.7,79.5,87.2,U;350,24.9,20.6,29.6,S|255,54.5,48.4,60.5,S;255,72.2,66.4,77.3,S;255,18,13.8,23.2,S;255,19.6,15.2,24.9,S;255,82,76.8,86.2,S;255,25.1,20.2,30.8,S|222,56.8,50.2,63.1,U;222,68.9,62.6,74.6,S;222,23,17.9,28.9,S;222,16.7,12.3,22.1,S;222,77,71.1,82.1,S;222,28.8,23.3,35.1,S|184,37.5,30.8,44.7,D;184,69.6,62.6,75.8,S;184,24.5,18.8,31.1,S;184,29.9,23.7,36.9,D;184,75.5,68.9,81.2,S;184,28.8,22.7,35.7,S|228,39.5,33.4,45.9,D;228,71.5,65.3,77,S;228,24.6,19.4,30.5,S;228,13.6,9.7,18.7,U;228,75.4,69.5,80.6,S;228,34.2,28.4,40.6,U"
"ZC" => "OT1|ZC|S|2022-01-03|2026-10-16|1203|30|1203,46.5;1203,76.1;1203,15.5;1203,26.9;1203,84.5;1203,38.4|250,46,39.9,52.2,S;250,76.4,70.8,81.2,S;250,12.4,8.9,17.1,S;250,22,17.3,27.5,S;250,87.6,82.9,91.1,S;250,38,32.2,44.2,S|311,52.4,46.9,57.9,U;311,78.1,73.2,82.4,S;311,12.9,9.6,17,S;311,27.7,23,32.9,S;311,87.1,83,90.4,S;311,34.4,29.3,39.8,S|312,50.6,45.1,56.1,S;312,76.3,71.3,80.7,S;312,14.4,11,18.8,S;312,31.1,26.2,36.4,S;312,85.6,81.2,89,S;312,41.7,36.3,47.2,S|214,38.8,32.5,45.5,U;214,73.4,67.1,78.8,S;214,22.4,17.4,28.5,U;214,30.4,24.6,36.8,S;214,77.6,71.5,82.6,U;214,43,36.5,49.7,S|116,34.5,26.5,43.5,U;116,75,66.4,82,S;116,19.8,13.6,28,S;116,18.1,12.2,26.1,U;116,80.2,72,86.4,S;116,32.8,24.9,41.7,S"
"ZF" => "OT1|ZF|S|2022-01-03|2026-10-16|1239|30|1239,48.7;1239,75.7;1239,18.8;1239,17.6;1239,81.2;1239,28.5|326,47.9,42.5,53.3,S;326,78.2,73.4,82.4,S;326,16,12.4,20.3,S;326,17.2,13.5,21.6,S;326,84,79.7,87.6,S;326,24.2,19.9,29.2,S|259,58.3,52.2,64.1,D;259,74.1,68.5,79.1,S;259,16.2,12.2,21.2,S;259,15.4,11.6,20.3,S;259,83.8,78.8,87.8,S;259,29.7,24.5,35.6,S|269,51.7,45.7,57.6,S;269,73.6,68,78.5,S;269,21.9,17.4,27.3,S;269,17.8,13.7,22.9,S;269,78.1,72.7,82.6,S;269,31.2,26,37,S|179,43.6,36.5,50.9,S;179,77.1,70.4,82.6,S;179,17.9,13,24.1,S;179,30.2,23.9,37.3,D;179,82.1,75.9,87,S;179,29.6,23.4,36.7,S|206,38.3,32,45.1,D;206,75.2,68.9,80.6,S;206,23.3,18,29.5,S;206,9.7,6.4,14.5,D;206,76.7,70.5,82,S;206,29.1,23.3,35.7,S"
"ZN" => "OT1|ZN|S|2022-01-03|2026-10-16|1239|30|1239,49.4;1239,73.4;1239,19.4;1239,17.7;1239,80.6;1239,27.2|329,47.1,41.8,52.5,S;329,76,71.1,80.3,S;329,16.4,12.8,20.8,S;329,17.3,13.6,21.8,S;329,83.6,79.2,87.2,S;329,22.8,18.6,27.6,S|250,58.4,52.2,64.3,D;250,72.4,66.6,77.6,S;250,17.2,13,22.4,S;250,14,10.2,18.8,S;250,82.8,77.6,87,S;250,29.2,23.9,35.1,S|244,55.3,49.1,61.4,S;244,73.8,67.9,78.9,S;244,18.4,14.1,23.8,S;244,20.1,15.5,25.6,S;244,81.6,76.2,85.9,S;244,28.3,23,34.2,S|185,45.4,38.4,52.6,S;185,70.8,63.9,76.9,S;185,24.9,19.2,31.6,S;185,34.6,28.1,41.7,D;185,75.1,68.4,80.8,S;185,28.1,22.1,35,S|231,39.8,33.7,46.3,D;231,72.7,66.6,78.1,S;231,22.5,17.6,28.3,S;231,6.1,3.6,9.9,D;231,77.5,71.7,82.4,S;231,29.4,23.9,35.6,S"
"ZS" => "OT1|ZS|S|2022-01-03|2026-10-16|1203|30|1203,49.4;1203,76;1203,17.2;1203,23.7;1203,82.8;1203,42.7|239,50.2,43.9,56.5,S;239,73.2,67.3,78.4,S;239,15.5,11.4,20.6,S;239,20.9,16.2,26.5,S;239,84.5,79.4,88.6,S;239,36.4,30.6,42.7,S|338,51.2,45.9,56.5,S;338,78.4,73.7,82.5,S;338,15.1,11.7,19.3,S;338,22.2,18.1,26.9,S;338,84.9,80.7,88.3,S;338,42,36.9,47.3,S|327,52.3,46.9,57.6,S;327,76.8,71.9,81,S;327,15.3,11.8,19.6,S;327,25.7,21.3,30.7,S;327,84.7,80.4,88.2,S;327,43.7,38.5,49.1,S|161,44.1,36.7,51.8,S;161,74.5,67.3,80.6,S;161,22.4,16.6,29.4,S;161,34.8,27.9,42.4,D;161,77.6,70.6,83.4,S;161,45.3,37.8,53.1,S|138,42.8,34.8,51.1,S;138,74.6,66.8,81.2,S;138,23.9,17.6,31.7,U;138,14.5,9.6,21.3,U;138,76.1,68.3,82.4,U;138,50,41.8,58.2,S"
"ZT" => "OT1|ZT|S|2022-01-03|2026-10-16|1239|30|1239,49.2;1239,72.1;1239,20.7;1239,17.8;1239,79.3;1239,27.8|319,48.9,43.5,54.4,S;319,74.3,69.2,78.8,S;319,18.5,14.6,23.1,S;319,19.4,15.5,24.1,S;319,81.5,76.9,85.4,S;319,25.7,21.2,30.8,S|225,64,57.5,70,D;225,76.9,71,81.9,S;225,15.6,11.4,20.9,S;225,16.9,12.6,22.3,S;225,84.4,79.1,88.6,S;225,29.8,24.2,36.1,S|237,54.9,48.5,61.1,S;237,71.7,65.7,77.1,S;237,19.8,15.3,25.4,S;237,18.1,13.8,23.5,S;237,80.2,74.6,84.7,S;237,25.7,20.6,31.7,S|211,37.9,31.6,44.6,D;211,67.8,61.2,73.7,S;211,27,21.5,33.4,U;211,29.4,23.7,35.9,D;211,73,66.6,78.5,U;211,26.5,21,32.9,S|247,40.1,34.2,46.3,D;247,68.8,62.8,74.3,S;247,23.5,18.6,29.1,S;247,6.1,3.7,9.8,D;247,76.5,70.9,81.4,S;247,32,26.5,38,S"
"ZW" => "OT1|ZW|S|2022-01-03|2026-10-16|1203|30|1203,47.5;1203,77.6;1203,12.8;1203,21.4;1203,87.2;1203,35.2|210,54.3,47.5,60.9,S;210,74.3,68,79.7,S;210,12.4,8.6,17.5,S;210,14.8,10.6,20.2,U;210,87.6,82.5,91.4,S;210,34.3,28.2,40.9,S|402,47.8,42.9,52.6,S;402,75.4,70.9,79.3,S;402,11.7,8.9,15.2,S;402,26.1,22.1,30.6,U;402,88.3,84.8,91.1,S;402,35.8,31.3,40.6,S|314,54.5,48.9,59.9,U;314,82.2,77.6,86,S;314,10.5,7.6,14.4,S;314,23.6,19.2,28.6,S;314,89.5,85.6,92.4,S;314,34.1,29.1,39.5,S|175,35.4,28.7,42.8,D;175,80.6,74.1,85.8,S;175,17.7,12.8,24,S;175,20,14.7,26.5,S;175,82.3,76,87.2,S;175,37.1,30.3,44.5,S|102,31.4,23.2,40.9,D;102,73.5,64.2,81.1,S;102,16.7,10.7,25.1,S;102,12.7,7.6,20.6,U;102,83.3,74.9,89.3,S;102,34.3,25.8,43.9,S"
=> ""
// --- END GENERATED CONSTANTS
// --- BEGIN SHARED CORE
// One session state machine, fed bar by bar. The same code runs (a) inside a fixed-timeframe request, where the chart
// keeps enough sessions for the 20-session average range and the row size, and (b) on the chart bars (or on their
// intrabars when the chart timeframe does not line up with the session), for what happens inside today's session.
type Sess
int startMin = 570
int endMin = 960
string tz = "America/New_York"
int ibMin = 60
int orMin = 15
int rowTicks = 0
bool active = false
int count = 0
int finished = 0
int dayKey = 0
int startTime = 0
int elapsed = 0
int lastDow = 0
int lastMonth = 0
float o = na
float h = na
float l = na
float c = na
float orH = na
float orL = na
bool orDone = false
float ibH = na
float ibL = na
bool ibDone = false
bool brkOrUp = false
bool brkOrDn = false
bool brkIbUp = false
bool brkIbDn = false
bool gapFilled = false
float step = na
float nextStep = na
array<float> perH
array<float> perL
float pO = na
float pH = na
float pL = na
float pC = na
float pVAH = na
float pVAL = na
float pPOC = na
float pStep = na
int pDayKey = 0
int pDow = 0
int pStart = 0
array<float> pPerH
array<float> pPerL
array<float> ranges
array<float> trs
float atr = na
float wO = na
float wH = na
float wL = na
float pwH = na
float pwL = na
bool wPartial = true
float mO = na
float mH = na
float mL = na
float pmH = na
float pmL = na
bool mPartial = true
f_newSess(int startMin, int endMin, string tz, int ibMin, int orMin, int rowTicks) =>
Sess.new(startMin = startMin, endMin = endMin, tz = tz, ibMin = ibMin, orMin = orMin, rowTicks = rowTicks, perH = array.new<float>(), perL = array.new<float>(), pPerH = array.new<float>(), pPerL = array.new<float>(), ranges = array.new<float>(), trs = array.new<float>())
// "HHMM-HHMM" -> minutes of the day
f_sessStart(string s) =>
int(str.tonumber(str.substring(s, 0, 2)) * 60 + str.tonumber(str.substring(s, 2, 4)))
f_sessEnd(string s) =>
int(str.tonumber(str.substring(s, 5, 7)) * 60 + str.tonumber(str.substring(s, 7, 9)))
// Row size of the profile: a round number of ticks that gives about 45 rows for a typical session
// (the median range of up to 60 sessions before the one being read). rowTicks > 0 overrides it.
f_autoStep(array<float> ranges, int rowTicks, float fallbackRange) =>
float typical = fallbackRange
int n = ranges.size()
if n > 0
array<float> srt = ranges.copy()
srt.sort(order.ascending)
typical := srt.get(int(math.floor(n / 2)))
int k = int(math.max(1, math.ceil(nz(typical, syminfo.mintick * 45) / 45 / syminfo.mintick)))
int ticks = k
array<int> nice = array.from(1, 2, 4, 5, 8, 10, 20, 25, 40, 50, 100, 200, 250, 500, 1000)
bool found = false
for v in nice
if not found and v >= k
ticks := v
found := true
if rowTicks > 0
ticks := rowTicks
ticks * syminfo.mintick
f_row(float price, float step) =>
int(math.floor(price / step + 1e-9))
// Point of control and 70% value area from the highs and lows of the 30-minute periods of one session.
// POC = the row with the most periods; ties go to the row closest to the middle of the range, then the higher one.
// Value area = grown from the POC one row at a time toward the side with more periods (ties up) until 70%.
// A row is named by its lower price, like the profile page of the portal.
f_profile(array<float> perH, array<float> perL, float step) =>
float poc = na
float vah = na
float val = na
int bot = na
int top = na
int np = perH.size()
if np > 0 and not na(step) and step > 0
for i = 0 to np - 1
float ph = perH.get(i)
float pl = perL.get(i)
if not na(ph) and not na(pl)
int rl = f_row(pl, step)
int rh = f_row(ph, step)
bot := na(bot) ? rl : math.min(bot, rl)
top := na(top) ? rh : math.max(top, rh)
if not na(bot) and top - bot < 5000
int nrows = top - bot + 1
array<int> counts = array.new<int>(nrows, 0)
for i = 0 to np - 1
float ph = perH.get(i)
float pl = perL.get(i)
if not na(ph) and not na(pl)
int rl = f_row(pl, step) - bot
int rh = f_row(ph, step) - bot
for r = rl to rh
counts.set(r, counts.get(r) + 1)
int mx = counts.max()
float mid = (nrows - 1) / 2.0
int pr = -1
float best = na
for r = 0 to nrows - 1
if counts.get(r) == mx
float d = math.abs(r - mid)
if pr < 0 or d <= best
pr := r
best := d
int total = counts.sum()
int loR = pr
int hiR = pr
float acc = counts.get(pr)
while acc < 0.70 * total and (loR > 0 or hiR < nrows - 1)
int up = hiR < nrows - 1 ? counts.get(hiR + 1) : -1
int dn = loR > 0 ? counts.get(loR - 1) : -1
if up >= dn
hiR += 1
acc += up
else
loR -= 1
acc += dn
poc := math.round_to_mintick((bot + pr) * step)
vah := math.round_to_mintick((bot + hiR) * step)
val := math.round_to_mintick((bot + loR) * step)
[poc, vah, val]
// Closes the running session: its levels become the "prior session" ones.
method finish(Sess s) =>
if s.active
s.active := false
s.finished := s.finished + 1
float rng = s.h - s.l
[poc, vah, val] = f_profile(s.perH, s.perL, s.step)
float tr = na(s.pC) ? rng : math.max(rng, math.max(math.abs(s.h - s.pC), math.abs(s.l - s.pC)))
s.trs.push(tr)
if s.trs.size() > 20
s.trs.shift()
s.ranges.push(rng)
if s.ranges.size() > 60
s.ranges.shift()
s.atr := s.trs.size() >= 5 ? s.trs.avg() : na
s.nextStep := f_autoStep(s.ranges, s.rowTicks, rng)
s.pO := s.o
s.pH := s.h
s.pL := s.l
s.pC := s.c
s.pPOC := poc
s.pVAH := vah
s.pVAL := val
s.pStep := s.step
s.pDayKey := s.dayKey
s.pDow := s.lastDow
s.pStart := s.startTime
s.pPerH := s.perH.copy()
s.pPerL := s.perL.copy()
s.wH := na(s.wH) ? s.h : math.max(s.wH, s.h)
s.wL := na(s.wL) ? s.l : math.min(s.wL, s.l)
s.mH := na(s.mH) ? s.h : math.max(s.mH, s.h)
s.mL := na(s.mL) ? s.l : math.min(s.mL, s.l)
s.finished
// Opens a new session at the bar that starts at time t (off = minutes after the nominal session open).
method begin(Sess s, int t, int off, int key, int dow, float o) =>
bool first = s.lastDow == 0
bool newWeek = first or dow <= s.lastDow or t - s.startTime > 6 * 86400000
if newWeek
s.pwH := s.wPartial ? na : s.wH
s.pwL := s.wPartial ? na : s.wL
s.wPartial := first and dow != dayofweek.monday
s.wH := na
s.wL := na
s.wO := o
int mon = month(t, s.tz)
if mon != s.lastMonth
s.pmH := s.mPartial ? na : s.mH
s.pmL := s.mPartial ? na : s.mL
s.mPartial := first
s.mH := na
s.mL := na
s.mO := o
s.lastDow := dow
s.lastMonth := mon
s.dayKey := key
s.startTime := t - off * 60000
s.active := true
s.count := s.count + 1
s.o := o
s.h := na
s.l := na
s.c := na
s.orH := na
s.orL := na
s.orDone := false
s.ibH := na
s.ibL := na
s.ibDone := false
s.brkOrUp := false
s.brkOrDn := false
s.brkIbUp := false
s.brkIbDn := false
s.gapFilled := false
s.elapsed := 0
s.step := f_autoStep(s.ranges, s.rowTicks, na)
s.perH := array.new<float>()
s.perL := array.new<float>()
s.count
// One bar (or intrabar) that starts at time t and lasts dur minutes; done = the bar is complete.
method feed(Sess s, int t, int dur, bool done, float o, float h, float l, float c) =>
int mins = hour(t, s.tz) * 60 + minute(t, s.tz)
int dow = dayofweek(t, s.tz)
bool inWin = mins >= s.startMin and mins < s.endMin and dow != dayofweek.saturday and dow != dayofweek.sunday and not na(h) and not na(l)
int key = year(t, s.tz) * 10000 + month(t, s.tz) * 100 + dayofmonth(t, s.tz)
if s.active and (not inWin or key != s.dayKey)
s.finish()
if inWin
int off = mins - s.startMin
if key != s.dayKey
s.begin(t, off, key, dow, o)
s.h := na(s.h) ? h : math.max(s.h, h)
s.l := na(s.l) ? l : math.min(s.l, l)
s.c := c
s.elapsed := off + dur
// opening range: bars that start inside the window build it; the first bar after it fixes it
if off < s.orMin
s.orH := na(s.orH) ? h : math.max(s.orH, h)
s.orL := na(s.orL) ? l : math.min(s.orL, l)
else
s.orDone := true
if h > s.orH
s.brkOrUp := true
if l < s.orL
s.brkOrDn := true
if off < s.ibMin
s.ibH := na(s.ibH) ? h : math.max(s.ibH, h)
s.ibL := na(s.ibL) ? l : math.min(s.ibL, l)
else
s.ibDone := true
if h > s.ibH
s.brkIbUp := true
if l < s.ibL
s.brkIbDn := true
// gap against the previous session's last price: filled when price trades back at it
if not na(s.pC) and not s.gapFilled
if (s.o > s.pC and l <= s.pC) or (s.o < s.pC and h >= s.pC)
s.gapFilled := true
// highs and lows of the 30-minute periods (A = first 30 minutes)
int k = int(math.floor(off / 30))
while s.perH.size() <= k
s.perH.push(na)
s.perL.push(na)
float ph = s.perH.get(k)
float pl = s.perL.get(k)
s.perH.set(k, na(ph) ? h : math.max(ph, h))
s.perL.set(k, na(pl) ? l : math.min(pl, l))
// the bar that ends the window closes the session (once that bar is complete)
if done and s.elapsed >= s.endMin - s.startMin
s.finish()
s.count
// The deep-history context: prior-session levels, 20-session average true range of the regular session, row size,
// week and month references. Evaluated on a fixed timeframe so that a 1-minute chart has the same history as a
// 60-minute one. Everything it returns is final when the session it describes has ended.
f_ctx(int startMin, int endMin, string tz, int rowTicks, int dur) =>
var Sess s = f_newSess(startMin, endMin, tz, 60, 15, rowTicks)
s.feed(time, dur, barstate.isconfirmed, open, high, low, close)
[s.finished, s.pDayKey, s.pDow, s.lastMonth, s.pStart, s.pO, s.pH, s.pL, s.pC, s.pVAH, s.pVAL, s.pPOC, s.atr, s.trs.size(), s.pStep, s.nextStep, s.wO, s.wH, s.wL, s.pwH, s.pwL, s.wPartial, s.mO, s.mH, s.mL, s.pmH, s.pmL, s.mPartial]
// Timeframe of the deep-history context and of the intrabars: the coarsest of 15 / 5 / 1 minutes the session lines up with.
f_gridTf(int a, int b, int cap) =>
a % 15 == 0 and b % 15 == 0 and cap >= 15 ? 15 : a % 5 == 0 and b % 5 == 0 and cap >= 5 ? 5 : 1
// --- END SHARED CORE
// ------------------------------------------------------------------------------------------------------------ inputs
string G0 = "General"
string lang = input.string("es", "Idioma / Language / Idioma", options = ["es", "en", "pt"], group = G0)
string marketIn = input.string("Auto", "Mercado de las estadísticas / Market", options = ["Auto", "ES", "NQ", "RTY", "YM", "NKD", "GC", "SI", "HG", "PL", "PA", "CL", "NG", "ZN", "ZB", "ZF", "ZT", "ZC", "ZS", "ZW", "6E", "6J", "6B", "6A", "6C", "6S", "6N", "6M", "BTC", "ETH"], group = G0, tooltip = "Auto: se toma del símbolo del gráfico (los micros usan las estadísticas de su contrato grande). / Auto: taken from the chart symbol.")
string viewIn = input.string("Hoy", "Tipo de apertura de la tabla / Table open type", options = ["Hoy", "Open-Drive", "Open-Test-Drive", "Open-Rejection-Reverse", "Open-Auction dentro del rango previo", "Open-Auction fuera del rango previo"], group = G0, tooltip = "Hoy: el de la sesión en curso o, antes de que se clasifique, el de la última sesión clasificada. / Today: the session in progress or, before it is classified, the last classified one.")
string srcMode = input.string("Velas de 1 minuto", "Datos de los primeros 30 minutos", options = ["Velas de 1 minuto", "Velas del gráfico"], group = G0, tooltip = "Velas de 1 minuto: las mismas reglas que nuestra tabla (intrabarras de 1 minuto si el gráfico no es de 1 minuto). Velas del gráfico: más liviano y aproximado: dentro de una vela larga no se sabe qué extremo llegó primero.")
bool showBox = input.bool(true, "Recuadro de los primeros 30 minutos", group = G0)
bool showLabel = input.bool(true, "Etiqueta con el tipo de apertura", group = G0)
int keepDays = input.int(10, "Sesiones con recuadro y etiqueta", minval = 1, maxval = 40, group = G0)
bool showTable = input.bool(true, "Tabla", group = G0)
string tablePos = input.string("top_right", "Posición de la tabla", options = ["top_right", "top_left", "bottom_right", "bottom_left", "middle_right"], group = G0)
string G5 = "Colores / Colours"
color cBox = input.color(color.new(#8b98a8, 88), "Recuadro", group = G5)
color cLab = input.color(#a78bfa, "Etiqueta", group = G5)
color cText = input.color(#c9d1d9, "Texto de la tabla", group = G5)
color cTableBg = input.color(color.new(#0d1117, 15), "Fondo de la tabla", group = G5)
f_t(string es, string en, string pt) =>
lang == "es" ? es : lang == "en" ? en : pt
// ------------------------------------------------------------------------------------------------------------- setup
int WINDOW = 30
float TOL = 0.05
float DRIVE = 0.20
int MIN_TRADED = 10
int IB_MIN = 60
string root = marketIn == "Auto" ? f_parent(syminfo.root) : marketIn
string lvSpec = f_lvSess(root)
string lvTz = f_lvTz(root)
int lvStart = f_sessStart(lvSpec)
int lvEnd = f_sessEnd(lvSpec)
int mult = timeframe.multiplier
bool okTf = timeframe.isminutes and mult <= 60
bool useLtf = okTf and mult > 1 and srcMode == "Velas de 1 minuto"
bool aligned = lvStart % mult == 0 and WINDOW % mult == 0
bool ok = okTf and (mult == 1 or useLtf or aligned)
int ctxDur = f_gridTf(lvStart, lvEnd, 15)
string ctxTf = str.tostring(ctxDur)
// The prior session (high, low, value area) and the median range of the 20 sessions before the one in progress, on a
// fixed timeframe so that a 1-minute chart has the same history as a 15-minute one.
f_scaleCtx(int startMin, int endMin, string tz, int dur) =>
var Sess s = f_newSess(startMin, endMin, tz, 60, 15, 0)
s.feed(time, dur, barstate.isconfirmed, open, high, low, close)
float med = na
int n = s.ranges.size()
if n >= 20
med := s.ranges.slice(n - 20, n).median()
[s.finished, s.pDayKey, s.pH, s.pL, s.pVAH, s.pVAL, med]
[cFin, cKey, cPH, cPL, cVAH, cVAL, cR] = request.security(syminfo.tickerid, ctxTf, f_scaleCtx(lvStart, lvEnd, lvTz, ctxDur), lookahead = barmerge.lookahead_off)
// ------------------------------------------------------------------------------------------------- the session's open
type OpenDay
int key = 0
int start = 0
float o = na
float wH = na
float wL = na
float wC = na
int tH = -1
int tL = -1
int traded = 0
bool classified = false
int code = -1
float r = na
float tol = na
float h = na
float l = na
float c = na
int tDayH = -1
int tDayL = -1
int last = 0
float ibH = na
float ibL = na
float pH = na
float pL = na
float pVAH = na
float pVAL = na
// 0 Open-Drive, 1 Open-Test-Drive, 2 Open-Rejection-Reverse, 3 Open-Auction inside the prior range, 4 outside; -1 none.
// exA / exB = the excursions above and below O in the window; "far" is the larger one, "near" the other.
f_classify(OpenDay d) =>
int code = -1
if d.traded >= MIN_TRADED and not na(d.r) and d.r > 0 and not na(d.o) and not na(d.wH) and not na(d.wL) and not na(d.wC)
float exA = math.max(0.0, d.wH - d.o)
float exB = math.max(0.0, d.o - d.wL)
bool farA = exA >= exB
float far = farA ? exA : exB
float near = farA ? exB : exA
float hold = farA ? d.wC - d.o : d.o - d.wC
// which extreme printed first: 1 the window's high, -1 its low, 0 the same minute (or a flat window)
int firstSide = d.tH == d.tL or (exA == 0 and exB == 0) ? 0 : d.tH < d.tL ? 1 : -1
int nearSide = farA ? -1 : 1
float tol = math.max(TOL * d.r, syminfo.mintick)
float drive = DRIVE * d.r
int closeSide = d.wC - d.o > tol ? 1 : d.o - d.wC > tol ? -1 : 0
if near <= tol and far >= drive and hold >= 0.5 * far
code := 0
else if firstSide == nearSide and near > tol and near <= drive and far >= drive and hold >= 0.5 * far
code := 1
else if exA > tol and exB > tol and firstSide != 0 and closeSide != 0 and closeSide != firstSide
code := 2
else if not na(d.pH) and not na(d.pL)
code := d.o <= d.pH and d.o >= d.pL ? 3 : 4
code
f_reset(OpenDay d, int key, int start, float o) =>
d.key := key
d.start := start
d.o := o
d.wH := na
d.wL := na
d.wC := na
d.tH := -1
d.tL := -1
d.traded := 0
d.classified := false
d.code := -1
d.h := na
d.l := na
d.c := na
d.tDayH := -1
d.tDayL := -1
d.last := 0
d.ibH := na
d.ibL := na
// what was known before the open (a context that already holds this session is not used)
bool before = not na(cKey) and cKey < key
d.r := before ? cR : na
d.tol := before and not na(cR) ? math.max(TOL * cR, syminfo.mintick) : na
d.pH := before ? cPH : na
d.pL := before ? cPL : na
d.pVAH := before ? cVAH : na
d.pVAL := before ? cVAL : na
d.key
var OpenDay sday = OpenDay.new()
// finished sessions, oldest first
var array<OpenDay> past = array.new<OpenDay>()
// One bar (or 1-minute intrabar) that starts at time t and lasts dur minutes; done = the bar is complete.
// Returns 1 when it opens a session, 2 when it classifies the open, 3 both.
f_otFeed(OpenDay d, int t, int dur, bool done, float o, float h, float l, float c) =>
int ev = 0
int mins = hour(t, lvTz) * 60 + minute(t, lvTz)
int dow = dayofweek(t, lvTz)
if mins >= lvStart and mins < lvEnd and dow != dayofweek.saturday and dow != dayofweek.sunday and not na(h) and not na(l)
int key = year(t, lvTz) * 10000 + month(t, lvTz) * 100 + dayofmonth(t, lvTz)
int off = mins - lvStart
if key != d.key
if d.key != 0
past.push(d.copy())
if past.size() > 60
past.shift()
f_reset(d, key, t - off * 60000, o)
ev := 1
if na(d.h) or h > d.h
d.h := h
d.tDayH := off
if na(d.l) or l < d.l
d.l := l
d.tDayL := off
d.c := c
d.last := off
if off < IB_MIN
d.ibH := na(d.ibH) ? h : math.max(d.ibH, h)
d.ibL := na(d.ibL) ? l : math.min(d.ibL, l)
if off < WINDOW
// the first minute of an extreme is kept: a later equal price does not move it
if na(d.wH) or h > d.wH
d.wH := h
d.tH := off
if na(d.wL) or l < d.wL
d.wL := l
d.tL := off
d.wC := c
d.traded := d.traded + dur
if not d.classified and (off >= WINDOW or (done and off + dur >= WINDOW))
d.classified := true
d.code := f_classify(d)
ev += 2
ev
int evNew = 0
int evCls = 0
if ok
if useLtf
[lt, lo, lh, ll, lc] = request.security_lower_tf(syminfo.tickerid, "1", [time, open, high, low, close])
int nl = lt.size()
if nl > 0
for i = 0 to nl - 1
bool done = i < nl - 1 or barstate.isconfirmed
int e = f_otFeed(sday, lt.get(i), 1, done, lo.get(i), lh.get(i), ll.get(i), lc.get(i))
if e % 2 == 1
evNew := 1
if e >= 2
evCls := 1
else
int e = f_otFeed(sday, time, mult, barstate.isconfirmed, open, high, low, close)
if e % 2 == 1
evNew := 1
if e >= 2
evCls := 1
// ------------------------------------------------------------------------------------------------------------- names
f_name(int c) =>
c == 0 ? "Open-Drive" : c == 1 ? "Open-Test-Drive" : c == 2 ? "Open-Rejection-Reverse" : c == 3 ? f_t("Open-Auction dentro del rango previo", "Open-Auction inside the prior range", "Open-Auction dentro da amplitude anterior") : c == 4 ? f_t("Open-Auction fuera del rango previo", "Open-Auction outside the prior range", "Open-Auction fora da amplitude anterior") : f_t("sin tipo", "no type", "sem tipo")
f_outcome(int o) =>
o == 0 ? f_t("Rango mayor que su mediana reciente", "Range above its recent median", "Amplitude acima da sua mediana recente") : o == 1 ? f_t("Superó el IB (primera hora) por un solo lado", "Traded beyond the IB (first hour) on one side only", "Superou o IB (primeira hora) por um só lado") : o == 2 ? f_t("Superó el IB por ambos lados", "Traded beyond the IB on both sides", "Superou o IB pelos dois lados") : o == 3 ? f_t("Cerró dentro del área de valor previa", "Closed inside the prior value area", "Fechou dentro da área de valor anterior") : o == 4 ? f_t("Máximo o mínimo en la primera hora", "High or low in the first hour", "Máxima ou mínima na primeira hora") : f_t("Máximo o mínimo en la última hora", "High or low in the last hour", "Máxima ou mínima na última hora")
f_2(int v) =>
v < 10 ? "0" + str.tostring(v) : str.tostring(v)
f_date(int key) =>
str.tostring(int(math.floor(key / 10000))) + "-" + f_2(int(math.floor(key / 100)) % 100) + "-" + f_2(key % 100)
f_dec(float v, string fmt) =>
string s = na(v) ? "—" : str.tostring(v, fmt)
lang == "en" ? s : str.replace_all(s, ".", ",")
f_pct(float v) =>
na(v) ? "—" : f_dec(v, "0.0") + (lang == "en" ? "%" : " %")
f_px(float v) =>
na(v) ? "—" : str.tostring(v, format.mintick)
f_verdict(string v) =>
v == "S" or v == "U" ? f_t("igual al azar", "same as chance", "igual ao acaso") : v == "D" ? f_t("distinto de todas", "different from all", "diferente de todos") : f_t("pocos casos", "too few cases", "poucos casos")
// --------------------------------------------------------------------------------------------------------- drawings
var array<box> boxes = array.new<box>()
var array<label> labs = array.new<label>()
if evCls == 1
string nm = f_name(sday.code)
string tip = "R = " + f_px(sday.r) + f_t(" · tolerancia ", " · tolerance ", " · tolerância ") + f_px(sday.tol) + " · drive " + f_px(na(sday.r) ? na : DRIVE * sday.r) + f_t(". Solo cómo abrió la sesión, no hacia dónde.", ". Only how the session opened, not which way.", ". Só como o pregão abriu, não para onde.")
if showBox and not na(sday.wH)
boxes.push(box.new(sday.start, sday.wH, sday.start + WINDOW * 60000, sday.wL, xloc = xloc.bar_time, border_color = color.new(cLab, 60), bgcolor = cBox))
if showLabel and not na(sday.wH)
labs.push(label.new(sday.start, sday.wH, nm, xloc = xloc.bar_time, style = label.style_label_lower_left, color = color.new(cLab, 85), textcolor = cLab, size = size.small, tooltip = tip))
while boxes.size() > keepDays
boxes.shift().delete()
while labs.size() > keepDays
labs.shift().delete()
// ------------------------------------------------------------------------------------------------------- statistics
// OT1|root|period|from|to|sessions|cells in the table's family|control: six "n,pct"|five open types: six
// "n,pct,low,high,verdict" each (the outcomes in the order of f_outcome)
var array<string> fs = str.split(f_ot(root), "|")
var bool statsOn = fs.size() >= 13 and fs.get(0) == "OT1"
f_part(array<string> f, int i, int j) =>
array<string> out = array.new<string>()
if i < f.size()
array<string> cells = str.split(f.get(i), ";")
if j < cells.size()
out := str.split(cells.get(j), ",")
out
f_num(array<string> a, int i) =>
float v = na
if i < a.size()
v := str.tonumber(a.get(i))
v
f_str(array<string> a, int i) =>
string v = ""
if i < a.size()
v := a.get(i)
v
// the open type the table shows, and the session it comes from
f_viewCode() =>
int c = viewIn == "Open-Drive" ? 0 : viewIn == "Open-Test-Drive" ? 1 : viewIn == "Open-Rejection-Reverse" ? 2 : viewIn == "Open-Auction dentro del rango previo" ? 3 : viewIn == "Open-Auction fuera del rango previo" ? 4 : -1
int k = 0
if c < 0
if sday.classified and sday.code >= 0
c := sday.code
k := sday.key
else
int n = past.size()
if n > 0
for i = n - 1 to 0
OpenDay p = past.get(i)
if c < 0 and p.classified and p.code >= 0
c := p.code
k := p.key
[c, k]
// ------------------------------------------------------------------------------------------------------------- table
f_pos(string p) =>
p == "top_left" ? position.top_left : p == "bottom_right" ? position.bottom_right : p == "bottom_left" ? position.bottom_left : p == "middle_right" ? position.middle_right : position.top_right
f_cell(table t, int col, int row, string txt, color tc, string al) =>
table.cell(t, col, row, txt, text_color = tc, text_size = size.small, text_halign = al)
true
string FOOT = f_t("Solo tamaño, frecuencia, ubicación y hora; no dice hacia dónde ni qué operar, y no es una señal. Igual al azar: el intervalo contiene el valor de todas las sesiones o la celda no supera el control de descubrimientos falsos.", "Size, frequency, location and time only; it says nothing about which way nor what to trade, and it is not a signal. Same as chance: the interval holds the all-sessions value or the cell fails the false-discovery control.", "Só tamanho, frequência, localização e hora; não diz para onde nem o que operar, e não é um sinal. Igual ao acaso: o intervalo contém o valor de todos os pregões ou a célula não passa no controle de descobertas falsas.")
var table info = na
if barstate.islast and showTable
// a fresh table on every update: merged cells are defined once per table
if not na(info)
table.delete(info)
info := table.new(f_pos(tablePos), 5, 12, bgcolor = cTableBg, border_width = 0)
color dim = color.new(cText, 35)
if not ok
f_cell(info, 0, 0, f_t("Usa un gráfico de 1 a 60 minutos.", "Use a chart of 1 to 60 minutes.", "Use um gráfico de 1 a 60 minutos."), cText, text.align_left)
else
[vc, vk] = f_viewCode()
string head = f_t("Tipo de apertura · ", "Open type · ", "Tipo de abertura · ") + root + " · " + lvSpec + " " + lvTz + f_t(" · datos al ", " · data through ", " · dados até ") + DATA_THROUGH
f_cell(info, 0, 0, head, cText, text.align_left)
table.merge_cells(info, 0, 0, 4, 0)
string today = sday.key == 0 ? f_t("Aún no hay una sesión en el gráfico.", "No session on the chart yet.", "Ainda não há um pregão no gráfico.") : not sday.classified ? f_t("Hoy: se clasifica al cumplirse los primeros 30 minutos.", "Today: classified once the first 30 minutes are complete.", "Hoje: classificado ao completar os primeiros 30 minutos.") : f_t("Hoy (", "Today (", "Hoje (") + f_date(sday.key) + "): " + f_name(sday.code) + " · R = " + f_px(sday.r)
string shown = vc < 0 ? f_t("Sin una sesión clasificada para la tabla.", "No classified session for the table.", "Sem um pregão classificado para a tabela.") : vk == sday.key and vk != 0 ? f_t("Lo que hizo la sesión después de ", "What the session did after ", "O que o pregão fez depois de ") + f_name(vc) : vk != 0 ? f_t("Tabla de la última sesión clasificada (", "Table of the last classified session (", "Tabela do último pregão classificado (") + f_date(vk) + "): " + f_name(vc) : f_t("Lo que hizo la sesión después de ", "What the session did after ", "O que o pregão fez depois de ") + f_name(vc)
f_cell(info, 0, 1, today, cText, text.align_left)
table.merge_cells(info, 0, 1, 4, 1)
f_cell(info, 0, 2, shown, dim, text.align_left)
table.merge_cells(info, 0, 2, 4, 2)
if not statsOn
f_cell(info, 0, 3, f_t("Sin tabla de tipos de apertura para este mercado.", "No open-type table for this market.", "Sem tabela de tipos de abertura para este mercado."), dim, text.align_left)
table.merge_cells(info, 0, 3, 4, 3)
else if vc >= 0
f_cell(info, 0, 3, f_t("Qué pasó", "What happened", "O que aconteceu"), dim, text.align_left)
f_cell(info, 1, 3, f_t("Desde 2022", "Since 2022", "Desde 2022"), dim, text.align_right)
f_cell(info, 2, 3, f_t("IC 95 %", "95% CI", "IC 95%"), dim, text.align_right)
f_cell(info, 3, 3, f_t("Todas", "All", "Todos"), dim, text.align_right)
f_cell(info, 4, 3, f_t("Veredicto", "Verdict", "Veredito"), dim, text.align_left)
float nType = na
for o = 0 to 5
array<string> c = f_part(fs, 8 + vc, o)
array<string> b = f_part(fs, 7, o)
nType := na(nType) ? f_num(c, 0) : nType
f_cell(info, 0, 4 + o, f_outcome(o), cText, text.align_left)
f_cell(info, 1, 4 + o, f_pct(f_num(c, 1)) + " (n = " + f_str(c, 0) + ")", cText, text.align_right)
f_cell(info, 2, 4 + o, na(f_num(c, 2)) ? "—" : f_dec(f_num(c, 2), "0.0") + "–" + f_dec(f_num(c, 3), "0.0"), dim, text.align_right)
f_cell(info, 3, 4 + o, f_pct(f_num(b, 1)), dim, text.align_right)
f_cell(info, 4, 4 + o, f_verdict(f_str(c, 4)), cText, text.align_left)
string per = f_t("Desde 2022: ", "Since 2022: ", "Desde 2022: ") + fs.get(3) + f_t(" a ", " to ", " a ") + fs.get(4) + ", " + fs.get(5) + f_t(" sesiones en total, ", " sessions in all, ", " pregões no total, ") + str.tostring(nType, "0") + f_t(" de este tipo. Todas = la misma cuenta en todas las sesiones del período; ", " of this type. All = the same count over every session of the period; ", " deste tipo. Todos = a mesma conta em todos os pregões do período; ") + fs.get(6) + f_t(" celdas en la tabla.", " cells in the table.", " células na tabela.")
f_cell(info, 0, 10, per, dim, text.align_left)
table.merge_cells(info, 0, 10, 4, 10)
f_cell(info, 0, 11, FOOT, dim, text.align_left)
table.merge_cells(info, 0, 11, 4, 11)
// ------------------------------------------------------------------------------------------------------------ alerts
// When the first 30 minutes are complete and the open gets its type. The type only: never a side.
bool aCls = evCls == 1 and sday.code >= 0
alertcondition(aCls, "Open type classified", "Tipo de apertura clasificado (primeros 30 minutos) / open type classified (first 30 minutes)")
alertcondition(aCls and sday.code == 0, "Open type: Open-Drive", "La sesión abrió como Open-Drive / the session opened as an Open-Drive")
alertcondition(aCls and sday.code == 1, "Open type: Open-Test-Drive", "La sesión abrió como Open-Test-Drive / the session opened as an Open-Test-Drive")
alertcondition(aCls and sday.code == 2, "Open type: Open-Rejection-Reverse", "La sesión abrió como Open-Rejection-Reverse / the session opened as an Open-Rejection-Reverse")
alertcondition(aCls and sday.code >= 3, "Open type: Open-Auction", "La sesión abrió como Open-Auction / the session opened as an Open-Auction")