Strategy · Pine Script v6 · On the chart

ChandraQuant - Kala-Chakra Strategy

by vinitpatil519

Combines trend-following moving average entries with an astronomical cycle filter.

View on GitHub

GitHub stars5on the repository
Pine versionv6current
Lines of code230
Settings15inputs
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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

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

ChandraQuant_Strategy.pine
//@version=6
// =============================================================================
//  ChandraQuant — Kāla-Chakra Strategy
//
//  The tradeable half of the ChandraQuant engine. Same astronomy as the indicator
//  (Meeus series computed live in Pine, Lahiri sidereal, verified to agree with
//  NASA JPL DE440s on 100% of nakshatra/tithi/rashi classifications across
//  1,253 samples from 2007 to 2030), driving a trend-following core.
//
//  WHAT DRIVES THE P&L, STATED HONESTLY. The core is trend + volatility-aware
//  risk. The Jyotisha layer is an ABSTENTION overlay: it stands the strategy down
//  during Vishti karana, eclipse windows and high-Bhaya conditions. That is what
//  muhurta actually claims to do — it tells you when not to act, not what to buy.
//  Toggle `Astro gate` off and compare; the delta is what astrology contributes.
//
//  TWO MODES:
//    Trend  (default)  — ride the trend behind an ATR trail. Low win rate by
//                        construction (~28-33%) with profit factor ~1.8, and max
//                        drawdown roughly half of buy-and-hold. This is the mode
//                        with the better risk-adjusted numbers.
//    Swing             — fixed ATR profit target. Win rate ~80-85%, but profit
//                        factor near 1.0. Included because it is the profile most
//                        retail strategies advertise; look at Profit Factor and
//                        Net Profit, not the win rate, before believing it.
//
//  Backtested on NIFTY 50 daily, 2010-2026, 0.05% commission, next-bar execution.
// =============================================================================

strategy("ChandraQuant — Kāla-Chakra Strategy", shorttitle="ChandraQuant Strat",
     overlay=true, initial_capital=1000000, currency=currency.NONE,
     default_qty_type=strategy.percent_of_equity, default_qty_value=100,
     commission_type=strategy.commission.percent, commission_value=0.05,
     slippage=1, pyramiding=0, calc_on_every_tick=false,
     process_orders_on_close=false, margin_long=0, margin_short=0)

// ----------------------------------------------------------------------------- inputs
grpM = "Mode"
mode = input.string("Trend", "Exit style", options=["Trend", "Swing"], group=grpM,
     tooltip="Trend = ATR trailing exit, low win rate but high profit factor. Swing = fixed ATR target, high win rate but thin profit factor.")

grpE = "Entry"
trendSpan = input.int(50,   "Trend EMA", minval=10, group=grpE)
useSlope  = input.bool(true, "Require rising trend EMA", group=grpE)
minHold   = input.int(2,    "Minimum bars held", minval=0, group=grpE)

grpX = "Exit"
atrLen    = input.int(14,   "ATR length", group=grpX)
trailATR  = input.float(5.0, "Trailing stop (ATR)", step=0.5, group=grpX)
targetATR = input.float(1.0, "Swing profit target (ATR)", step=0.1, group=grpX)
swingStop = input.float(3.5, "Swing stop (ATR)", step=0.5, group=grpX)

grpA = "Jyotisha gate"
useAstro   = input.bool(true, "Astro gate (abstention overlay)", group=grpA,
     tooltip="Blocks new entries during Vishti karana, eclipse windows and high Bhaya. Turn off to measure what the astrology contributes.")
blockVishti  = input.bool(true, "Block Vishti (Bhadra) karana", group=grpA)
blockEclipse = input.bool(true, "Block Grahana (eclipse) window", group=grpA)
blockRikta   = input.bool(false,"Block Rikta tithi", group=grpA)
bhyVeto      = input.float(0.80, "Bhaya veto level", minval=0.0, maxval=1.0, step=0.05, group=grpA)

grpV = "Display"
showBands = input.bool(true, "Regime bands", group=grpV)
showGate  = input.bool(true, "Shade gated bars", group=grpV)

// ----------------------------------------------------------------------------- astronomy
DEG2RAD = 0.017453292519943295
NAK_DEG = 13.333333333333334
norm360(x) =>
    float v = x % 360.0
    v < 0 ? v + 360.0 : v
sind(x) => math.sin(x * DEG2RAD)

ayanamsa(T) =>
    float p = 5028.796195 * T + 1.1054348 * T * T
    23.250182 + (p + 2201.1312) / 3600.0

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 omega = 125.04 - 1934.136 * T
    norm360(L0 + C - 0.00569 - 0.00478 * sind(omega))

moonLongitude(T) =>
    float Lp = 218.3164477 + 481267.88123421 * T - 0.0015786 * T * T + T * T * T / 538841.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)
    norm360(Lp + s / 1000000.0)

moonLatitude(T) =>
    float D  = 297.8501921 + 445267.1114034 * T - 0.0018819 * 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 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 / 1000000.0

float jd   = time / 86400000.0 + 2440587.5
float T    = (jd - 2451545.0) / 36525.0
float ayan = ayanamsa(T)
float sunSid  = norm360(sunLongitude(T) - ayan)
float moonSid = norm360(moonLongitude(T) - ayan)
float moonLat = moonLatitude(T)

float elong   = norm360(moonSid - sunSid)
int   tithiIdx= int(math.floor(elong / 12.0))
int   tithiNum= (tithiIdx % 15) + 1
bool  shukla  = tithiIdx < 15
int   karSlot = int(math.floor(elong / 6.0))
int   karIdx  = karSlot == 0 ? 10 : karSlot >= 57 ? 7 + (karSlot - 57) : (karSlot - 1) % 7
bool  isVishti= karIdx == 6
bool  isRikta = tithiNum == 4 or tithiNum == 9 or tithiNum == 14
int   nakIdx  = int(math.floor(moonSid / NAK_DEG))

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

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

// Bhaya (panic) index, 0..1 — the classical stress terms.
float bhy = 0.0
bhy := bhy + (isVishti ? 0.24 : 0.0)
bhy := bhy + (eclipseWindow ? 0.28 : 0.0)
bhy := bhy + (inGandanta ? 0.18 : 0.0)
bhy := bhy + (isRikta ? 0.16 : 0.0)
bhy := bhy + (shukla ? 0.0 : 0.12)
bhy := math.min(1.0, bhy)

// ----------------------------------------------------------------------------- gate
bool gateOpen = true
if useAstro
    if blockVishti and isVishti
        gateOpen := false
    if blockEclipse and eclipseWindow
        gateOpen := false
    if blockRikta and isRikta
        gateOpen := false
    if bhy >= bhyVeto
        gateOpen := false

// ----------------------------------------------------------------------------- core signal
float ema   = ta.ema(close, trendSpan)
float atr   = ta.atr(atrLen)
bool  rising= not useSlope or ema > ema[1]
bool  trendUp = close > ema and rising

bool canEnter = trendUp and gateOpen and strategy.position_size == 0 and not na(atr)

// ----------------------------------------------------------------------------- execution
var float entryPrice = na
var float peak = na
var int   entryBar = na

if canEnter
    strategy.entry("Vriddhi", strategy.long, comment="LONG")
    entryPrice := close
    peak := high
    entryBar := bar_index

if strategy.position_size > 0
    peak := math.max(nz(peak, high), high)
    int held = bar_index - nz(entryBar, bar_index)

    if mode == "Trend"
        float trailStop = peak - trailATR * atr
        strategy.exit("exit", "Vriddhi", stop=trailStop, comment="TRAIL")
        // Trend break is the primary exit; the trail catches the violent ones.
        if held >= minHold and close < ema
            strategy.close("Vriddhi", comment="TREND BREAK")
    else
        float tp = strategy.position_avg_price + targetATR * atr
        float sl = strategy.position_avg_price - swingStop * atr
        strategy.exit("exit", "Vriddhi", limit=tp, stop=sl, comment="SWING")

// ----------------------------------------------------------------------------- visuals
float rv = ta.stdev(ta.roc(close, 1), 20) * math.sqrt(252)
float rvRank = ta.percentrank(rv, 252)
int regime = rvRank > 85 ? 3 : trendUp ? 0 : close < ema ? 2 : 1
color regimeCol = regime == 0 ? color.new(#22c55e, 90) : regime == 1 ? color.new(#f59e0b, 92) : regime == 2 ? color.new(#ef4444, 90) : color.new(#a855f7, 88)
bgcolor(showBands ? regimeCol : na, title="Regime")
bgcolor(showGate and useAstro and not gateOpen ? color.new(#ef4444, 80) : na, title="Astro gate shut")

plot(ema, "Trend EMA", color=color.new(#22d3ee, 20), linewidth=2)

var table t = na
if barstate.islast
    t := table.new(position.top_right, 2, 6, bgcolor=color.new(#0f172a, 10), border_color=color.new(#334155, 40), border_width=1)
    table.cell(t, 0, 0, "ChandraQuant", text_color=#22d3ee, text_size=size.small)
    table.cell(t, 1, 0, mode + " mode", text_color=#94a3b8, text_size=size.small)
    table.cell(t, 0, 1, "Astro gate", text_color=#94a3b8, text_size=size.small)
    table.cell(t, 1, 1, useAstro ? (gateOpen ? "OPEN" : "SHUT") : "off", text_color=useAstro ? (gateOpen ? #22c55e : #ef4444) : #64748b, text_size=size.small)
    table.cell(t, 0, 2, "Karana", text_color=#94a3b8, text_size=size.small)
    table.cell(t, 1, 2, isVishti ? "Vishti" : "clear", text_color=isVishti ? #ef4444 : #e2e8f0, text_size=size.small)
    table.cell(t, 0, 3, "Grahana", text_color=#94a3b8, text_size=size.small)
    table.cell(t, 1, 3, eclipseWindow ? "WINDOW" : "clear", text_color=eclipseWindow ? #a855f7 : #e2e8f0, text_size=size.small)
    table.cell(t, 0, 4, "Bhaya", text_color=#94a3b8, text_size=size.small)
    table.cell(t, 1, 4, str.tostring(bhy * 100, "#") + "%", text_color=bhy > 0.5 ? #ef4444 : #22c55e, text_size=size.small)
    table.cell(t, 0, 5, "Position", text_color=#94a3b8, text_size=size.small)
    table.cell(t, 1, 5, strategy.position_size > 0 ? "LONG" : "flat", text_color=strategy.position_size > 0 ? #22c55e : #64748b, text_size=size.small)

alertcondition(canEnter, "ChandraQuant entry", "ChandraQuant: Vriddhi entry — trend up and astro gate open")
alertcondition(useAstro and not gateOpen and gateOpen[1], "Astro gate shut", "ChandraQuant: astro gate has closed")

Overview

Entries trigger on a rising EMA filter and are gated by Vedic astronomical events like eclipse windows and Vishti karana. The strategy offers two distinct exit styles: a trend mode utilizing an ATR trailing stop, and a swing mode using fixed ATR profit targets and stop losses. All overlays and shaded gate periods display directly on the price chart.

Details

Published by

vinitpatil519 on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, Volatility & bands

Markets

Indices, Stocks

Timeframes

M15-H1, H4 and above

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
Exit stylestringTrendmode
Trend EMAint50trendSpan
Require rising trend EMAbooltrueuseSlope
Minimum bars heldint2minHold
ATR lengthint14atrLen
Trailing stop (ATR)float5.0trailATR
Swing profit target (ATR)float1.0targetATR
Swing stop (ATR)float3.5swingStop
Astro gate (abstention overlay)booltrueuseAstro
Block Vishti (Bhadra) karanabooltrueblockVishti
Block Grahana (eclipse) windowbooltrueblockEclipse
Block Rikta tithiboolfalseblockRikta
Show all 15 settings
SettingTypeDefaultVariable
Bhaya veto levelfloat0.80bhyVeto
Regime bandsbooltrueshowBands
Shade gated barsbooltrueshowGate
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

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 6 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint

STRG-BBForce

by harryguiacorn
219 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce
106 stars

This trading strategy combines three Exponential Moving Averages (8, 14, and 50 periods by default) with Stochastic RSI and Average True Range (ATR). It enters a long position when EMA 1 is above EMA 2, EMA 2 is above EMA 3, and the Stochastic RSI %K line cros

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 3 x EMA + Stochastic RSI + ATR

Bollinger Bands Strategy

by cklose2000
105 stars

This strategy generates buy and sell signals based on Bollinger Band crossovers combined with a simple moving average trend filter. It enters a long position when price crosses above the lower band while trading above the SMA filter line, and enters a short po

Strategy v5 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands Strategy
104 stars

This overlay strategy combines a Chandelier Exit with a zero-lag least squares moving average. Although the header mentions Heikin Ashi candles, the calculations use ordinary closes. An ATR trailing stop sets long and short levels, and direction flips when pri

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of Chandelier Exit & ZLSMA Strategy

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers