Indicator · Pine Script v6 · On the chart

ChandraQuant — Kāla-Chakra

by vinitpatil519

ChandraQuant Kala-Chakra is an overlay indicator for Indian equity indices.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code327
Settings10inputs
LicenceMIT
Last update7 weeks ago9 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

327 lines of Pine Script v6 from v3/pine/ChandraQuant_KalaChakra.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

ChandraQuant_KalaChakra.pine
//@version=6
// =============================================================================
//  ChandraQuant — Kāla-Chakra
//  Vedic astronomical regime overlay for Indian equity indices.
//
//  This script computes REAL astronomy on the chart. There is no lookup table for
//  the Sun and Moon: their ecliptic longitudes are evaluated from Meeus' periodic
//  series (Astronomical Algorithms, ch. 25 and 47) directly in Pine, then converted
//  to the sidereal zodiac with the Lahiri ayanamsa. Accuracy is ~0.01° for Surya
//  and ~0.02° for Chandra — two orders of magnitude finer than the 13°20' width of
//  a nakshatra — and it works on any bar, any date, past or future, forever.
//
//  Only Guru, Shani and Rahu use an embedded table (monthly nodes, 1996–2036),
//  because they move 0.08°/0.03°/0.05° per day and a series for each would be
//  hundreds of terms for no visible gain. Interpolation error stays under 0.4°.
//
//  Everything drawn here is a deterministic function of time. Nothing is fitted to
//  price, and nothing repaints.
//
//  Companion to the ChandraQuant Alpha Engine (Python). See CLAUDE.md.
// =============================================================================

indicator("ChandraQuant — Kāla-Chakra", shorttitle="ChandraQuant", overlay=true, max_labels_count=500)

// ----------------------------------------------------------------------------- inputs
grpD = "Display"
showBands    = input.bool(true,  "Regime background bands",  group=grpD)
showNakLabel = input.bool(true,  "Nakshatra change markers", group=grpD)
showSyzygy   = input.bool(true,  "Purnima / Amavasya glyphs", group=grpD)
showEclipse  = input.bool(true,  "Grahana (eclipse) shading", group=grpD)
showVishti   = input.bool(true,  "Vishti (Bhadra) karana marks", group=grpD)
showTable    = input.bool(true,  "Info table", group=grpD)
tablePos     = input.string("Top right", "Table position", options=["Top right","Top left","Bottom right","Bottom left"], group=grpD)

grpT = "Trend context"
emaFast = input.int(20,  "Fast EMA", group=grpT)
emaSlow = input.int(50,  "Slow EMA", group=grpT)
emaTrend= input.int(200, "Trend EMA", group=grpT)

// ----------------------------------------------------------------------------- constants
DEG2RAD = 0.017453292519943295
NAK_DEG = 13.333333333333334      // 360 / 27
TITHI_DEG = 12.0
KARANA_DEG = 6.0

norm360(x) =>
    float v = x % 360.0
    v < 0 ? v + 360.0 : v

sind(x) => math.sin(x * DEG2RAD)
cosd(x) => math.cos(x * DEG2RAD)

// ----------------------------------------------------------------------------- time
// Pine's `time` is the bar open in milliseconds UTC. For an NSE daily bar that is
// 03:45 UTC, i.e. the 09:15 IST opening bell — the same instant the Python engine
// evaluates. Julian Day follows directly.
julianDay() => time / 86400000.0 + 2440587.5

// ----------------------------------------------------------------------------- Lahiri ayanamsa
// Anchored at 23.250182° on JD 2435553.5 (1956-01-01), accumulating IAU-2006
// general precession in longitude. Matches Swiss Ephemeris to a few arc-seconds.
ayanamsa(T) =>
    float p  = 5028.796195 * T + 1.1054348 * T * T
    23.250182 + (p + 2201.1312) / 3600.0

// ----------------------------------------------------------------------------- Surya (Meeus ch. 25)
sunLongitude(T) =>
    float L0 = 280.46646 + 36000.76983 * T + 0.0003032 * T * T
    float M  = 357.52911 + 35999.05029 * T - 0.0001537 * T * T
    float C  = (1.914602 - 0.004817 * T - 0.000014 * T * T) * sind(M) + (0.019993 - 0.000101 * T) * sind(2.0 * M) + 0.000289 * sind(3.0 * M)
    float trueLon = L0 + C
    float omega = 125.04 - 1934.136 * T
    norm360(trueLon - 0.00569 - 0.00478 * sind(omega))

// ----------------------------------------------------------------------------- Chandra (Meeus ch. 47)
// The 27 largest periodic terms in longitude. Truncating here costs ~0.02°, which is
// invisible at nakshatra resolution but keeps the script fast on long histories.
moonLongitude(T) =>
    float Lp = 218.3164477 + 481267.88123421 * T - 0.0015786 * T * T + T * T * T / 538841.0 - T * T * T * T / 65194000.0
    float D  = 297.8501921 + 445267.1114034 * T - 0.0018819 * T * T + T * T * T / 545868.0
    float Ms = 357.5291092 + 35999.0502909 * T - 0.0001536 * T * T
    float Mp = 134.9633964 + 477198.8675055 * T + 0.0087414 * T * T + T * T * T / 69699.0
    float F  = 93.2720950 + 483202.0175233 * T - 0.0036539 * T * T - T * T * T / 3526000.0
    float E  = 1.0 - 0.002516 * T - 0.0000074 * T * T

    float s = 0.0
    s := s + 6288774.0 * sind(Mp)
    s := s + 1274027.0 * sind(2.0 * D - Mp)
    s := s +  658314.0 * sind(2.0 * D)
    s := s +  213618.0 * sind(2.0 * Mp)
    s := s -  185116.0 * sind(Ms) * E
    s := s -  114332.0 * sind(2.0 * F)
    s := s +   58793.0 * sind(2.0 * D - 2.0 * Mp)
    s := s +   57066.0 * sind(2.0 * D - Ms - Mp) * E
    s := s +   53322.0 * sind(2.0 * D + Mp)
    s := s +   45758.0 * sind(2.0 * D - Ms) * E
    s := s -   40923.0 * sind(Ms - Mp) * E
    s := s -   34720.0 * sind(D)
    s := s -   30383.0 * sind(Ms + Mp) * E
    s := s +   15327.0 * sind(2.0 * D - 2.0 * F)
    s := s -   12528.0 * sind(Mp + 2.0 * F)
    s := s +   10980.0 * sind(Mp - 2.0 * F)
    s := s +   10675.0 * sind(4.0 * D - Mp)
    s := s +   10034.0 * sind(3.0 * Mp)
    s := s +    8548.0 * sind(4.0 * D - 2.0 * Mp)
    s := s -    7888.0 * sind(2.0 * D + Ms - Mp) * E
    s := s -    6766.0 * sind(2.0 * D + Ms) * E
    s := s -    5163.0 * sind(D - Mp)
    s := s +    4987.0 * sind(D + Ms) * E
    s := s +    4036.0 * sind(2.0 * D - Ms + Mp) * E
    s := s +    3994.0 * sind(2.0 * D + 2.0 * Mp)
    s := s +    3861.0 * sind(4.0 * D)
    s := s +    3665.0 * sind(2.0 * D - 3.0 * Mp)
    norm360(Lp + s / 1000000.0)

// Chandra's ecliptic latitude — needed for eclipse geometry, since an eclipse
// requires a syzygy AND the Moon near a node.
moonLatitude(T) =>
    float D  = 297.8501921 + 445267.1114034 * T - 0.0018819 * T * T
    float Ms = 357.5291092 + 35999.0502909 * T - 0.0001536 * T * T
    float Mp = 134.9633964 + 477198.8675055 * T + 0.0087414 * T * T
    float F  = 93.2720950 + 483202.0175233 * T - 0.0036539 * T * T
    float E  = 1.0 - 0.002516 * T

    float b = 0.0
    b := b + 5128122.0 * sind(F)
    b := b +  280602.0 * sind(Mp + F)
    b := b +  277693.0 * sind(Mp - F)
    b := b +  173237.0 * sind(2.0 * D - F)
    b := b +   55413.0 * sind(2.0 * D - Mp + F)
    b := b +   46271.0 * sind(2.0 * D - Mp - F)
    b := b +   32573.0 * sind(2.0 * D + F)
    b := b +   17198.0 * sind(2.0 * Mp + F)
    b := b +    9266.0 * sind(2.0 * D + Mp - F)
    b := b +    8822.0 * sind(2.0 * Mp - F)
    b := b +    8216.0 * sind(2.0 * D - Ms - F) * E
    b := b +    4324.0 * sind(2.0 * D - 2.0 * Mp - F)
    b / 1000000.0

// ---------------------------------------------------------------------------
// Slow-graha table: sidereal longitudes at regular nodes, linearly interpolated.
// Span 1996-01-01 to 2036-01-01, 30-day nodes, 488 points per graha.
// Guru/Shani/Rahu move 0.08/0.03/0.05 deg per day, so interpolation error stays
// far below one degree - nakshatra boundaries are 13 deg 20' wide.
// Generated by chandraquant/pine/emit.py - do not hand-edit.
// ---------------------------------------------------------------------------
cq_jd0   = 2450083.50000
cq_step  = 30.0
var float[] cq_guru = array.from(245.708, 252.278, 257.959, 262.042, 263.813, 262.842, 259.632, 255.998, 254.071, 254.873, 258.247, 263.532, 270.008, 277.008, 283.915, 290.117, 294.954, 297.716, 297.797, 295.244, 291.437, 288.687, 288.583, 291.305, 296.239, 302.603, 309.682, 316.848, 323.522, 329.098, 332.898, 334.216, 332.686, 329.074, 325.563, 324.327, 326.088, 330.384, 336.392, 343.338, 350.577, 357.548, 363.695, 368.387, 370.896, 370.590, 367.619, 363.687, 361.305, 361.868, 365.235, 370.609, 377.170, 384.244, 391.274, 397.734, 403.035, 406.470, 407.289, 405.208, 401.319, 398.076, 397.443, 399.739, 404.296, 410.287, 417.012, 423.905, 430.451, 436.087, 440.128, 441.794, 440.563, 437.027, 433.329, 431.735, 433.022, 436.743, 442.111, 448.419, 455.088, 461.599, 467.396, 471.811, 474.059, 473.507, 470.415, 466.573, 464.313, 464.774, 467.759, 472.563, 478.489, 484.945, 491.401, 497.296, 501.968, 504.635, 504.617, 501.960, 498.139, 495.434, 495.247, 497.627, 501.973, 507.602, 513.915, 520.360, 526.368, 531.275, 534.310, 534.768, 532.542, 528.822, 525.791, 525.064, 526.933, 530.913, 536.338, 542.590, 549.099, 555.277, 560.464, 563.906, 564.883, 563.143, 559.592, 556.278, 555.027, 556.410, 560.066, 565.348, 571.610, 578.253, 584.675, 590.226, 594.178, 595.803, 594.695, 591.430, 587.854, 586.017, 586.839, 590.137, 595.276, 601.574, 608.391, 615.116, 621.115, 625.702, 628.150, 627.904, 625.149, 621.394, 618.865, 618.954, 621.748, 626.649, 632.925, 639.889, 646.915, 653.396, 658.693, 662.108, 662.969, 661.059, 657.367, 654.108, 653.227, 655.256, 659.705, 665.790, 672.768, 679.990, 686.875, 692.836, 697.219, 699.305, 698.561, 695.350, 691.542, 689.534, 690.492, 694.180, 699.807, 706.565, 713.777, 720.871, 727.302, 732.468, 735.660, 736.171, 733.835, 729.908, 726.882, 726.595, 729.251, 734.143, 740.426, 747.390, 754.456, 761.101, 766.763, 770.764, 772.338, 770.994, 767.381, 763.715, 762.284, 763.822, 767.828, 773.472, 780.022, 786.884, 793.540, 799.448, 803.955, 806.289, 805.798, 802.703, 798.803, 796.526, 797.067, 800.205, 805.187, 811.278, 817.872, 824.445, 830.456, 835.266, 838.109, 838.266, 835.696, 831.818, 829.000, 828.756, 831.150, 835.546, 841.228, 847.583, 854.073, 860.149, 865.174, 868.388, 869.049, 866.955, 863.218, 860.064, 859.213, 861.000, 864.919, 870.285, 876.479, 882.941, 889.112, 894.349, 897.905, 899.027, 897.397, 893.861, 890.472, 889.111, 890.376, 893.904, 899.045, 905.161, 911.674, 918.004, 923.509, 927.456, 929.093, 927.994, 924.731, 921.153, 919.289, 920.037, 923.203, 928.167, 934.271, 940.903, 947.465, 953.320, 957.761, 960.046, 959.635, 956.789, 953.072, 950.648, 950.789, 953.532, 958.301, 964.403, 971.182, 978.022, 984.300, 989.348, 992.444, 992.949, 990.772, 987.061, 984.010, 983.362, 985.509, 989.960, 995.979, 1002.856, 1009.952, 1016.662, 1022.367, 1026.385, 1028.013, 1026.835, 1023.439, 1019.813, 1018.170, 1019.444, 1023.331, 1029.071, 1035.889, 1043.114, 1050.155, 1056.438, 1061.337, 1064.139, 1064.205, 1061.551, 1057.644, 1054.946, 1055.068, 1058.079, 1063.256, 1069.767, 1076.900, 1084.064, 1090.719, 1096.288, 1100.091, 1101.385, 1099.769, 1096.049, 1092.529, 1091.412, 1093.311, 1097.663, 1103.617, 1110.425, 1117.482, 1124.263, 1130.223, 1134.720, 1136.991, 1136.406, 1133.225, 1129.316, 1127.156, 1127.920, 1131.331, 1136.589, 1142.926, 1149.722, 1156.449, 1162.578, 1167.489, 1170.430, 1170.670, 1168.122, 1164.192, 1161.330, 1161.132, 1163.657, 1168.217, 1174.059, 1180.550, 1187.153, 1193.338, 1198.494, 1201.878, 1202.725, 1200.750, 1196.989, 1193.723, 1192.792, 1194.572, 1198.526, 1203.936, 1210.164, 1216.660, 1222.883, 1228.220, 1231.937, 1233.258, 1231.783, 1228.266, 1224.774, 1223.287, 1224.458, 1227.916, 1232.989, 1239.037, 1245.491, 1251.793, 1257.325, 1261.360, 1263.125, 1262.139, 1258.913, 1255.283, 1253.324, 1253.962, 1257.001, 1261.821, 1267.772, 1274.261, 1280.710, 1286.496, 1290.907, 1293.180, 1292.759, 1289.904, 1286.192, 1283.767, 1283.860, 1286.491, 1291.094, 1297.002, 1303.588, 1310.252, 1316.370, 1321.255, 1324.167, 1324.473, 1322.158, 1318.452, 1315.518, 1314.964, 1317.103, 1321.449, 1327.307, 1334.006, 1340.918, 1347.427, 1352.883, 1356.580, 1357.827, 1356.316, 1352.817, 1349.366, 1347.992, 1349.442, 1353.381, 1359.087, 1365.830, 1372.949, 1379.839, 1385.893, 1390.453, 1392.808, 1392.400, 1389.461, 1385.642, 1383.299, 1383.784, 1387.050, 1392.386, 1398.995, 1406.176, 1413.325, 1419.876, 1425.226, 1428.683, 1429.546, 1427.560, 1423.754, 1420.492, 1419.783, 1422.067, 1426.739, 1432.955, 1439.966, 1447.159, 1453.991, 1459.907, 1464.255, 1466.289, 1465.441, 1462.103, 1458.264, 1456.369)
var float[] cq_shani = array.from(325.600, 328.202, 331.614, 335.315, 338.798, 341.590, 343.259, 343.497, 342.288, 340.122, 337.972, 336.839, 337.252, 339.168, 342.198, 345.827, 349.541, 352.850, 355.294, 356.470, 356.141, 354.460, 352.143, 350.271, 349.721, 350.782, 353.228, 356.592, 360.352, 364.007, 367.083, 369.131, 369.781, 368.899, 366.843, 364.539, 363.089, 363.171, 364.837, 367.726, 371.334, 375.146, 378.680, 381.468, 383.073, 383.172, 381.774, 379.471, 377.350, 376.430, 377.147, 379.348, 382.590, 386.358, 390.155, 393.509, 395.955, 397.071, 396.609, 394.766, 392.370, 390.587, 390.262, 391.577, 394.233, 397.741, 401.595, 405.316, 408.433, 410.483, 411.068, 410.056, 407.873, 405.554, 404.233, 404.519, 406.373, 409.397, 413.093, 416.969, 420.553, 423.374, 424.967, 424.988, 423.469, 421.087, 419.007, 418.230, 419.105, 421.424, 424.737, 428.549, 432.384, 435.770, 438.227, 439.303, 438.745, 436.800, 434.383, 432.685, 432.488, 433.905, 436.613, 440.140, 444.004, 447.735, 450.855, 452.876, 453.381, 452.261, 450.014, 447.731, 446.519, 446.902, 448.801, 451.825, 455.500, 459.354, 462.916, 465.695, 467.205, 467.104, 465.480, 463.088, 461.098, 460.432, 461.368, 463.687, 466.961, 470.723, 474.505, 477.824, 480.179, 481.109, 480.399, 478.379, 476.015, 474.444, 474.349, 475.796, 478.472, 481.937, 485.726, 489.366, 492.362, 494.209, 494.510, 493.232, 490.964, 488.797, 487.734, 488.205, 490.113, 493.090, 496.688, 500.441, 503.865, 506.449, 507.711, 507.367, 505.613, 503.269, 501.448, 500.941, 501.956, 504.275, 507.497, 511.169, 514.816, 517.937, 520.021, 520.639, 519.678, 517.587, 515.347, 513.983, 514.053, 515.576, 518.255, 521.665, 525.345, 528.806, 531.533, 533.033, 532.985, 531.489, 529.230, 527.256, 526.426, 527.068, 529.059, 532.044, 535.581, 539.195, 542.379, 544.619, 545.475, 544.783, 542.879, 540.635, 539.061, 538.807, 540.001, 542.412, 545.644, 549.239, 552.701, 555.513, 557.182, 557.368, 556.101, 553.953, 551.896, 550.821, 551.159, 552.872, 555.650, 559.064, 562.634, 565.850, 568.196, 569.234, 568.762, 567.035, 564.821, 563.102, 562.594, 563.518, 565.708, 568.791, 572.310, 575.764, 578.635, 580.433, 580.808, 579.738, 577.703, 575.601, 574.340, 574.434, 575.922, 578.534, 581.850, 585.386, 588.625, 591.058, 592.246, 591.965, 590.399, 588.227, 586.399, 585.685, 586.391, 588.404, 591.373, 594.838, 598.293, 601.220, 603.134, 603.679, 602.790, 600.862, 598.730, 597.315, 597.204, 598.509, 600.993, 604.242, 607.762, 611.036, 613.559, 614.895, 614.796, 613.381, 611.251, 609.329, 608.435, 608.953, 610.825, 613.712, 617.150, 620.626, 623.624, 625.666, 626.387, 625.677, 623.853, 621.692, 620.133, 619.836, 620.983, 623.368, 626.575, 630.105, 633.438, 636.074, 637.577, 637.674, 636.416, 634.328, 632.310, 631.239, 631.583, 633.331, 636.158, 639.592, 643.115, 646.214, 648.416, 649.342, 648.832, 647.123, 644.933, 643.221, 642.734, 643.727, 646.024, 649.208, 652.770, 656.193, 658.980, 660.692, 661.022, 659.950, 657.914, 655.794, 654.530, 654.685, 656.305, 659.078, 662.522, 666.118, 669.356, 671.765, 672.946, 672.682, 671.120, 668.906, 667.025, 666.319, 667.135, 669.331, 672.490, 676.099, 679.640, 682.622, 684.597, 685.219, 684.385, 682.434, 680.207, 678.719, 678.645, 680.104, 682.800, 686.251, 689.933, 693.341, 696.004, 697.502, 697.552, 696.194, 693.984, 691.917, 690.948, 691.534, 693.586, 696.693, 700.341, 704.014, 707.224, 709.515, 710.499, 709.979, 708.175, 705.863, 704.119, 703.754, 704.987, 707.555, 710.980, 714.738, 718.330, 721.283, 723.155, 723.597, 722.532, 720.390, 718.143, 716.860, 717.138, 718.969, 721.966, 725.617, 729.409, 732.857, 735.499, 736.907, 736.792, 735.231, 732.889, 730.876, 730.152, 731.068, 733.425, 736.758, 740.552, 744.309, 747.556, 749.836, 750.738, 750.064, 748.089, 745.709, 744.079, 743.967, 745.478, 748.275, 751.858, 755.720, 759.380, 762.370, 764.232, 764.592, 763.381, 761.111, 758.863, 757.731, 758.236, 760.276, 763.425, 767.177, 771.041, 774.545, 777.218, 778.606, 778.400, 776.709, 774.292, 772.336, 771.772, 772.864, 775.354, 778.772, 782.622, 786.426, 789.712, 792.003, 792.863, 792.088, 790.011, 787.617, 786.084, 786.111, 787.735, 790.596, 794.210, 798.093, 801.775, 804.777, 806.616, 806.902, 805.588, 803.259, 801.055, 800.036, 800.643, 802.735, 805.891, 809.633, 813.488, 816.982, 819.626, 820.944, 820.631, 818.848, 816.431, 814.567, 814.110, 815.261, 817.751, 821.137, 824.946, 828.709, 831.943, 834.149, 834.884, 833.978)
var float[] cq_rahu = array.from(178.622, 177.033, 175.443, 173.853, 172.263, 170.674, 169.084, 167.494, 165.904, 164.314, 162.725, 161.135, 159.545, 157.955, 156.366, 154.776, 153.186, 151.596, 150.007, 148.417, 146.827, 145.237, 143.648, 142.058, 140.468, 138.878, 137.289, 135.699, 134.109, 132.519, 130.930, 129.340, 127.750, 126.160, 124.570, 122.981, 121.391, 119.801, 118.211, 116.622, 115.032, 113.442, 111.852, 110.263, 108.673, 107.083, 105.493, 103.904, 102.314, 100.724, 99.134, 97.545, 95.955, 94.365, 92.775, 91.186, 89.596, 88.006, 86.416, 84.826, 83.237, 81.647, 80.057, 78.467, 76.878, 75.288, 73.698, 72.108, 70.519, 68.929, 67.339, 65.749, 64.160, 62.570, 60.980, 59.390, 57.801, 56.211, 54.621, 53.031, 51.442, 49.852, 48.262, 46.672, 45.082, 43.493, 41.903, 40.313, 38.723, 37.134, 35.544, 33.954, 32.364, 30.775, 29.185, 27.595, 26.005, 24.416, 22.826, 21.236, 19.646, 18.057, 16.467, 14.877, 13.287, 11.698, 10.108, 8.518, 6.928, 5.338, 3.749, 2.159, 0.569, -1.021, -2.610, -4.200, -5.790, -7.380, -8.969, -10.559, -12.149, -13.739, -15.328, -16.918, -18.508, -20.098, -21.687, -23.277, -24.867, -26.457, -28.046, -29.636, -31.226, -32.816, -34.406, -35.995, -37.585, -39.175, -40.765, -42.354, -43.944, -45.534, -47.124, -48.713, -50.303, -51.893, -53.483, -55.072, -56.662, -58.252, -59.842, -61.431, -63.021, -64.611, -66.201, -67.790, -69.380, -70.970, -72.560, -74.150, -75.739, -77.329, -78.919, -80.509, -82.098, -83.688, -85.278, -86.868, -88.457, -90.047, -91.637, -93.227, -94.816, -96.406, -97.996, -99.586, -101.175, -102.765, -104.355, -105.945, -107.534, -109.124, -110.714, -112.304, -113.894, -115.483, -117.073, -118.663, -120.253, -121.842, -123.432, -125.022, -126.612, -128.201, -129.791, -131.381, -132.971, -134.560, -136.150, -137.740, -139.330, -140.919, -142.509, -144.099, -145.689, -147.278, -148.868, -150.458, -152.048, -153.638, -155.227, -156.817, -158.407, -159.997, -161.586, -163.176, -164.766, -166.356, -167.945, -169.535, -171.125, -172.715, -174.304, -175.894, -177.484, -179.074, -180.663, -182.253, -183.843, -185.433, -187.022, -188.612, -190.202, -191.792, -193.382, -194.971, -196.561, -198.151, -199.741, -201.330, -202.920, -204.510, -206.100, -207.689, -209.279, -210.869, -212.459, -214.048, -215.638, -217.228, -218.818, -220.407, -221.997, -223.587, -225.177, -226.766, -228.356, -229.946, -231.536, -233.126, -234.715, -236.305, -237.895, -239.485, -241.074, -242.664, -244.254, -245.844, -247.433, -249.023, -250.613, -252.203, -253.792, -255.382, -256.972, -258.562, -260.151, -261.741, -263.331, -264.921, -266.510, -268.100, -269.690, -271.280, -272.870, -274.459, -276.049, -277.639, -279.229, -280.818, -282.408, -283.998, -285.588, -287.177, -288.767, -290.357, -291.947, -293.536, -295.126, -296.716, -298.306, -299.895, -301.485, -303.075, -304.665, -306.254, -307.844, -309.434, -311.024, -312.614, -314.203, -315.793, -317.383, -318.973, -320.562, -322.152, -323.742, -325.332, -326.921, -328.511, -330.101, -331.691, -333.280, -334.870, -336.460, -338.050, -339.639, -341.229, -342.819, -344.409, -345.998, -347.588, -349.178, -350.768, -352.358, -353.947, -355.537, -357.127, -358.717, -360.306, -361.896, -363.486, -365.076, -366.665, -368.255, -369.845, -371.435, -373.024, -374.614, -376.204, -377.794, -379.383, -380.973, -382.563, -384.153, -385.742, -387.332, -388.922, -390.512, -392.102, -393.691, -395.281, -396.871, -398.461, -400.050, -401.640, -403.230, -404.820, -406.409, -407.999, -409.589, -411.179, -412.768, -414.358, -415.948, -417.538, -419.127, -420.717, -422.307, -423.897, -425.486, -427.076, -428.666, -430.256, -431.845, -433.435, -435.025, -436.615, -438.205, -439.794, -441.384, -442.974, -444.564, -446.153, -447.743, -449.333, -450.923, -452.512, -454.102, -455.692, -457.282, -458.871, -460.461, -462.051, -463.641, -465.230, -466.820, -468.410, -470.000, -471.589, -473.179, -474.769, -476.359, -477.949, -479.538, -481.128, -482.718, -484.308, -485.897, -487.487, -489.077, -490.667, -492.256, -493.846, -495.436, -497.026, -498.615, -500.205, -501.795, -503.385, -504.974, -506.564, -508.154, -509.744, -511.333, -512.923, -514.513, -516.103, -517.692, -519.282, -520.872, -522.462, -524.052, -525.641, -527.231, -528.821, -530.411, -532.000, -533.590, -535.180, -536.770, -538.359, -539.949, -541.539, -543.129, -544.718, -546.308, -547.898, -549.488, -551.077, -552.667, -554.257, -555.847, -557.436, -559.026, -560.616, -562.206, -563.796, -565.385, -566.975, -568.565, -570.155, -571.744, -573.334, -574.924, -576.514, -578.103, -579.693, -581.283, -582.873, -584.462, -586.052, -587.642, -589.232, -590.821, -592.411, -594.001, -595.591)

cq_slow(arr, jd) =>
    float pos = (jd - cq_jd0) / cq_step
    int n = array.size(arr)
    int i = math.max(0, math.min(n - 2, int(math.floor(pos))))
    float frac = math.max(0.0, math.min(1.0, pos - i))
    float a = array.get(arr, i)
    float b = array.get(arr, i + 1)
    (a + (b - a) * frac) % 360.0

// ----------------------------------------------------------------------------- compute
float jd  = julianDay()
float T   = (jd - 2451545.0) / 36525.0
float ayan = ayanamsa(T)

float sunTrop  = sunLongitude(T)
float moonTrop = moonLongitude(T)
float sunSid   = norm360(sunTrop - ayan)
float moonSid  = norm360(moonTrop - ayan)
float moonLat  = moonLatitude(T)

float guruSid  = cq_slow(cq_guru, jd)
float shaniSid = cq_slow(cq_shani, jd)
float rahuSid  = cq_slow(cq_rahu, jd)

// --- Panchanga ---------------------------------------------------------------------
float elong    = norm360(moonSid - sunSid)
int   tithiIdx = int(math.floor(elong / TITHI_DEG))              // 0..29
int   tithiNum = (tithiIdx % 15) + 1                             // 1..15
bool  shukla   = tithiIdx < 15
int   nakIdx   = int(math.floor(moonSid / NAK_DEG))              // 0..26
int   padaIdx  = int(math.floor((moonSid % NAK_DEG) / (NAK_DEG / 4.0))) + 1
int   yogaIdx  = int(math.floor(norm360(sunSid + moonSid) / NAK_DEG))
int   karSlot  = int(math.floor(elong / KARANA_DEG))             // 0..59

// Karana identity: Kimstughna at slot 0, the seven chara karanas repeating across
// slots 1..56, then Shakuni, Chatushpada and Naga closing the lunar month.
int karIdx = karSlot == 0 ? 10 : karSlot >= 57 ? 7 + (karSlot - 57) : (karSlot - 1) % 7
bool isVishti = karIdx == 6

bool isPurnima = tithiIdx == 14
bool isAmavasya = tithiIdx == 29
bool isRikta = tithiNum == 4 or tithiNum == 9 or tithiNum == 14

// Gandanta: the water–fire junctions at 0°, 120° and 240°, ±3°20'.
float gdist = math.min(math.min(math.abs(((moonSid - 0.0 + 180.0) % 360.0) - 180.0), math.abs(((moonSid - 120.0 + 180.0) % 360.0) - 180.0)), math.abs(((moonSid - 240.0 + 180.0) % 360.0) - 180.0))
bool inGandanta = gdist <= 3.3333

// Grahana: a syzygy with the Moon inside the ecliptic limit.
bool nearSyzygy = elong < 14.0 or elong > 346.0 or math.abs(elong - 180.0) < 14.0
bool eclipseWindow = nearSyzygy and math.abs(moonLat) < 1.5

// --- Composites ---------------------------------------------------------------------
// Kala Taranga: the cosmic tide. A weighted sum of the aspect geometry between the
// slow grahas and the luminaries, standardised on the chart's own history.
float gsSep = math.abs(((guruSid - shaniSid + 180.0) % 360.0) - 180.0)
float grSep = math.abs(((guruSid - rahuSid + 180.0) % 360.0) - 180.0)
float srSep = math.abs(((shaniSid - rahuSid + 180.0) % 360.0) - 180.0)
float mgSep = math.abs(((moonSid - guruSid + 180.0) % 360.0) - 180.0)
float msSep = math.abs(((moonSid - shaniSid + 180.0) % 360.0) - 180.0)

aspectK(sep, angle, orb) => math.max(0.0, 1.0 - math.abs(sep - angle) / orb)

float ktwRaw = 0.0
ktwRaw := ktwRaw + 1.00 * (aspectK(gsSep, 0.0, 12.0) - aspectK(gsSep, 90.0, 8.0) + aspectK(gsSep, 120.0, 8.0))
ktwRaw := ktwRaw + 0.70 * (aspectK(grSep, 120.0, 8.0) - aspectK(grSep, 0.0, 10.0))
ktwRaw := ktwRaw - 0.90 * aspectK(srSep, 0.0, 10.0)
ktwRaw := ktwRaw + 0.50 * (aspectK(mgSep, 0.0, 8.0) + aspectK(mgSep, 120.0, 7.0))
ktwRaw := ktwRaw - 0.40 * aspectK(msSep, 0.0, 8.0)
ktwRaw := ktwRaw + 0.35 * (shukla ? 1.0 : -1.0)

float ktw = ta.sma(ktwRaw, 5)
float ktwZ = (ktw - ta.sma(ktw, 200)) / math.max(ta.stdev(ktw, 200), 0.0001)

// Bhaya (panic) index: the classical stress terms, 0..1.
float bhyRaw = 0.0
bhyRaw := bhyRaw + (isVishti ? 0.22 : 0.0)
bhyRaw := bhyRaw + (eclipseWindow ? 0.26 : 0.0)
bhyRaw := bhyRaw + (inGandanta ? 0.18 : 0.0)
bhyRaw := bhyRaw + (isRikta ? 0.14 : 0.0)
bhyRaw := bhyRaw + 0.20 * aspectK(srSep, 0.0, 12.0)
bhyRaw := bhyRaw + (shukla ? 0.0 : 0.10)
float bhy = math.min(1.0, bhyRaw)

// --- Regime ---------------------------------------------------------------------------
// Trend and volatility define the regime; the astro layer supplies the risk overlay.
float emaF = ta.ema(close, emaFast)
float emaS = ta.ema(close, emaSlow)
float emaT = ta.ema(close, emaTrend)
float rv   = ta.stdev(ta.roc(close, 1), 20) * math.sqrt(252)
float rvRank = ta.percentrank(rv, 252)

bool trendUp   = close > emaT and emaF > emaS
bool trendDown = close < emaT and emaF < emaS
bool turbulent = rvRank > 85

// 0 Vriddhi, 1 Sthira, 2 Kshaya, 3 Kshobha
int regime = turbulent ? 3 : trendUp ? 0 : trendDown ? 2 : 1

color regimeCol = regime == 0 ? color.new(#22c55e, 88) : regime == 1 ? color.new(#f59e0b, 90) : regime == 2 ? color.new(#ef4444, 88) : color.new(#a855f7, 85)

bgcolor(showBands ? regimeCol : na, title="Regime band")
bgcolor(showEclipse and eclipseWindow ? color.new(#a855f7, 70) : na, title="Grahana window")
bgcolor(showVishti and isVishti ? color.new(#ef4444, 82) : na, title="Vishti karana")

// --- Markers -----------------------------------------------------------------------------
var string[] NAK = array.from("Ashvini","Bharani","Krittika","Rohini","Mrigashira","Ardra","Punarvasu","Pushya","Ashlesha","Magha","P.Phalguni","U.Phalguni","Hasta","Chitra","Svati","Vishakha","Anuradha","Jyeshtha","Mula","P.Ashadha","U.Ashadha","Shravana","Dhanishtha","Shatabhishaj","P.Bhadrapada","U.Bhadrapada","Revati")
var string[] TITHI = array.from("Pratipada","Dvitiya","Tritiya","Chaturthi","Panchami","Shashthi","Saptami","Ashtami","Navami","Dashami","Ekadashi","Dvadashi","Trayodashi","Chaturdashi","Purnima")
var string[] YOGA = array.from("Vishkambha","Priti","Ayushman","Saubhagya","Shobhana","Atiganda","Sukarma","Dhriti","Shula","Ganda","Vriddhi","Dhruva","Vyaghata","Harshana","Vajra","Siddhi","Vyatipata","Variyana","Parigha","Shiva","Siddha","Sadhya","Shubha","Shukla","Brahma","Indra","Vaidhriti")
var string[] KARANA = array.from("Bava","Balava","Kaulava","Taitila","Gara","Vanija","Vishti","Shakuni","Chatushpada","Naga","Kimstughna")
var string[] RASHI = array.from("Mesha","Vrishabha","Mithuna","Karka","Simha","Kanya","Tula","Vrischika","Dhanu","Makara","Kumbha","Meena")

string nakName   = array.get(NAK, nakIdx)
string tithiName = (shukla ? "Shukla " : "Krishna ") + (isAmavasya ? "Amavasya" : array.get(TITHI, tithiNum - 1))
string yogaName  = array.get(YOGA, yogaIdx)
string karName   = array.get(KARANA, karIdx)

bool nakChanged = nakIdx != nakIdx[1]
if showNakLabel and nakChanged and not na(nakIdx[1])
    label.new(bar_index, low, nakName, style=label.style_label_up, color=color.new(#334155, 20), textcolor=#e2e8f0, size=size.tiny)

plotshape(showSyzygy and isPurnima, title="Purnima", style=shape.circle, location=location.abovebar, color=color.new(#fbbf24, 0), size=size.tiny)
plotshape(showSyzygy and isAmavasya, title="Amavasya", style=shape.circle, location=location.abovebar, color=color.new(#475569, 0), size=size.tiny)

// --- Trend plot ---------------------------------------------------------------------------
plot(emaT, "Trend EMA", color=color.new(#64748b, 40), linewidth=1)
plot(emaF, "Fast EMA", color=color.new(#22d3ee, 30), linewidth=1)

// --- Info table -----------------------------------------------------------------------------
var table info = na
if barstate.islast and showTable
    pos = tablePos == "Top right" ? position.top_right : tablePos == "Top left" ? position.top_left : tablePos == "Bottom right" ? position.bottom_right : position.bottom_left
    info := table.new(pos, 2, 13, bgcolor=color.new(#0f172a, 10), border_color=color.new(#334155, 40), border_width=1)
    regimeName = regime == 0 ? "VRIDDHI" : regime == 1 ? "STHIRA" : regime == 2 ? "KSHAYA" : "KSHOBHA"
    regimeTxt  = regime == 0 ? #22c55e : regime == 1 ? #f59e0b : regime == 2 ? #ef4444 : #a855f7

    table.cell(info, 0, 0, "ChandraQuant", text_color=#22d3ee, text_size=size.small)
    table.cell(info, 1, 0, "Kāla-Chakra",  text_color=#94a3b8, text_size=size.small)
    table.cell(info, 0, 1, "Regime",    text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 1, regimeName,  text_color=regimeTxt, text_size=size.small)
    table.cell(info, 0, 2, "Tithi",     text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 2, tithiName,   text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 3, "Nakshatra", text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 3, nakName + " · " + str.tostring(padaIdx), text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 4, "Yoga",      text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 4, yogaName,    text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 5, "Karana",    text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 5, karName,     text_color=isVishti ? #ef4444 : #e2e8f0, text_size=size.small)
    table.cell(info, 0, 6, "Chandra",   text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 6, array.get(RASHI, int(moonSid / 30.0)) + " " + str.tostring(moonSid % 30.0, "#.#") + "°", text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 7, "Surya",     text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 7, array.get(RASHI, int(sunSid / 30.0)) + " " + str.tostring(sunSid % 30.0, "#.#") + "°", text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 8, "Guru",      text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 8, array.get(RASHI, int(guruSid / 30.0)), text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 9, "Shani",     text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 9, array.get(RASHI, int(shaniSid / 30.0)), text_color=#e2e8f0, text_size=size.small)
    table.cell(info, 0, 10, "Kāla Taraṅga", text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 10, str.tostring(ktwZ, "#.##"), text_color=ktwZ > 0 ? #22c55e : #ef4444, text_size=size.small)
    table.cell(info, 0, 11, "Bhaya",    text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 11, str.tostring(bhy * 100, "#") + "%", text_color=bhy > 0.5 ? #ef4444 : #22c55e, text_size=size.small)
    table.cell(info, 0, 12, "Ayanamsa", text_color=#94a3b8, text_size=size.small)
    table.cell(info, 1, 12, str.tostring(ayan, "#.###") + "°", text_color=#64748b, text_size=size.small)

// --- Alerts ------------------------------------------------------------------------------------
alertcondition(regime != regime[1], "Regime change", "ChandraQuant: regime has shifted")
alertcondition(nakChanged, "Nakshatra change", "ChandraQuant: Chandra enters a new nakshatra")
alertcondition(isVishti and not isVishti[1], "Vishti karana begins", "ChandraQuant: Vishti (Bhadra) — abstention window")
alertcondition(eclipseWindow and not eclipseWindow[1], "Grahana window", "ChandraQuant: eclipse window opens")

// --- Exposed for other scripts --------------------------------------------------------------------
plot(moonSid, "Chandra sidereal", display=display.data_window)
plot(sunSid,  "Surya sidereal",   display=display.data_window)
plot(ktwZ,    "Kala Taranga",     display=display.data_window)
plot(bhy,     "Bhaya",            display=display.data_window)
plot(nakIdx,  "Nakshatra index",  display=display.data_window)
plot(tithiIdx,"Tithi index",      display=display.data_window)

Overview

ChandraQuant — Kāla-Chakra calculates Sun and Moon ecliptic longitudes from Meeus periodic series, converts them to the sidereal zodiac with the Lahiri ayanamsa, and marks nakshatra changes, Purnima and Amavasya, eclipse intervals, and Vishti karana on the price chart. Optional background bands show the astronomical regime. Fast, slow, and trend exponential moving averages supply price context, and an info table lists the current readings. All drawings are deterministic functions of time and do not repaint.

Details

Published by

vinitpatil519 on GitHub

Draws

On the price chart

Markets

Indices

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Regime background bandsbooltrueshowBands
Nakshatra change markersbooltrueshowNakLabel
Purnima / Amavasya glyphsbooltrueshowSyzygy
Grahana (eclipse) shadingbooltrueshowEclipse
Vishti (Bhadra) karana marksbooltrueshowVishti
Info tablebooltrueshowTable
Table positionstringTop righttablePos
Fast EMAint20emaFast
Slow EMAint50emaSlow
Trend EMAint200emaTrend
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

228 stars

TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi

Indicator v6 Screeners & dashboardsTrend
Updated 3 months ago · None stated GitHub repository of TradersPost Trading Checklist
92 stars

This indicator plots five moving averages of a chosen source on the price chart, defaulting to EMA lengths 10, 20, 30, 40 and 50. The user can switch the average type to SMA, WMA or HMA and recolor each line. Wide translucent glows sit under the lines, and sof

Indicator v5 TrendMoving averages
Updated 2 months ago · Custom licence GitHub repository of Moon Dev Rainbow MA Ribbon 10-50

EMA Ribbon Overlay

by iamrichardD
57 stars

Calculates exponential moving averages for fast, pivot, and slow lengths along with optional 50, 100, and 200 simple moving average context lines. It visualizes bullish and bearish ribbon fills on the main price chart alongside MACD calculations to generate ea

Indicator v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon Overlay
53 stars

This indicator analyzes historical candle direction and price range over a configurable lookback window to gauge market trend. It categorizes trend direction using candle count, price range sum, or both. Signals are filtered using a Simple Moving Average to en

Indicator v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of Candle Counter + MA + RSI + Mode
43 stars

This indicator evaluates market momentum and risk by calculating trend metrics and volatility stats, displaying them in an on-chart table pane. It measures short-term and long-term trend strength via two MACD configurations built on three customizable EMA leng

Indicator v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of Trend Strength & Volatility

Market Monitor - 15m

by chris-c-thomas
14 stars

Market Monitor - 15m is a directional bias chart overlay designed for 15-minute intraday chart analysis. It calculates a triple exponential moving average ribbon with EMA cloud shading, session VWAP with multiplier bands, prior day levels, a 30-minute opening

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Market Monitor - 15m

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers