本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// Decennial and 20-Year Analog Composite (DJIA weekly closes 1885-2019)
// Source: S. H. Williamson, Daily Closing Value of the Dow Jones Average, MeasuringWorth 2019 (fja05680 mirror),
// 36,863 daily rows 1885-05-02 to 2019-12-24, reduced to 7,027 weekly closes (Monday-start weeks, last close),
// stored as ln(close) x 10000, delta encoded.
// Each analog path = ln change from the analog's own year-end week; composite = mean over analogs; shown as percent.
// Modes: Decennial = all earlier years with the same last digit (E. L. Smith 1939). 20-year calendar = Y-20k (Gann).
// 20-year synodic = shifts of k x 7253.45 days (mean Jupiter-Saturn synodic period).
// Diagnostic in the table is unregistered and in-sample to this file. It is not a protocol verdict.
indicator("Decennial and 20-Year Analog Composite (DJIA 1885-2019)", shorttitle = "AnalogComp", overlay = false, max_polylines_count = 4, max_labels_count = 10)
mode = input.string("Decennial (same last digit)", "Composite", options = ["Decennial (same last digit)", "20-year calendar (Gann)", "20-year Jupiter-Saturn synodic"])
kMax = input.int(6, "Max analogs, 20-year modes", minval = 1, maxval = 7)
projYear = input.int(2027, "Projection year", minval = 1886, maxval = 2040)
showAct = input.bool(true, "Actual YTD percent of chart symbol")
showTbl = input.bool(false, "Table")
// first value = ln(close) x 10000 of week 0; then weekly deltas
var array<string> DJW = array.from(
"34479,-93,-36,145,-257,-45,163,256,-240,-153,345,531,-137,143,98,311,82,-257,-154,-123,283,-183,280,452,302,121,208,75,162,100,-23,46,-435,297,-39,55,-99,-456,-139,261,191,308,-356,-16,79,-230,-23,-197,-22,122,-98,60,-328,110,71,106,212,-60,112,314,-97,72,-147,34,29,180,40,-86,-51,-13,92,143,211,124,-93,55,132,-41,123,7,12,48,22,130,-251,-333,-92,263,-211,108,-55,-181,102,155,-49,43,-23,-31,64,76,84,103,-43,6,5,-67,144,77,-79,-10,-79,-64,-295,42,-183,-7,-1,-510,327,35,-124,-208,419,-169,-215,-164,176,-263,-448,285,-40,208,77,263,24,-131,-140,-38,68,58,27,23,-112,145,-196,-9,124,-74,-140,-96,-119,-129,-286,322,-60,247,320,-64,-162,18,-206,-71,-8,8,73,-72,178,341,-16,80,142,169,-247,202,84,153,-350,126,256,-180,58,-26,-53,-8,39,-99,-115,-111,-119,55,251,106,-57,119,-75,-1,188,-60,76,-78,25,-185,-110,0,-75,196,74,-31,80,62,-38,133,191,29,47,29,-38,-120,-189,24,-179,103,98,185,45,-121,276,187,-14,-45,43,-123,0,-125,113,-86,11,170,-29,-242,168,1,59,-151,194,-14,-116,137,23,-31,-145,-84,-62,52,76,-24,-41,56,-87,195,285,149,178,129,4,-94,30,-86,-193,-26,54,-13,12,-19,-105,-237,213,-274,198,-144,-201,111,-214,-247,-40,48,-185,-57,-471,-756,566,30,-785,438,2,-88,389,369,5,-237,55,299,-103,14,-28,-293,184,-107,71,127,198,35,298,-21,-354,-130,193,-128,-108,61,-72,-334,195,144,-168,-163,-75,56,228,239,501,177,-14,318,-85,-60,-76,-34,69,-125,-253,131,112,-7,-22,-2,200,187,71,-64,-51,-42,35,71,152,-83,51,126,24,-68,-158,-190,190,165,-165,-4,16,-186,-76,87,-133,21,31,50,-32,-108,-18,93,178,-34,-87,-52,74,-333,26,-178,128,-3,124,144,-73,-1,15,-30,-130,-235,-22,146,-279,-34,166,-70,254,214,-83,-34,-198,-156,-410,-13,-138,-17,186,112,33,-279,-220,66,-512,-599,530,-280,-303,368,-175,-169,-80,-149,-427,-712,-883,905,-213,-261,362,669,284,-117,-104,-6,48,-337,435,842,-345,-113,-49,347,63,-388,-59,-440,-203,349,-259,360,37,46,-93,-22,-24,193,115,113,33,165,28,-64,-81,-131,-22,-23,-433,193,-86,152,-173,-241,52,-137,232,-38,-144,136,121,533,159,-86,-57,-71,-105,-298,56,-131,15,-220,14,484,-417,-42,-129,102,32,-107,-123,-153,196,47,-237,130,-182,-78,-20,-185,27,122,431,153,-159,194,273,125,42,625,-70,17,-128,-26,206,-65,-78,100,-59,93,292,31,31,-16,69,288,87,-586,384,14,-138,15,-79,-125,-313,-254,214,-177,70,-28,-39,-1602,636,-185,25,-61,395,283,255,-72,205,-265,26,-55,-162,-88,152,-44,134,202,-45,-146,-151,153,-132,-35,11,55,-317,-353,203,-1000,126,-182,-1062,779,-109,199,575,-95,10,469,-70,-386,101,540,161,735,-34,-277,-135,117,-166,-493,100,9,39,459,-189,128,-271,-419,216,272,-96,234,-249,-428,93,100,-307,-137,49,227,-242,79,236,279,366,75,187,42,111,255,514,-8,787,33,-25,240,469,11,-65,-567,55,-330,-461,218,-128,-568,171,23,-8,218,256,-131,112,4,242,-294,-55,138,134,-18,-480,-564,124,-549,352,-431,377,209,-224,4,320,914,55,141,143,188,25,-330,159,122,90,-210,159,185,314,160,390,265,-49,-337,-38,-109,-911,142,-261,212,323,33,394,-56,-57,340,280,-231,227,72,136,13,121,424,-231,-204,418,417,-117,212,550,53,373,-271,423,92,-39,-382,-625,342,-320,88,322,-156,-190,101,143,-77,77,182,146,229,35,-59,20,163,-461,44,-135,-26,-115,212,194,13,-252,385,-17,-16,-886,-815,-526,871,-9,-187,5,-87,546,-181,-128,-260,-215,-173,132,277,271,19,-268,-630,216,-69,-543,10,-108,214,-415,-177,-319,231,198,-27,443,-122,0,67,103,-89,-62,12,-231,-569,156,226,191,509,91,-47,1059,328,-287,-61,-363,301,602,24,-365,-48,-392,291,153,356,3,-235,-130,-54,25,198,158,295,225,269,-174,74,-441,301,-33,396,-68,177,36,29,-173,-752,38,191,-205,-265,235,372,-31,-624,-261,362,-340,-599,317,44,-110,-40,127,70,-67,-103,-320,-118,143,101,130,-89,-75,56,177,-15,-42,48,23,72,-2,259,-15,-55,-77,192,2,-206,-45,-168,299,-60,-141,85,-194,-142,159,-68,244,83,-115,105,-4,-106,73,42,-39,164,-167,-87,-288,408,-9,-97,-451,-208,204,-132,-51,-310,332,290,150,184,-119,-118,134,196,87,32,-161,-316,28,212,-348,-185,7,288,-55,11,-49,-136,-208,-186,-298,75,-313,90,99,-407,-326,-974,335,-687,1115,-256,294,-236,-220,-463,-488,286,-612,80,-132,145,-319,-134,234,-2,425,-6,278,89,-78,134,13,373,-202,-261,96,-168,-49",
"43,-186,494,-113,178,116,-55,-52,-66,-43,-181,71,42,-19,196,-47,47,38,306,321,121,-192,147,211,-126,207,125,405,-149,-15,271,29,641,144,246,109,441,263,219,180,-399,-222,0,165,-55,210,-79,96,100,250,121,256,-2,205,-58,208,223,218,81,-265,-620,12,166,-561,-43,71,169,-178,312,234,254,-100,-81,327,137,31,16,57,-357,-87,261,82,15,15,-68,166,-161,173,-82,273,281,290,367,344,-109,120,92,275,289,-84,-207,-1,-332,38,-317,261,-129,-35,228,-40,47,-184,-712,117,370,-49,51,131,-41,-321,-130,-321,110,-297,358,365,-14,39,353,78,-175,9,108,-3,-69,109,17,-348,76,75,-91,200,-67,63,3,28,-213,19,268,-41,-339,15,-245,181,114,-142,-248,-542,-143,-607,175,495,-239,105,102,65,-197,-17,-459,-136,252,-287,-28,370,265,-129,-16,-15,-342,-681,-554,-16,428,176,-742,310,-478,22,-767,-610,-58,-159,-160,-470,208,598,435,-622,365,-107,341,544,28,-426,11,-317,-123,173,56,435,445,173,210,-227,195,-4,215,17,244,380,-290,46,124,-105,-26,-68,124,299,383,172,116,523,-395,83,273,-121,-135,-468,75,243,-55,74,138,6,615,37,-219,166,-109,-24,-324,232,69,-106,-6,61,-205,65,185,-402,-118,44,-22,36,288,141,212,-15,54,23,360,-81,75,73,245,-44,-310,22,191,-17,129,14,258,173,79,-104,-149,173,-234,296,9,134,-252,65,-303,346,26,-17,87,-224,28,39,58,-43,44,-120,-355,7,-225,-445,76,230,-55,255,-22,-69,-90,-177,-39,358,-277,-441,60,274,59,-203,-561,39,124,97,-433,-55,-14,-495,-89,221,235,49,-157,-64,-14,10,-18,182,193,451,78,-114,100,-268,219,-11,-546,95,-14,-12,4,169,39,55,43,251,-53,-31,-115,-304,72,115,10,-4,-40,-31,-181,282,-73,-43,403,-8,19,20,38,9,-96,39,-27,49,-64,-386,-276,121,-305,30,-63,25,-689,359,29,274,-116,-312,393,273,70,51,-105,-159,380,-45,-53,56,-46,68,-128,-108,-31,87,39,97,179,128,449,-14,195,-99,8,180,-228,91,83,5,-229,238,-102,124,30,-65,-255,185,-28,53,67,72,23,19,-13,-91,236,130,-6,-142,90,-251,-69,-16,-23,40,96,-397,-237,223,-66,71,-9,-223,-402,153,-12,-257,-185,86,-117,6,-187,359,192,-63,-143,-198,-12,-43,-33,147,-189,-444,72,-199,167,73,-28,173,197,-27,115,86,30,213,-50,246,-104,-75,-167,-290,-37,74,-20,-221,65,-139,-27,57,-63,224,139,-34,91,203,173,81,-41,70,-69,-31,-120,81,131,-167,52,-95,-178,-369,365,-34,157,72,21,-11,11,-7,-174,144,-3,-84,-112,-1093,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,430,106,-343,239,343,115,230,-235,-147,154,-356,-4,220,-10,184,377,312,578,661,5,265,-1303,-135,561,-128,584,367,5,-63,-164,-171,495,319,155,180,272,-265,654,-129,-62,351,416,579,-148,294,293,-9,-194,121,-32,213,-30,-28,110,80,80,-165,-100,-199,-292,158,291,-144,-213,-141,154,303,-267,49,-41,-198,-739,552,81,131,11,-21,-9,127,-87,-291,-38,66,-244,270,-107,-27,217,157,106,-67,345,256,331,157,48,-437,483,91,105,74,315,-17,-289,-107,-642,-465,42,182,-169,295,-130,-722,175,124,-52,152,330,-58,156,-240,-245,70,-301,182,-268,-64,302,549,1,151,-217,67,-179,-167,-183,4,-54,92,-125,-42,-262,-657,-26,-17,178,-85,-298,-443,250,-112,-872,-283,15,431,-89,-356,-403,103,600,178,98,55,205,426,-99,138,-25,-113,92,-92,-353,63,159,-252,477,-237,93,403,185,-266,-406,157,255,91,89,62,-249,139,-97,-73,140,-65,161,1,9,-173,102,183,121,-5,467,-134,-285,326,-312,-422,-85,192,31,-130,-42,182,-168,-90,49,-96,-176,349,271,-20,377,47,111,25,86,-4,227,88,246,353,193,148,377,193,-454,351,64,255,73,-2,37,-284,-344,-202,-79,321,149,184,-310,471,18,368,-104,-42,510,-264,-508,-128,-455,360,-167,-101,145,352,-329,-373,21,114,-770,-202,150,-462,348,491,420,-16,-72,247,-74,-869,-234,128,-305,-388,405,21,102,-138,-114,145,214,-429,-44,-339,-322,173,150,-30,166,-122,320,-393,-216,-10,64,71,-72,-249,-747,-380,191,284,-745,-355,-92,432,388,46,-31,189,-170,71,45,-62,-28,-336,509,74,-244,61,79,235,88,81,-292,-202,-179,-239,-401,-358,89,73,28,-162,262,-53,-44,-267,-252,72,365,561,-153,-3,122,-71,-153,144,389,-3,340,78,102,146,146,51,-120,186,-247,263,159,-95,225,-78,157,-113,305,232,62,-159,227,173,264,43,-77,91,-71,184,86,88,-329,-189,185,-28,68,193,45,109,20,1,201,105,123,38,-123,-134,-286,427,287,-144,-326,38,-326,-54,-275,332,187,42,50,11,-98,134,-150,40,134,236,148,-35,160,-66,102,-155,-51,-19,-45,-98,-46",
"-396,-138,-74,289,-179,140,-247,-152,-602,176,-1,220,-454,-15,217,354,-80,177,-32,-426,-57,-74,158,-245,80,-238,441,194,-192,324,59,75,146,-169,169,108,102,-67,346,83,4,-283,-19,-40,78,-23,-238,-366,190,-354,39,97,-10,-151,-136,148,-84,-42,365,73,213,92,121,50,229,249,-79,245,-106,158,-428,120,182,8,-104,-149,42,28,206,130,294,80,165,-25,149,318,235,251,-4,79,-12,20,-141,-53,82,70,184,-66,-374,-280,166,91,223,-188,183,217,148,184,85,-85,42,-17,44,137,-7,244,70,-80,252,160,188,-113,3,324,121,-238,164,54,31,370,197,124,-134,-344,46,186,2,-94,245,97,35,-246,-4,145,161,130,-71,-411,-302,14,-357,-408,98,-33,-224,569,-100,-223,-159,172,212,134,221,313,-174,227,59,239,-269,373,291,86,-234,-55,114,-97,-269,89,23,-544,-291,183,55,174,101,-41,160,166,53,122,-87,-205,-86,-55,11,1,-55,111,169,132,-100,94,-10,-1,7,125,177,73,-157,225,31,211,29,-140,28,-46,-107,74,158,170,180,250,-6,-175,354,186,103,238,94,-45,78,-416,-5,-563,30,442,295,139,8,18,-48,180,17,104,-21,-200,25,21,-119,133,-376,66,121,243,188,245,201,-57,141,-199,78,237,141,-142,5,147,-556,-157,-120,350,142,-275,49,335,36,-64,379,496,227,31,-46,-49,25,30,367,183,70,-53,439,438,380,89,-1222,507,547,389,171,-39,156,277,164,-587,-190,469,288,-238,265,-440,86,-198,53,216,147,355,-76,-97,-548,-173,199,295,251,352,321,37,-2,-62,340,-308,449,401,129,-73,-283,-161,-395,-169,327,-853,-800,-890,-1452,-336,718,-280,976,-404,-721,127,428,-6,-76,484,354,51,-20,-128,276,80,-191,227,347,130,119,22,-297,-999,516,15,-40,137,-647,-541,-1262,176,151,300,319,153,-244,-522,241,277,253,133,-136,-447,-784,-67,-894,-410,426,-447,-657,753,73,-251,-277,-881,366,-554,712,-24,-527,415,-133,314,425,587,-87,-311,-169,245,-623,-94,-259,-342,-662,-299,255,-568,-360,-709,112,534,140,1216,-107,-761,-102,-298,-116,-126,774,-567,309,-689,-684,-1029,-400,-1461,1297,-321,700,-397,921,-834,-877,-790,14,-1328,228,-628,-162,694,542,-795,-233,-231,1422,-264,-189,759,-459,-791,-313,-597,-1005,-171,-680,-540,338,-1007,106,-1061,646,-529,-148,-605,-83,-642,843,548,1259,2043,-520,613,1182,353,-231,-1415,1189,-373,-1642,486,-539,202,51,864,-590,-854,-534,927,-188,-361,331,493,21,-209,-176,-534,321,-587,-956,555,0,1176,-482,-361,633,586,1388,723,-6,409,-80,1109,45,478,-454,585,534,411,90,-1823,669,-205,510,87,664,-135,-417,576,-540,-510,350,-269,-1336,954,117,318,264,61,-21,382,-484,-2,188,-301,176,672,48,314,-367,336,-402,75,-268,-110,-72,92,170,138,123,-328,-468,-628,310,-8,-390,787,96,-332,-91,149,190,-454,-644,-33,153,118,520,-326,-197,-392,419,169,24,218,13,-230,223,438,25,292,51,-9,-196,-110,409,159,-314,64,-44,-30,45,182,-124,-3,-200,-341,208,96,219,229,403,-7,104,289,44,114,-546,444,381,131,-212,235,70,67,208,50,161,1,-2,-3,305,117,-353,228,-107,244,260,315,-19,221,202,-81,-261,148,-287,-14,41,233,182,-123,142,173,55,132,88,-104,368,-243,151,-56,376,-63,-279,-269,-370,98,239,-51,131,-185,315,165,79,-22,164,227,69,-8,220,-194,-226,290,53,13,54,-51,256,208,89,-97,72,344,-106,31,71,-124,-7,-185,55,-4,234,162,51,-51,74,155,-35,-110,359,-185,-349,49,-77,-292,126,-198,-145,64,-345,314,-17,17,-319,-54,-9,222,258,168,281,41,43,192,-336,-434,-194,-758,-134,-679,439,-682,-544,-695,831,-982,604,-995,267,325,-76,-15,57,-524,794,262,-327,-788,225,166,203,291,-278,-406,-177,-1217,-49,832,481,-282,-556,520,0,-344,-392,265,213,-88,1529,488,-170,170,404,-210,308,-670,359,53,37,-298,-480,91,733,452,146,141,-200,70,405,-520,-130,-64,55,137,68,221,-211,-218,-102,-558,442,-32,62,90,180,152,-688,-9,-636,-897,651,-82,-8,253,50,-89,416,24,217,-350,150,-418,114,342,483,-49,-132,-263,-242,94,124,888,82,55,-30,-194,52,228,-48,-50,-216,162,-193,-137,89,97,32,26,63,-405,31,60,-63,221,-8,-136,-26,123,-162,66,83,210,-95,-134,30,-38,-185,-1682,-647,79,-26,670,-43,-78,-23,-10,33,47,314,50,-402,282,310,256,-337,312,-10,119,-216,87,6,194,239,-248,-245,-36,22,77,-261,94,174,90,-292,-61,-450,115,-507,142,134,-32,157,-120,36,159,-471,-209,24,-76,171,-123,46,-76,267,261,39,72,63,288,14,56,-38,-142,-108,69,141,-35,2,20,-119,6,-279,-209,53,-220,13,-131,27",
"-243,205,-516,-267,-25,561,-286,12,-114,-28,41,-209,-180,133,-429,-264,117,-81,110,-165,-258,-273,223,232,-7,62,163,355,-42,32,-169,176,395,-93,-109,-59,-95,140,86,-83,25,-45,96,194,183,317,-134,141,-82,247,-58,-75,-37,25,50,250,81,18,-38,176,64,258,19,159,-2,179,48,-1,-123,412,77,-297,148,56,137,158,-77,107,233,72,-124,-113,223,57,37,34,-51,-574,-42,136,-79,-27,113,51,208,-54,7,-229,94,-7,-2,-221,-261,89,-128,47,255,45,26,-26,161,22,-11,-79,-149,21,37,49,15,264,-10,-80,-25,19,-75,-136,2,192,-19,55,134,77,14,327,14,66,105,31,-332,39,-74,102,163,-131,9,-265,73,98,65,148,-22,-16,-126,59,49,-141,42,59,255,81,-126,112,82,130,-187,93,41,6,215,30,64,-158,97,-280,3,124,216,214,92,121,-167,150,-2,93,-66,41,42,-177,-38,121,-253,-98,132,127,-46,330,255,154,-76,216,123,167,51,-6,-11,170,147,47,-310,317,143,-73,-161,114,-72,408,39,-18,350,-228,103,-439,-359,299,-27,212,84,258,51,98,-93,-177,270,-109,91,219,-110,19,-352,124,54,-123,-151,-176,259,37,-142,-148,-442,-501,-372,-252,293,-297,-61,198,-170,240,-43,-162,-235,280,71,215,204,-144,65,-95,38,-32,310,198,-171,49,-164,-194,-200,281,61,-93,-284,-195,41,284,-135,-506,228,136,60,302,54,7,288,166,-9,96,-139,-202,50,-72,-50,-96,-69,125,-185,258,59,206,-83,-14,-54,-68,114,-162,-206,203,95,-101,100,-46,-166,-319,195,-305,-215,85,-18,97,-78,323,48,199,114,50,155,-161,123,415,-13,39,-29,145,-68,-87,3,82,-303,-32,-217,92,-186,219,-22,62,-205,-30,-44,84,72,155,280,-83,-526,-262,176,-258,190,72,-102,98,-7,230,-126,133,-122,-211,-211,150,-168,191,115,-50,-14,60,-8,18,-188,23,70,-11,-98,-113,-254,-158,-51,194,65,168,149,60,79,178,12,104,-107,8,48,115,-56,37,184,54,-9,221,53,-48,165,-20,62,13,168,45,63,90,-252,204,-45,245,-82,30,9,27,-86,250,121,-204,295,90,-27,20,125,35,210,-31,90,139,-184,73,-703,-25,-429,384,26,212,111,193,-51,14,74,261,35,-13,238,-182,142,-101,-50,82,102,146,-324,-11,45,140,165,222,121,134,18,262,35,-4,-70,20,-56,-119,-36,-8,94,233,-46,158,103,-173,-261,-194,142,42,145,-246,-213,299,171,-23,214,144,-41,161,5,147,134,79,-144,-35,160,-15,-284,-338,40,66,-18,-188,245,174,-54,18,96,102,-20,81,28,-43,-99,-132,-185,-44,148,11,47,124,-133,32,-234,5,11,75,-101,128,-11,192,20,60,83,92,-27,-11,138,75,1,-88,-107,22,53,-200,-17,51,-51,2,-123,-69,141,156,-7,219,154,-57,111,46,60,134,-159,-12,-10,100,-242,9,-43,84,20,147,22,-82,-257,-163,-40,-115,161,92,-11,9,-214,-146,-95,0,122,55,19,-3,-45,207,5,6,-138,-230,-53,-176,-36,173,128,13,213,93,17,109,-47,-53,150,88,-99,129,-93,-1,22,183,102,94,54,0,-99,118,165,9,58,-79,251,88,141,-13,188,62,37,111,43,4,-171,179,140,153,106,-38,103,129,-141,104,107,-170,-40,137,213,177,-49,107,-295,152,-182,386,299,24,256,46,13,123,56,181,-220,24,-16,219,125,102,-57,-52,246,-453,91,244,-22,105,171,2,3,-42,-102,79,65,68,212,144,109,108,161,-21,97,25,-205,13,-76,221,189,44,189,78,-437,-265,-216,305,-79,271,195,132,0,-4,102,-115,93,37,-56,-80,-368,47,230,-207,199,179,65,183,194,106,-24,179,-214,-55,95,86,-299,-97,-494,171,-112,221,42,99,228,137,67,-44,154,-55,-31,-154,-116,93,-128,-201,-313,150,160,-83,-2,91,-105,-97,-170,4,455,-55,47,41,36,-88,-337,18,-23,-232,38,-24,42,58,56,-28,39,59,189,27,71,122,15,145,-31,18,14,121,-233,66,266,75,-97,-22,-186,-167,-174,-258,179,-119,50,-265,-250,105,-455,-167,30,-10,-14,120,75,162,-60,-151,-306,132,266,-133,123,146,-14,-28,-97,-109,7,260,34,-12,-86,-183,17,181,124,102,65,-119,86,36,148,109,-24,38,99,56,76,308,73,93,-79,42,7,81,129,135,7,130,179,55,-126,68,201,187,-91,-38,-13,99,192,-8,256,87,51,6,-36,-198,97,239,21,100,84,-70,-63,88,-98,294,54,-38,-59,210,3,142,-217,-41,37,150,240,133,-97,100,166,-94,-148,-51,117,-166,-230,-183,108,63,6,98,-159,211,67,-143,59,108,175,97,92,-89,129,-54,-240,-212,-367,67,-73,100,56,-358,-65,173,98,-105,195,32,-221,-240,97,138,148,-7,67,404,-62,-59,-89,87,-261,-329,112,-39,191,50,108,-173,-179,-196,-286,-87,107,170,-322,6,310,208,-83,48,-175,247,112,-74,44,93,191,11,145,144,-205,185,61,240,-120,193,-59,61,104,146,-123,-96,175,-40,259,-138,20,46,-223,46,-68,127,-25,-119,322,218,27,13,-95,62,-4,-64",
"-208,-5,100,-70,33,-98,149,217,65,42,-52,-8,16,-117,141,-225,-44,-156,-122,205,109,30,-97,21,48,109,-81,-133,-104,-170,92,-322,-15,-466,155,-615,-13,-156,-397,-698,401,262,240,-222,134,193,-69,295,61,-75,-137,82,-235,-218,130,-2,-227,-75,606,190,238,217,69,43,-62,-26,78,164,141,13,107,51,-48,90,-65,-327,191,58,22,69,287,86,45,77,13,72,21,-59,89,-63,-5,-18,-194,134,-123,-197,-65,122,150,153,53,85,83,64,47,-76,96,-45,119,66,-25,-38,-145,-393,534,128,-1,26,11,62,86,18,94,29,79,38,30,40,73,126,-16,12,86,-15,68,-151,27,139,-28,-65,-4,-179,42,194,69,126,71,45,-67,-54,-143,116,-2,5,109,220,-23,110,-24,62,-51,46,-52,44,-32,188,-97,-127,-76,50,-6,68,97,96,27,104,-15,-146,-32,200,-84,49,-51,-46,19,88,117,50,64,110,76,-189,-44,-188,-215,-29,-286,240,49,11,-189,204,9,71,12,68,133,120,109,6,1,93,25,124,88,-14,-33,-38,-48,-22,70,54,88,30,173,12,8,-28,10,27,-140,-231,-219,-47,-55,76,15,154,21,22,-172,-336,-300,9,227,-103,44,28,32,-226,192,-53,-230,-254,59,-140,-436,-304,91,-155,487,-290,-214,-394,361,200,259,-36,173,-119,-75,-174,294,-73,-100,-169,289,321,143,-37,158,-20,-58,-41,-9,23,247,79,-122,-147,74,269,156,99,-177,-176,-48,-81,133,115,-87,-197,102,148,308,-89,244,-34,-18,-275,79,70,282,10,-83,22,-114,-236,-96,-362,72,-8,178,18,91,-75,77,198,-43,-25,-210,-175,-17,-277,-44,160,-111,-62,28,-138,175,295,450,-89,93,144,-69,-153,-42,42,175,-14,-140,-35,64,207,-93,-282,-195,-19,185,72,42,277,-44,79,101,203,-36,187,-64,-135,111,71,13,184,-69,31,-147,-151,-7,-280,107,33,79,19,43,-378,-125,65,-76,173,167,-88,66,-93,-9,353,46,59,-207,-105,-138,-329,-211,-73,187,-390,-75,-335,104,-26,-43,197,-6,-208,58,74,-75,-193,-18,354,309,-73,52,-131,-313,-132,-240,-81,41,98,143,-138,-196,-90,-415,117,7,55,262,84,-155,-110,353,10,-18,-185,-376,-185,-219,-219,-587,562,-77,-157,515,-462,18,158,488,-67,54,-116,-207,475,270,70,-122,-44,43,58,33,-70,-52,-50,214,-159,24,256,435,120,-38,68,126,-23,104,183,83,92,139,-116,3,216,3,161,-103,-5,190,213,80,-64,-50,-10,-153,-154,157,-62,-302,-142,153,130,-149,-8,-336,-91,63,287,304,51,-20,-30,-211,53,-1,-219,-257,-158,17,-332,-28,72,514,-34,198,84,101,225,-41,8,-11,3,120,-1,57,211,-28,32,-6,-17,230,53,-40,-101,-136,6,207,101,-102,-284,112,-3,-168,97,-170,-19,67,267,130,17,-67,110,-91,-146,-45,108,-83,-159,132,38,390,113,103,194,-13,90,-58,-226,156,266,-78,-128,-223,-229,-14,-2,-200,15,113,-95,-428,302,-212,300,40,-435,337,-275,-360,391,-404,287,-348,-99,134,-245,181,277,280,-302,-183,-233,-96,275,124,-138,458,205,252,76,-154,239,-539,-291,-190,-428,-379,191,-271,38,351,373,-450,165,45,-181,-283,-1,426,-48,302,111,-110,-365,10,-32,177,-298,134,54,-379,-27,-179,623,-125,-334,-161,-133,-58,9,-43,-416,323,-606,-632,-120,-10,-778,672,-755,-620,1186,-50,-290,447,28,-297,-512,55,-687,259,96,61,524,375,-217,335,541,117,308,210,-144,411,44,-136,94,-303,550,237,42,441,20,-148,-69,5,88,-183,369,205,-16,-8,-100,-334,-91,-107,97,-257,373,8,-325,251,-136,-66,131,99,100,-53,-3,211,-152,234,-499,170,138,181,-13,593,201,258,221,-211,36,303,-155,3,150,-79,238,-119,-238,125,205,-39,-6,-36,-19,-158,-117,153,233,-20,0,33,-100,-23,-63,14,42,-164,-105,258,-8,68,142,-296,-284,-163,18,276,-230,-164,225,82,-64,235,61,67,191,-217,-112,-100,-51,-102,-174,93,-72,212,-60,139,-340,-17,-91,309,-221,-2,106,-90,23,-346,148,-16,106,100,-185,-52,-22,191,-368,-16,-199,-88,-94,195,-176,-3,-208,94,-80,-225,-164,177,-156,434,-121,104,-246,-106,1,177,15,-464,-226,16,-167,89,65,-304,47,-119,149,133,-160,11,160,327,220,297,-99,139,73,-180,188,137,-262,-168,-50,-79,331,-77,271,369,27,67,-15,-182,318,-327,-185,39,162,193,-682,-389,210,-197,-116,154,17,4,-80,38,-42,314,67,14,262,-296,-150,58,-45,-92,327,117,81,29,155,-59,-157,-4,-107,-202,136,-67,-182,168,97,69,-84,49,-150,-66,140,76,244,186,-36,85,-153,56,167,-173,214,-675,-294,-66,118,-153,113,-48,130,131,114,-46,0,-121,352,100,103,61,160,-120,-185,-65,-506,-109,-332,-96,83,94,-362,513,91,-64,259,323,-38,125,171,-76,138,80,-20,407,-64,145,246,125,-89,-270,89,-47,286,-248,112,0,57,-132,-205,86,562,36,35,-381,-417,216",
"307,66,-43,48,-346,75,53,-220,48,403,-103,217,71,20,123,-68,53,146,-246,-194,97,-145,204,20,125,-101,-33,-345,-37,34,-234,165,-103,-60,-176,-313,-348,128,-428,-147,436,141,-247,-162,172,-1,40,-34,379,76,-69,-122,-27,18,-97,-221,-30,304,-234,-204,-115,1,-208,-125,103,152,249,52,6,219,-161,243,-133,-258,-198,-179,59,-264,182,-77,213,177,23,-268,-305,48,981,162,460,-200,111,29,-129,835,63,379,-393,588,-113,-181,-137,235,-123,-71,326,14,279,44,-261,111,123,79,58,254,177,-205,0,198,-89,-47,406,211,247,52,-113,-239,217,-25,-141,378,-4,-133,-148,-125,321,-263,-133,-4,95,-18,195,198,-114,241,-181,312,-68,-117,-205,-43,259,6,209,-96,-41,-143,67,65,220,-129,-87,-234,-272,-308,-103,141,54,-274,384,-253,87,-285,157,69,95,-33,-70,-204,-238,155,61,-400,398,12,-87,-114,-77,120,755,132,-51,202,-99,-140,247,-294,42,-203,69,292,-173,97,19,-258,269,-261,-219,109,194,43,-160,275,76,389,13,96,-62,-48,182,-231,-177,160,-6,-61,53,7,67,-221,214,87,128,103,8,-118,179,82,-7,31,155,-18,-30,-241,-61,42,118,13,-212,-75,175,60,84,213,-90,245,101,217,202,53,34,385,51,0,40,-233,152,-44,265,266,312,197,67,-54,532,-136,296,-463,289,276,-26,-337,83,-167,354,289,49,-63,29,30,83,-427,-242,179,-260,107,402,172,55,8,-772,23,40,25,106,242,-26,246,46,-69,106,109,56,-67,87,8,-16,400,346,119,266,132,-16,235,-50,249,-95,326,10,231,-218,-272,-180,199,182,-217,-129,213,150,219,180,66,-1,79,218,-99,343,77,354,89,-262,-300,183,-327,178,272,-620,-997,-1412,217,-175,-123,-111,-17,-782,552,564,122,-309,-143,232,-272,283,-247,374,157,42,170,-112,255,-534,46,501,-372,6,85,-123,-84,-193,20,570,146,11,183,-53,-120,110,-327,324,-45,-393,-106,7,182,69,141,-36,106,175,-79,233,-155,-19,-374,-23,60,84,242,34,84,-2,118,144,42,384,36,-196,168,-347,127,35,43,-216,223,48,139,306,38,-153,239,249,-29,96,-18,-108,181,-369,194,265,204,106,69,115,14,164,72,-156,-130,27,41,339,-808,456,-350,126,-15,102,86,266,-59,29,-103,153,73,-308,-42,-453,168,173,-47,-275,368,86,214,-136,11,36,127,-205,-191,244,331,66,3,280,-134,254,-272,82,84,255,-64,-213,-312,-337,-267,-433,317,20,-214,-204,-241,234,-459,499,-341,222,-9,244,-90,127,119,14,152,-17,-243,-255,565,48,264,360,360,-155,71,154,-23,-308,190,-58,82,152,-181,91,-64,-116,95,382,-169,79,-117,-200,88,163,119,-146,113,-34,-94,240,11,-106,-86,112,-44,-149,74,309,-238,170,-35,-342,-139,-28,-28,96,69,553,318,-7,203,-99,-29,6,64,105,-39,-142,45,124,-138,54,20,335,-125,35,99,-49,100,30,5,-131,-208,-9,145,1,3,-139,324,-183,-10,-227,41,44,72,64,-233,-154,-202,120,104,58,42,-21,-18,169,19,47,28,39,-76,-151,60,-44,162,391,-145,-209,145,100,68,127,-92,-203,76,239,-188,40,28,17,144,98,50,-114,-29,-11,-20,106,21,52,-21,59,26,128,69,-18,-34,-23,-196,106,10,125,54,85,-101,112,26,-28,55,98,29,17,-10,176,121,121,79,-189,60,-19,-126,-17,79,85,-315,-375,105,-35,-35,90,-33,-27,288,-25,40,3,9,-377,27,170,119,-50,79,-47,58,-36,330,11,-27,149,-261,30,-120,293,-49,101,-319,-16,37,-285,100,-146,309,69,3,85,106,-100,-30,181,27,37,146,-56,115,94,158,46,84,37,146,119,51,199,-204,64,171,-46,194,165,-65,317,13,-144,158,-68,-140,-2,-35,100,114,204,-70,52,-42,52,2,-111,175,92,243,117,76,136,38,-153,37,125,-235,242,166,192,307,-69,229,-169,-120,207,92,-88,170,-268,5,59,-163,73,302,132,-210,95,-84,98,-89,-118,-140,-153,85,371,2,15,58,-188,78,310,85,-26,202,-39,207,-144,25,323,204,193,77,-217,-121,281,117,-26,241,191,-202,173,63,192,-83,-78,178,-94,-190,-95,-323,-208,476,52,482,138,35,208,-20,142,455,18,-140,267,33,-40,279,99,-201,-428,248,-343,259,-102,223,6,146,8,-249,-169,-361,185,-11,399,-74,409,-389,-105,-100,365,-495,226,-68,263,352,218,52,156,28,38,347,-124,210,13,190,-113,91,-101,45,20,-238,154,-227,-139,262,90,89,251,-438,-61,-326,-203,128,-582,-524,201,128,167,-309,147,634,42,164,436,-62,266,187,-345,-218,92,347,-40,491,-319,-238,258,-59,-31,70,-36,451,143,27,-82,10,342,309,185,93,222,-108,-77,-252,206,-272,342,-283,541,49,14,-270,-237,55,240,115,-10,-10,-45,-207,-497,-6,360,-610,440,245,-24,61,215,-14,267,-36,11,131,80,22,172,-410,-467,208,-504,-199,-356,499,-432,650,476,-173",
"172,-752,509,-102,-147,30,16,-313,470,-169,-156,-43,42,178,165,-74,-209,241,239,17,131,41,-16,-265,-73,-183,-51,-389,33,350,213,-201,25,-151,-93,322,-263,191,141,-117,-129,59,69,189,-76,17,-337,86,106,-803,-329,385,-89,338,437,215,130,-119,434,-266,-13,-12,-328,-18,-96,-241,275,36,-152,91,-92,-170,177,-465,-352,0,-1539,717,303,243,-151,364,-235,301,266,93,-109,199,-240,226,100,121,-269,-218,69,68,-166,162,66,394,194,33,-171,-23,-128,-79,65,-343,96,-67,408,-244,-179,-344,-121,-235,-12,147,-770,-797,301,59,507,37,108,-239,-277,-137,-401,-362,-228,419,584,145,87,23,49,260,103,-286,-248,92,-247,352,211,-228,-546,-95,-238,56,138,-160,-193,153,809,-451,160,-90,162,-37,327,26,86,-90,285,237,60,91,-232,90,54,75,104,-142,41,141,29,71,93,-34,181,-349,274,107,48,-144,226,8,-42,-144,158,82,180,233,45,82,47,135,-31,-76,100,32,-8,-33,11,-341,-53,26,249,-27,9,20,-239,-106,-104,-46,220,53,162,6,-43,-86,-68,-72,-176,176,-325,10,286,84,63,52,-28,-233,143,-136,-121,-179,273,344,153,-78,62,67,-47,101,165,-41,-167,-44,-157,26,280,74,-10,52,91,-153,-135,-177,-37,54,-363,69,34,149,-200,322,67,-78,49,105,-311,5,141,182,9,-9,-50,11,-38,-155,48,219,-34,-212,143,-265,-5,-71,182,123,146,75,152,-49,-92,90,7,-154,223,1,-271,223,-105,116,178,-48,-37,50,182,0,-153,10,16,186,18,183,-171,-210,120,-28,-321,112,-23,145,-53,-322,119,318,19,-137,261,-86,159,-63,147,-46,148,145,93,35,73,-87,102,191,-51,-70,93,111,-82,96,-52,127,7,-63,133,-58,148,-95,-431,133,-136,302,-102,165,41,274,122,109,46,171,-36,118,-180,159,-207,37,150,215,-41,-432,-63,44,-122,226,-15,-185,248,277,54,122,19,-413,208,-154,-415,102,-150,297,188,-212,83,-63,-433,-152,-411,89,430,-451,136,26,-93,-308,48,337,-118,317,-228,416,34,128,-242,187,-398,126,-345,80,-385,-428,-52,-168,351,-110,-39,354,-64,-27,-73,-284,178,-29,-218,-762,-2003,463,-669,1202,-430,-512,-545,928,-222,-6,-59,-75,592,-494,-377,-249,-95,344,-534,-637,-420,-637,863,75,661,306,82,59,-68,167,432,-364,11,266,304,41,-299,-120,-188,-164,708,392,86,214,-52,196,40,-109,173,221,-159,-186,390,132,-23,-264,315,243,47,-8,76,79,-137,183,-87,180,-8,-420,-104,-55,86,296,-75,231,55,110,101,70,64,19,168,-177,-587,228,-410,-56,-204,277,232,-298,-461,514,-98,318,40,177,-334,-87,-62,289,14,137,236,-29,162,51,63,-12,288,-222,10,-100,258,25,71,71,3,84,96,71,-40,224,149,95,-212,32,-103,-156,301,127,2,-31,133,240,-135,-34,-67,-56,-236,-166,44,-58,529,59,-141,160,-434,-592,-155,-409,423,-39,-224,460,-662,130,173,476,140,351,-204,141,-299,-490,678,136,-264,354,-63,116,50,238,-48,159,-48,115,26,-4,-43,237,-115,100,-116,-162,139,151,-145,-168,-358,69,-274,353,168,-99,187,-84,4,36,195,16,85,51,-89,-51,163,213,-10,-105,128,-209,11,-179,-11,-214,-179,329,13,99,-16,43,-194,377,40,119,179,81,-12,-8,14,63,216,81,-2,46,-9,204,-216,113,176,96,155,-34,-123,87,-117,-182,75,150,215,51,10,64,-150,-226,-47,-134,75,300,48,-125,-123,109,106,110,29,93,126,65,13,-41,-167,292,157,-5,-20,13,-358,-115,61,225,-31,135,79,-238,147,12,55,-238,236,-29,92,43,-56,69,67,123,-88,102,-57,128,-73,91,-82,-279,37,65,201,57,23,-88,171,-97,-61,-277,-100,257,342,105,34,99,10,73,-384,298,139,-123,-54,-128,92,-292,377,109,67,-4,-154,-60,211,-232,29,164,-129,142,-31,92,45,-23,-122,-90,28,65,-38,-122,17,182,-290,68,-180,60,-600,110,-330,204,-30,-43,96,365,77,247,10,138,-378,330,-14,27,-332,-79,244,-72,-639,-222,66,229,-160,-144,258,151,218,120,224,-49,156,-122,181,59,-128,-19,-116,-20,211,-37,32,-107,-156,310,109,202,29,-74,60,18,-13,-85,52,-222,21,75,26,-37,-56,4,8,-151,522,11,150,9,302,43,46,-87,102,-39,-30,134,-11,98,173,96,87,-49,6,-153,32,-3,-99,46,189,32,-53,-44,132,60,30,53,5,-21,30,104,-27,116,119,-107,-84,64,79,-86,213,37,24,164,43,197,46,44,-50,-27,85,282,40,132,41,-14,231,199,103,207,-420,-536,417,36,-310,320,-155,-583,239,-71,177,42,-62,-20,232,-47,39,-72,273,-90,-205,-126,76,227,16,155,5,-59,140,47,67,-19,92,222,-107,-4,-428,41,-301,233,280,-224,-453,502,-460,-119,-712,305,126,237,292,13,131,17,305,57,-2,-224,155,-135,166,190,-5,55,-6,-14,-215,-69,-69,-277,431,41,238,-44,136,135,-65",
"14,-264,-75,-153,-100,297,149,156,-105,-43,-92,91,-18,70,144,121,116,-85,142,-53,43,113,21")
var int BASE = timestamp("UTC", 1885, 4, 27, 0, 0)
WEEK = 604800000.0
SYN = 7253.45
f_wk(int t) =>
int(math.floor((t - BASE) / WEEK))
// analog week offsets for target year y
f_offs(int y) =>
array<int> o = array.new<int>()
int a0 = f_wk(timestamp("UTC", y, 1, 1, 0, 0)) - 1
for k = 1 to 30
int n = mode == "Decennial (same last digit)" ? 10 * k : 20 * k
if mode != "20-year Jupiter-Saturn synodic"
if y - n < 1886 or (mode == "20-year calendar (Gann)" and k > kMax)
break
array.push(o, int(math.round((timestamp("UTC", y, 1, 1, 0, 0) - timestamp("UTC", y - n, 1, 1, 0, 0)) / WEEK)))
else
int s = int(math.round(k * SYN / 7.0))
if a0 - s < 0 or k > kMax
break
array.push(o, s)
o
// composite in ln units at week w for target year y, given offsets
f_comp(array<int> LL, array<int> o, int w, int y) =>
int a0 = f_wk(timestamp("UTC", y, 1, 1, 0, 0)) - 1
int n = array.size(LL)
float sum = 0.0
int cnt = 0
for s in o
if a0 - s >= 0 and w - s >= 0 and w - s < n
sum += (array.get(LL, w - s) - array.get(LL, a0 - s)) / 10000.0
cnt += 1
cnt > 0 ? sum / cnt : na
f_pct(float v) =>
na(v) ? na : (math.exp(v) - 1.0) * 100.0
// ---------- load ----------
var array<int> L = array.new<int>()
if barstate.isfirst
int acc = 0
bool first = true
for c in DJW
recs = str.split(c, ",")
for r in recs
int v = int(str.tonumber(r))
acc := first ? v : acc + v
first := false
array.push(L, acc)
// ---------- historical composite and actual ----------
int yr = year(time, "UTC")
var array<int> offs = array.new<int>()
var int offYear = 0
if yr != offYear
offs := f_offs(yr)
offYear := yr
float comp = f_pct(f_comp(L, offs, f_wk(time), yr))
var float prevYE = na
if yr != yr[1] and not na(close[1])
prevYE := close[1]
float ytd = showAct and not na(prevYE) ? (close / prevYE - 1.0) * 100.0 : na
plot(comp, "Composite (percent from prior year-end)", color = #C9A84C, linewidth = 2, style = plot.style_stepline)
plot(ytd, "Actual YTD percent", color = #2E5EAA, linewidth = 1)
hline(0, "Zero", color = color.new(color.gray, 50))
// ---------- projection for projYear ----------
var polyline pl = na
var label pLbl = na
if barstate.islast
polyline.delete(pl)
label.delete(pLbl)
array<int> po = f_offs(projYear)
int w0 = f_wk(timestamp("UTC", projYear, 1, 1, 0, 0))
int w1 = f_wk(timestamp("UTC", projYear, 12, 31, 0, 0))
array<chart.point> pts = array.new<chart.point>()
float lastV = na
for w = w0 to w1
float v = f_pct(f_comp(L, po, w, projYear))
if not na(v)
array.push(pts, chart.point.from_time(BASE + w * 604800000 + 4 * 86400000, v))
lastV := v
if array.size(pts) > 1
pl := polyline.new(pts, xloc = xloc.bar_time, line_color = #E8603C, line_width = 2)
pLbl := label.new(array.get(pts, array.size(pts) - 1).time, lastV, str.tostring(projYear) + " composite " + str.tostring(lastV, "#.0") + "%, " + str.tostring(array.size(po)) + " analogs", xloc = xloc.bar_time, color = #E8603C, textcolor = color.white, style = label.style_label_left, size = size.small)
// ---------- table ----------
var table tb = table.new(position.top_right, 2, 6, bgcolor = color.new(#0A1628, 0), border_width = 1)
if barstate.islast and showTbl
table.cell(tb, 0, 0, "AnalogComp", text_color = #C9A84C, text_size = size.small)
table.cell(tb, 1, 0, mode, text_color = color.white, text_size = size.small)
table.cell(tb, 0, 1, "Data", text_color = #C9A84C, text_size = size.tiny)
table.cell(tb, 1, 1, "DJIA weekly 1885-2019; analogs after 2019 are skipped", text_color = color.white, text_size = size.tiny)
table.cell(tb, 0, 2, "Decennial", text_color = #C9A84C, text_size = size.tiny)
table.cell(tb, 1, 2, "mean r 0.202 vs random-year null 0.066, perm p 0.005, 103 target yrs 1916-2018; same digit ranks 1 of 10 in digit-rotation placebo", text_color = color.white, text_size = size.tiny)
table.cell(tb, 0, 3, "20y calendar", text_color = #C9A84C, text_size = size.tiny)
table.cell(tb, 1, 3, "mean r 0.035 vs random-year null 0.069, perm p 0.715, 73 target yrs 1946-2018", text_color = color.white, text_size = size.tiny)
table.cell(tb, 0, 4, "20y synodic", text_color = #C9A84C, text_size = size.tiny)
table.cell(tb, 1, 4, "mean r 0.055 vs random-year null 0.072, perm p 0.601, 74 target yrs 1945-2018", text_color = color.white, text_size = size.tiny)
table.cell(tb, 0, 5, "Status", text_color = #C9A84C, text_size = size.tiny)
table.cell(tb, 1, 5, "Unregistered in-sample diagnostic, not a protocol verdict. Holdout 2020 on not yet run.", text_color = color.white, text_size = size.tiny)
// ---------- timeframe notice ----------
// Pine cannot open a popup when an indicator is added, so a banner is drawn in the pane on any chart
// that is not weekly. It disappears when the chart is switched to a weekly timeframe.
var table tfNote = table.new(position.middle_center, 1, 1, bgcolor = color.new(#0A1628, 10), border_color = #C9A84C, border_width = 1)
if barstate.islast and not timeframe.isweekly
table.cell(tfNote, 0, 0, "AnalogComp is built from weekly closes. Use it on a WEEKLY chart.", text_color = #C9A84C, text_size = size.large)