Gann Calendar: Financial Time Table, Decennial, Seasonal

BY_Tse · study · 233 行 · 点赞 16 · TradingView 原页

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

Pine Script

//@version=6
// Gann Calendar Tables: Financial Time Table, decennial digit, Gann seasonal windows, solar-year divisions
// Financial Time Table: Benner-derived chart attributed to Gann (1909); the attribution is unverified.
//   Codes come from alternating 19- and 18-year columns starting 1784. The offsets reproduce all 117 coded years
//   in the businesscycles.biz transcription of the chart (1785-2007); later years are a mechanical extension.
// Seasonal windows: Gann, Master Time Factor (course text, edition and page unverified).
// Solar-year divisions: Sun at k x 45 deg, pyswisseph Moshier, UT; 2027 equinoxes and solstices match USNO to 1 minute.
// Display tool only. No forecast claim attaches to any code or marker.
indicator("Gann Calendar: Financial Time Table, Decennial, Seasonal", shorttitle = "GannCal", overlay = true, max_labels_count = 100)
 
grpT = "Financial Time Table"
showFTT  = input.bool(true, "Shade years by FTT code", group = grpT)
fttShift = input.int(0, "User shift for years from 1989 on", minval = -3, maxval = 3, group = grpT, tooltip = "0 = chart as transcribed. A nonzero value is your own adjustment, not a sourced variant. A secondary source says Gann expected an adjustment by 1989; no adjusted table was found.")
cLow     = input.color(color.new(#4FC3F7, 80), "Low years (A, D, G, K/A)", group = grpT)
cHigh    = input.color(color.new(#00E676, 82), "High years (B, E, H)", group = grpT)
cPanic   = input.color(color.new(#FF5252, 80), "Panic years (C, F, J)", group = grpT)
grpD = "Decennial"
showDig  = input.bool(true, "Highlight years ending in digit", group = grpD)
digit    = input.int(7, "Digit", minval = 0, maxval = 9, group = grpD)
cDig     = input.color(color.new(#FFD54F, 82), "Decennial year color", group = grpD)
grpS = "Seasonal"
showWin  = input.bool(true, "Gann windows Jan 2-7, Jan 15-21, Jul 3-7, Jul 20-27", group = grpS)
cWin     = input.color(color.new(#FF4081, 60), "Gann window color", group = grpS)
showCard = input.bool(true, "Equinoxes and solstices", group = grpS)
showXQ   = input.bool(false, "Cross-quarters (Sun at 15 deg fixed signs)", group = grpS)
grpF = "Future"
showFut  = input.bool(true, "Shade future bars (daily, weekly, monthly charts)", group = grpF)
futBars  = input.int(500, "Future bars to shade", minval = 1, maxval = 500, group = grpF, tooltip = "500 is the furthest TradingView draws a shifted plot. About 2 years on a daily chart, 9.6 years on weekly.")
futDays  = input.int(730, "Equinox and solstice label horizon (days)", minval = 0, maxval = 3660, group = grpF)
grpX = "Table"
showTbl  = input.bool(false, "Table", group = grpX)
tblYear  = input.int(2026, "Table first year", minval = 1786, maxval = 2100, group = grpX)
 
// Sun at k x 45 deg (k = 0..7), unix minutes UT _ k
var array<string> SEA = array.from(
     "-44656399_7,-44591850_0,-44525692_1,-44458149_2,-44390276_3,-44323364_4,-44258074_5,-44194113_6,-44130447_7,-44065894_0,-43999744_1,-43932199_2,-43864336_3,-43797415_4,-43732128_5,-43668160_6,-43604498_7,-43539942_0,-43473795_1,-43406253_2,-43338381_3,-43271466_4,-43206169_5,-43142215_6,-43078550_7,-43014004_0,-42947848_1,-42880306_2,-42812429_3,-42745506_4,-42680217_5,-42616257_6,-42552602_7,-42488049_0,-42421900_1,-42354350_2,-42286484_3,-42219562_4,-42154270_5,-42090308_6,-42026649_7,-41962099_0,-41895948_1,-41828406_2,-41760532_3,-41693617_4,-41628316_5,-41564355_6,-41500692_7,-41436155_0,-41370008_1,-41302467_2,-41234595_3,-41167666_4,-41102371_5,-41038399_6,-40974744_7,-40910198_0,-40844063_1,-40776517_2,-40708644_3,-40641720_4,-40576423_5,-40512461_6,-40448796_7,-40384252_0,-40318105_1,-40250570_2,-40182693_3,-40115774_4,-40050475_5,-39986513_6,-39922847_7,-39858301_0,-39792158_1,-39724623_2,-39656761_3,-39589832_4,-39524536_5,-39460562_6,-39396902_7,-39332351_0,-39266213_1,-39198676_2,-39130810_3,-39063890_4,-38998584_5,-38934621_6,-38870956_7,-38806417_0,-38740267_1,-38672732_2,-38604858_3,-38537936_4,-38472639_5,-38408671_6,-38345011_7,-38280464_0,-38214321_1,-38146777_2,-38078914_3,-38011991_4,-37946698_5,-37882727_6,-37819064_7,-37754514_0,-37688371_1,-37620833_2,-37552961_3,-37486045_4,-37420743_5,-37356781_6,-37293113_7,-37228574_0,-37162430_1,-37094894_2,-37027020_3,-36960090_4,-36894793_5,-36830824_6,-36767169_7,-36702621_0,-36636485_1,-36568940_2,-36501069_3,-36434140_4,-36368840_5,-36304878_6,-36241220_7,-36176676_0,-36110530_1,-36042992_2,-35975114_3,-35908191_4,-35842886_5,-35778923_6,-35715262_7,-35650723_0,-35584581_1,-35517045_2,-35449178_3,-35382245_4,-35316942_5,-35252965_6,-35189309_7,-35124765_0,-35058635_1,-34991095_2,-34923224_3,-34856296_4,-34790987_5,-34727020_6,-34663356_7,-34598821_0,-34532681_1,-34465149_2,-34397268_3,-34330340_4,-34265035_5,-34201066_6,-34137404_7,-34072863_0,-34006726_1,-33939189_2,-33871323_3,-33804390_4,-33739090_5,-33675116_6,-33611456_7,-33546907_0,-33480772_1,-33413238_2,-33345368_3,-33278445_4,-33213133_5,-33149167_6,-33085501_7,-33020967_0,-32954826_1,-32887297_2,-32819424_3,-32752491_4,-32687184_5,-32623208_6,-32559553_7,-32495013_0,-32428882_1,-32361341_2,-32293473_3,-32226542_4,-32161238_5,-32097267_6,-32033607_7,-31969067_0,-31902929_1,-31835394_2,-31767518_3,-31700596_4,-31635287_5,-31571320_6,-31507653_7,-31443117_0,-31376981_1,-31309451_2,-31241583_3,-31174649_4,-31109347_5,-31045368_6,-30981710_7,-30917166_0,-30851040_1,-30783505_2,-30715636_3,-30648702_4,-30583393_5,-30519427_6,-30455766_7,-30391231_0,-30325093_1,-30257563_2,-30189683_3,-30122752_4,-30057441_5,-29993475_6,-29929817_7,-29865282_0,-29799145_1,-29731611_2,-29663744_3,-29596807_4,-29531502_5,-29467525_6,-29403871_7,-29339329_0,-29273200_1,-29205665_2,-29137795_3,-29070866_4,-29005549_5,-28941578_6,-28877915_7,-28813389_0,-28747257_1,-28679731_2,-28611852_3,-28544916_4,-28479602_5,-28415624_6,-28351966_7,-28287433_0,-28221310_1,-28153776_2,-28085905_3,-28018965_4,-27953658_5,-27889681_6,-27826022_7,-27761483_0,-27695354_1,-27627826_2,-27559950_3,-27493020_4,-27427703_5,-27363734_6,-27300067_7,-27235534_0,-27169402_1,-27101880_2,-27034013_3,-26967074_4,-26901761_5,-26837779_6,-26774121_7,-26709581_0,-26643458_1,-26575926_2,-26508062_3,-26441125_4,-26375809_5,-26311833_6,-26248174_7,-26183641_0,-26117509_1,-26049980_2,-25982102_3,-25915172_4,-25849855_5,-25785883_6,-25722220_7,-25657689_0,-25591556_1,-25524024_2,-25456157_3,-25389220_4,-25323915_5,-25259933_6,-25196274_7,-25131731_0,-25065607_1,-24998073_2,-24930203_3,-24863270_4,-24797955_5,-24733983_6,-24670320_7,-24605791_0,-24539662_1,-24472137_2,-24404256_3,-24337317_4,-24272000_5,-24208027_6,-24144370_7,-24079840_0,-24013714_1,-23946181_2,-23878308_3,-23811362_4,-23746051_5,-23682075_6,-23618423_7,-23553888_0,-23487762_1,-23420230_2,-23352353_3,-23285417_4,-23220094_5,-23156123_6,-23092462_7,-23027939_0,-22961812_1,-22894290_2,-22826416_3",
     "-22759473_4,-22694152_5,-22630167_6,-22566510_7,-22501981_0,-22435867_1,-22368338_2,-22300469_3,-22233523_4,-22168203_5,-22104222_6,-22040564_7,-21976036_0,-21909917_1,-21842394_2,-21774513_3,-21707575_4,-21642251_5,-21578276_6,-21514611_7,-21450085_0,-21383960_1,-21316439_2,-21248571_3,-21181628_4,-21116313_5,-21052327_6,-20988669_7,-20924130_0,-20858013_1,-20790487_2,-20722623_3,-20655684_4,-20590360_5,-20526381_6,-20462719_7,-20398194_0,-20332070_1,-20264552_2,-20196675_3,-20129737_4,-20064410_5,-20000430_6,-19936771_7,-19872246_0,-19806125_1,-19738597_2,-19670728_3,-19603784_4,-19538470_5,-19474486_6,-19410831_7,-19346297_0,-19280178_1,-19212648_2,-19144774_3,-19077839_4,-19012517_5,-18948543_6,-18884876_7,-18820352_0,-18754229_1,-18686712_2,-18618836_3,-18551895_4,-18486573_5,-18422591_6,-18358931_7,-18294402_0,-18228288_1,-18160762_2,-18092892_3,-18025942_4,-17960622_5,-17896643_6,-17832991_7,-17768462_0,-17702344_1,-17634818_2,-17566937_3,-17499994_4,-17434665_5,-17370693_6,-17307034_7,-17242515_0,-17176389_1,-17108868_2,-17040995_3,-16974047_4,-16908725_5,-16844738_6,-16781085_7,-16716557_0,-16650445_1,-16582916_2,-16515047_3,-16448101_4,-16382772_5,-16318787_6,-16255130_7,-16190612_0,-16124499_1,-16056981_2,-15989097_3,-15922151_4,-15856816_5,-15792834_6,-15729172_7,-15664656_0,-15598544_1,-15531024_2,-15463149_3,-15396194_4,-15330873_5,-15266885_6,-15203230_7,-15138700_0,-15072590_1,-15005067_2,-14937194_3,-14870247_4,-14804916_5,-14740936_6,-14677271_7,-14612749_0,-14546633_1,-14479124_2,-14411250_3,-14344304_4,-14278969_5,-14214980_6,-14151320_7,-14086797_0,-14020687_1,-13953168_2,-13885302_3,-13818348_4,-13753021_5,-13689031_6,-13625377_7,-13560851_0,-13494740_1,-13427218_2,-13359341_3,-13292398_4,-13227065_5,-13163085_6,-13099421_7,-13034903_0,-12968783_1,-12901268_2,-12833395_3,-12766450_4,-12701126_5,-12637136_6,-12573476_7,-12508947_0,-12442839_1,-12375316_2,-12307448_3,-12240499_4,-12175173_5,-12111187_6,-12047530_7,-11983007_0,-11916897_1,-11849381_2,-11781499_3,-11714551_4,-11649216_5,-11585237_6,-11521578_7,-11457063_0,-11390948_1,-11323429_2,-11255554_3,-11188598_4,-11123273_5,-11059287_6,-10995637_7,-10931112_0,-10865003_1,-10797477_2,-10729605_3,-10662654_4,-10597320_5,-10533337_6,-10469679_7,-10405165_0,-10339055_1,-10271544_2,-10203665_3,-10136716_4,-10071376_5,-10007387_6,-9943727_7,-9879214_0,-9813111_1,-9745595_2,-9677723_3,-9610763_4,-9545433_5,-9481440_6,-9417787_7,-9353266_0,-9287166_1,-9219648_2,-9151769_3,-9084816_4,-9019478_5,-8955497_6,-8891834_7,-8827320_0,-8761208_1,-8693700_2,-8625825_3,-8558874_4,-8493539_5,-8429549_6,-8365889_7,-8301367_0,-8235262_1,-8167746_2,-8099881_3,-8032925_4,-7967589_5,-7903596_6,-7839942_7,-7775425_0,-7709322_1,-7641809_2,-7573930_3,-7506979_4,-7441635_5,-7377649_6,-7313988_7,-7249480_0,-7183370_1,-7115856_2,-7047980_3,-6981025_4,-6915694_5,-6851701_6,-6788045_7,-6723524_0,-6657422_1,-6589900_2,-6522028_3,-6455074_4,-6389740_5,-6325751_6,-6262091_7,-6197574_0,-6131471_1,-6063963_2,-5996083_3,-5929131_4,-5863788_5,-5799800_6,-5736138_7,-5671626_0,-5605521_1,-5538010_2,-5470136_3,-5403172_4,-5337838_5,-5273846_6,-5210197_7,-5145677_0,-5079577_1,-5012058_2,-4944180_3,-4877221_4,-4811878_5,-4747894_6,-4684238_7,-4619728_0,-4553619_1,-4486110_2,-4418232_3,-4351278_4,-4285934_5,-4221941_6,-4158283_7,-4093770_0,-4027671_1,-3960156_2,-3892286_3,-3825325_4,-3759985_5,-3695985_6,-3632332_7,-3567820_0,-3501728_1,-3434216_2,-3366335_3,-3299377_4,-3234028_5,-3170038_6,-3106375_7,-3041870_0,-2975769_1,-2908263_2,-2840384_3,-2773423_4,-2708085_5,-2644090_6,-2580434_7,-2515915_0,-2449818_1,-2382304_2,-2314435_3,-2247474_4,-2182133_5,-2118140_6,-2054482_7,-1989967_0,-1923870_1,-1856367_2,-1788491_3,-1721537_4,-1656185_5,-1592192_6,-1528529_7,-1464023_0,-1397923_1,-1330417_2,-1262545_3,-1195582_4,-1130243_5,-1066244_6,-1002593_7,-938078_0,-871984_1,-804467_2,-736593_3,-669634_4,-604291_5,-540300_6,-476641_7,-412132_0,-346030_1,-278525_2,-210646_3,-143693_4,-78349_5,-14356_6",
     "49306_7,113816_0,179914_1,247423_2,315294_3,382259_4,447598_5,511596_6,575245_7,639758_0,705848_1,773360_2,841240_3,908205_4,973557_5,1037544_6,1101200_7,1165701_0,1231801_1,1299306_2,1367188_3,1434153_4,1499499_5,1563493_6,1627144_7,1691652_0,1757746_1,1825261_2,1893133_3,1960101_4,2025448_5,2089448_6,2153100_7,2217607_0,2283694_1,2351198_2,2419077_3,2486038_4,2551398_5,2615396_6,2679059_7,2743557_0,2809647_1,2877146_2,2945025_3,3011995_4,3077343_5,3141346_6,3204999_7,3269510_0,3335594_1,3403104_2,3470978_3,3537948_4,3603299_5,3667295_6,3730953_7,3795462_0,3861556_1,3929054_2,3996930_3,4063889_4,4129246_5,4193243_6,4256907_7,4321414_0,4387509_1,4455010_2,4522878_3,4589845_4,4655194_5,4719201_6,4782852_7,4847362_0,4913447_1,4980956_2,5048831_3,5115796_4,5181153_5,5245150_6,5308809_7,5373310_0,5439404_1,5506907_2,5574789_3,5641749_4,5707098_5,5771096_6,5834755_7,5899263_0,5965355_1,6032865_2,6100737_3,6167705_4,6233048_5,6297051_6,6360705_7,6425216_0,6491300_1,6558803_2,6626682_3,6693646_4,6759004_5,6822998_6,6886660_7,6951159_0,7017251_1,7084749_2,7152630_3,7219602_4,7284952_5,7348950_6,7412599_7,7477104_0,7543191_1,7610702_2,7678578_3,7745553_4,7810906_5,7874903_6,7938552_7,8003054_0,8069143_1,8136644_2,8204524_3,8271487_4,8336849_5,8400848_6,8464508_7,8529003_0,8595091_1,8662590_2,8730466_3,8797439_4,8862793_5,8926802_6,8990452_7,9054952_0,9121026_1,9188531_2,9256409_3,9323385_4,9388746_5,9452746_6,9516403_7,9580899_0,9646982_1,9714477_2,9782360_3,9849329_4,9914689_5,9978688_6,10042347_7,10106848_0,10172934_1,10240433_2,10308304_3,10375280_4,10440634_5,10504642_6,10568294_7,10632799_0,10698875_1,10766373_2,10834246_3,10901215_4,10966583_5,11030587_6,11094248_7,11158742_0,11224827_1,11292319_2,11360197_3,11427168_4,11492528_5,11556534_6,11620188_7,11684688_0,11750769_1,11818274_2,11886147_3,11953123_4,12018477_5,12082483_6,12146137_7,12210641_0,12276722_1,12344220_2,12412098_3,12479062_4,12544426_5,12608426_6,12672091_7,12736588_0,12802674_1,12870168_2,12938044_3,13005019_4,13070376_5,13134383_6,13198033_7,13262534_0,13328610_1,13396114_2,13463992_3,13530973_4,13596336_5,13660337_6,13723988_7,13788483_0,13854566_1,13922064_2,13989949_3,14056920_4,14122287_5,14186286_6,14249942_7,14314435_0,14380519_1,14448020_2,14515896_3,14582876_4,14648235_5,14712247_6,14775897_7,14840395_0,14906463_1,14973963_2,15041840_3,15108817_4,15174188_5,15238196_6,15301857_7,15366346_0,15432421_1,15499909_2,15567794_3,15634772_4,15700138_5,15764144_6,15827800_7,15892295_0,15958370_1,16025868_2,16093743_3,16160728_4,16226088_5,16290097_6,16353749_7,16418251_0,16484325_1,16551818_2,16619692_3,16686664_4,16752037_5,16816041_6,16879704_7,16944196_0,17010277_1,17077764_2,17145639_3,17212615_4,17277982_5,17341994_6,17405645_7,17470140_0,17536211_1,17603710_2,17671584_3,17738567_4,17803933_5,17867944_6,17931596_7,17996089_0,18062162_1,18129657_2,18197540_3,18264510_4,18329879_5,18393882_6,18457543_7,18522033_0,18588113_1,18655606_2,18723483_3,18790463_4,18855822_5,18919835_6,18983487_7,19047986_0,19114051_1,19181546_2,19249421_3,19316403_4,19381775_5,19445782_6,19509438_7,19573927_0,19640000_1,19707486_2,19775371_3,19842351_4,19907724_5,19971728_6,20035380_7,20099868_0,20165943_1,20233439_2,20301316_3,20368304_4,20433671_5,20497684_6,20561330_7,20625824_0,20691891_1,20759386_2,20827261_3,20894239_4,20959616_5,21023627_6,21087288_7,21151772_0,21217844_1,21285328_2,21353209_3,21420189_4,21485562_5,21549578_6,21613233_7,21677721_0,21743783_1,21811277_2,21879153_3,21946145_4,22011515_5,22075530_6,22139182_7,22203674_0,22269740_1,22337229_2,22405111_3,22472089_4,22537466_5,22601472_6,22665133_7,22729622_0,22795698_1,22863184_2,22931060_3,22998044_4,23063414_5,23127431_6,23191083_7,23255577_0,23321639_1,23389131_2,23457002_3,23523989_4,23589367_5,23653383_6,23717038_7,23781525_0,23847593_1,23915078_2,23982961_3,24049941_4,24115319_5,24179328_6,24242986_7,24307470_0,24373542_1,24441034_2,24508913_3,24575901_4,24641268_5,24705284_6,24768934_7,24833429_0,24899491_1",
     "24966984_2,25034860_3,25101842_4,25167218_5,25231228_6,25294888_7,25359375_0,25425445_1,25492927_2,25560811_3,25627794_4,25693172_5,25757183_6,25820834_7,25885318_0,25951383_1,26018874_2,26086753_3,26153750_4,26219124_5,26283139_6,26346783_7,26411270_0,26477331_1,26544824_2,26612706_3,26679691_4,26745074_5,26809082_6,26872739_7,26937217_0,27003287_1,27070772_2,27138654_3,27205641_4,27271019_5,27335039_6,27398691_7,27463173_0,27529226_1,27596714_2,27664589_3,27731584_4,27796965_5,27860988_6,27924643_7,27989124_0,28055179_1,28122658_2,28190543_3,28257530_4,28322916_5,28386927_6,28450587_7,28515066_0,28581130_1,28648611_2,28716489_3,28783484_4,28848860_5,28912881_6,28976530_7,29041021_0,29107077_1,29174562_2,29242432_3,29309419_4,29374804_5,29438823_6,29502482_7,29566966_0,29633029_1,29700505_2,29768383_3,29835365_4,29900752_5,29964770_6,30028426_7,30092905_0,30158965_1,30226451_2,30294327_3,30361322_4,30426699_5,30490722_6,30554371_7,30618857_0,30684912_1,30752402_2,30820281_3,30887265_4,30952647_5,31016660_6,31080321_7,31144802_0,31210868_1,31278348_2,31346232_3,31413219_4,31478597_5,31542614_6,31606268_7,31670752_0,31736806_1,31804291_2,31872167_3,31939167_4,32004549_5,32068570_6,32132218_7,32196701_0,32262755_1,32330237_2,32398123_3,32465115_4,32530506_5,32594516_6,32658169_7,32722642_0,32788706_1,32856189_2,32924073_3,32991071_4,33056454_5,33120476_6,33184122_7,33248603_0,33314654_1,33382141_2,33450016_3,33517012_4,33582401_5,33646426_6,33710081_7,33774557_0,33840609_1,33908084_2,33975969_3,34042960_4,34108354_5,34172374_6,34236032_7,34300503_0,34366555_1,34434033_2,34501914_3,34568919_4,34634304_5,34698331_6,34761980_7,34826463_0,34892509_1,34959992_2,35027869_3,35094863_4,35160255_5,35224273_6,35287932_7,35352410_0,35418469_1,35485942_2,35553823_3,35620813_4,35686204_5,35750228_6,35813884_7,35878361_0,35944411_1,36011889_2,36079761_3,36146762_4,36212151_5,36276182_6,36339833_7,36404312_0,36470358_1,36537837_2,36605718_3,36672710_4,36738103_5,36802121_6,36865780_7,36930252_0,36996309_1,37063786_2,37131670_3,37198665_4,37264049_5,37328073_6")
 
f_code19(int o) =>
    switch o
        1  => "A"
        5  => "B"
        7  => "C"
        8  => "D"
        11 => "E"
        12 => "F"
        13 => "G"
        15 => "H"
        16 => "J"
        => ""
 
f_code18(int o) =>
    switch o
        1  => "A"
        5  => "B"
        7  => "C"
        8  => "D"
        10 => "E"
        11 => "F"
        13 => "G"
        14 => "H"
        16 => "J"
        => ""
 
// column covers years s+1 .. s+L; K (s+L+1) coincides with the next column's A
f_ftt(int y0) =>
    int y = y0 >= 1989 ? y0 - fttShift : y0
    int s = 1784
    int L = 19
    string cd0 = ""
    if y > 1784
        while y - 1 >= s + L
            s += L
            L := L == 19 ? 18 : 19
        int o = y - s
        cd0 := L == 19 ? f_code19(o) : f_code18(o)
        if o == 1 and s > 1784
            cd0 := "K/A"
    cd0
 
f_codeColor(string c) =>
    c == "A" or c == "K/A" or c == "D" or c == "G" ? cLow : c == "B" or c == "E" or c == "H" ? cHigh : c == "C" or c == "F" or c == "J" ? cPanic : na
 
f_solid(color c) =>
    na(c) ? color.gray : color.rgb(color.r(c), color.g(c), color.b(c))
 
f_meaning(string c) =>
    switch c
        "A"   => "extreme low, new business generation"
        "K/A" => "K (as A, plus unemployment) and A"
        "B"   => "high stock prices"
        "C"   => "panic"
        "D"   => "low stock prices"
        "E"   => "high stock prices"
        "F"   => "panic"
        "G"   => "low stock prices"
        "H"   => "very high prices, most prosperous"
        "J"   => "major panic, 4 years falling"
        => "unlabeled"
 
f_win(int y, int m, int d1, int d2) =>
    int a = timestamp("UTC", y, m, d1, 0, 0)
    int b = timestamp("UTC", y, m, d2 + 1, 0, 0)
    time < b and time_close > a
 
// ---------- future bars ----------
// TradingView lays out future bars without holidays: weekdays on daily charts of weekday sessions,
// every calendar day when the symbol trades weekends, whole weeks and months on W and M charts.
var bool weekendBars = false
weekendBars := weekendBars or dayofweek(time, syminfo.timezone) == dayofweek.saturday or dayofweek(time, syminfo.timezone) == dayofweek.sunday
 
// noon (exchange time) of the date that the n-th future bar opens on; na on intraday charts
f_futTime(int n) =>
    string tz = syminfo.timezone
    int y0 = year(last_bar_time, tz)
    int m0 = month(last_bar_time, tz)
    int base = timestamp(tz, y0, m0, dayofmonth(last_bar_time, tz), 12, 0)
    int k = n * timeframe.multiplier
    int t = na
    if timeframe.isdaily and weekendBars
        t := base + k * 86400000
    else if timeframe.isdaily
        int wd = dayofweek(last_bar_time, tz) - dayofweek.monday
        int w = wd + k
        t := base + (int(math.floor(w / 5)) * 7 + w % 5 - wd) * 86400000
    else if timeframe.isweekly
        t := base + k * 7 * 86400000
    else if timeframe.ismonthly
        int mm = m0 - 1 + k
        t := timestamp(tz, y0 + int(math.floor(mm / 12)), mm % 12 + 1, 1, 12, 0)
    t
 
f_dayInWin(int t) =>
    int m = month(t, syminfo.timezone)
    int d = dayofmonth(t, syminfo.timezone)
    (m == 1 and ((d >= 2 and d <= 7) or (d >= 15 and d <= 21))) or (m == 7 and ((d >= 3 and d <= 7) or (d >= 20 and d <= 27)))
 
// does the future bar that opens at t touch a Gann window
f_futWin(int t) =>
    bool r = false
    if timeframe.isdaily
        r := f_dayInWin(t)
    else if timeframe.isweekly
        for i = 0 to 6
            r := r or f_dayInWin(t + i * 86400000)
    else if timeframe.ismonthly
        int m = month(t, syminfo.timezone)
        r := m == 1 or m == 7
    r
 
// ---------- load solar-year divisions ----------
var array<int> zT = array.new<int>()
var array<int> zK = array.new<int>()
var int zP = 0
if barstate.isfirst
    for c in SEA
        recs = str.split(c, ",")
        for r in recs
            p = str.split(r, "_")
            array.push(zT, int(str.tonumber(array.get(p, 0))) * 60000)
            array.push(zK, int(str.tonumber(array.get(p, 1))))
    while zP < array.size(zT) and array.get(zT, zP) < time
        zP += 1
 
bool hEq = false
bool hSol = false
bool hXQ = false
while zP < array.size(zT) and array.get(zT, zP) < time_close
    int k = array.get(zK, zP)
    hEq := hEq or k == 0 or k == 4
    hSol := hSol or k == 2 or k == 6
    hXQ := hXQ or k % 2 == 1
    zP += 1
 
// ---------- shading ----------
int yr = year(time_close, "UTC")
string code = f_ftt(yr)
color cc = f_codeColor(code)
bgcolor(showFTT and not na(cc) ? cc : na, title = "FTT year code")
bgcolor(showDig and yr % 10 == digit ? cDig : na, title = "Decennial digit")
bool inWin = f_win(yr, 1, 2, 7) or f_win(yr, 1, 15, 21) or f_win(yr, 7, 3, 7) or f_win(yr, 7, 20, 27)
bgcolor(showWin and inWin ? cWin : na, title = "Gann seasonal window")
plotshape(showCard and hEq, "Equinox", shape.diamond, location.bottom, #26A69A, text = "EQ", textcolor = #26A69A, size = size.tiny)
plotshape(showCard and hSol, "Solstice", shape.diamond, location.bottom, #FFA726, text = "SOL", textcolor = #FFA726, size = size.tiny)
plotshape(showXQ and hXQ, "Cross-quarter", shape.circle, location.bottom, #B0BEC5, text = "XQ", textcolor = #B0BEC5, size = size.tiny)
bool newYear = yr != yr[1]
plotshape(showFTT and newYear and code != "", "FTT code at year start", shape.labeldown, location.top, f_solid(cc), text = "FTT", textcolor = color.black, size = size.tiny)
 
// future: values computed on bar i are drawn futBars bars later, so only the last futBars bars carry them
int fn = bar_index + futBars - last_bar_index
int ft = showFut and fn >= 1 ? f_futTime(fn) : na
int fy = na(ft) ? na : year(ft, syminfo.timezone)
int fyPrev = na(ft) ? na : fn == 1 ? year(last_bar_time, syminfo.timezone) : year(f_futTime(fn - 1), syminfo.timezone)
string fcode = na(fy) ? "" : f_ftt(fy)
color fcc = f_codeColor(fcode)
bgcolor(showFTT and not na(fcc) ? fcc : na, offset = futBars, title = "FTT year code (future)")
bgcolor(showDig and not na(fy) and fy % 10 == digit ? cDig : na, offset = futBars, title = "Decennial digit (future)")
bgcolor(showWin and not na(ft) and f_futWin(ft) ? cWin : na, offset = futBars, title = "Gann seasonal window (future)")
plotshape(showFTT and not na(fy) and fy != fyPrev and fcode != "", "FTT code at year start (future)", shape.labeldown, location.top, f_solid(fcc), text = "FTT", textcolor = color.black, size = size.tiny, offset = futBars)
 
// ---------- future markers and table ----------
var array<label> futL = array.new<label>()
var table tb = table.new(position.top_right, 3, 8, bgcolor = color.new(#0A1628, 0), border_width = 1)
if barstate.islast
    for l in futL
        label.delete(l)
    array.clear(futL)
    int tEnd = timenow + futDays * 86400000
    if zP < array.size(zT)
        for i = zP to array.size(zT) - 1
            int t = array.get(zT, i)
            if t > tEnd
                break
            int k = array.get(zK, i)
            bool card = k % 2 == 0
            if (card and showCard) or (not card and showXQ)
                string nm = card ? (k == 0 ? "Aries ingress" : k == 2 ? "Cancer ingress" : k == 4 ? "Libra ingress" : "Capricorn ingress") : "Sun " + str.tostring(k * 45) + " deg (cross-quarter)"
                array.push(futL, label.new(t, close, card ? "☉" + str.tostring(k * 45) : "XQ", xloc = xloc.bar_time, color = card ? #26A69A : #78909C, textcolor = color.white, style = label.style_label_down, size = size.tiny, tooltip = nm + "\n" + str.format_time(t, "yyyy-MM-dd HH:mm", "UTC") + " UT"))
    if showTbl
        table.cell(tb, 0, 0, "Year", text_color = #C9A84C, text_size = size.small)
        table.cell(tb, 1, 0, "FTT", text_color = #C9A84C, text_size = size.small)
        table.cell(tb, 2, 0, "Meaning (chart legend)", text_color = #C9A84C, text_size = size.small)
        for j = 0 to 5
            int y = tblYear + j
            string cd = f_ftt(y)
            table.cell(tb, 0, j + 1, str.tostring(y) + (y % 10 == digit ? " *" : ""), text_color = color.white, text_size = size.small)
            table.cell(tb, 1, j + 1, cd == "" ? "-" : cd, bgcolor = na(f_codeColor(cd)) ? color.new(#0A1628, 0) : f_solid(f_codeColor(cd)), text_color = color.black, text_size = size.small)
            table.cell(tb, 2, j + 1, f_meaning(cd), text_color = color.white, text_size = size.small)
        table.cell(tb, 0, 7, "Note", text_color = #C9A84C, text_size = size.tiny)
        table.cell(tb, 1, 7, "", text_color = color.white, text_size = size.tiny)
        table.cell(tb, 2, 7, "* = decennial digit " + str.tostring(digit) + ". Gann attribution unverified. Benner rows tested: underperformed buy and hold.", text_color = color.white, text_size = size.tiny)

← 返回列表