SBI Pivot Strategy — Buy/Sell Rules + Real 5-Month Trade Walkthrough

Aa document ma algoStrategy.js (SbiApp/Backend/algoStrategy.js + pivotStrategy.js) ni actual buy/sell logic samjavi che, ane pachi ek real backtest run (2022-06-30 → 2022-11-30, ~5 mahina) na badha 7 trades ne step-by-step explain karya che — kem buy thayu, kem sell thayu, konsa indicator value hata te date pe.

Aa BASE config (production stockConfigs.js ni SBIN.NS entry) thi chalyu che, koi hindsight auto-tuning nathi thayu — etle j aa real/deployable strategy no honest example che.


1. Pivot Levels — pehla aa samjo

Har din na buy/sell decision gai kal na High/Low/Close thi nikalta pivot levels sathe compare thay che (algoStrategy.js:70-82):

pivot = (High + Low + Close) / 3      [gai kal na]

R1 = 2×pivot − Low        R2 = pivot + (High−Low)      R3 = High + 2×(pivot−Low)
S1 = 2×pivot − High        S2 = pivot − (High−Low)      S3 = Low − 2×(High−pivot)

R1/R2/R3 = resistance (upar), S1/S2/S3 = support (niche). Aa levels aaje na trading start thava pehla j fixed thai jay che — koi "future data" nathi vaparai.

2. EMA ane MACD — badha strategy ma vaprai che, pela samjo

EMA (Exponential Moving Average)

EMA = pichla N din na closing price nu "weighted" average, jema recent din ne vadhare weight male che (simple average karta far vadhu responsive). Formula (indicators.js:11-23):

alpha = 2 / (N + 1)
EMA[aaje] = alpha × close[aaje] + (1 − alpha) × EMA[gai kal]

Strategy ma char alag EMA vaprai che, char alag time-frame na trend mate:

Indicator Period Roughly represent kare
EMA10 10 din Bau short-term trend (~2 week)
EMA20 20 din Short-term trend (~1 mahino)
EMA50 50 din Medium-term trend (~2.5 mahina)
EMA200 200 din Long-term trend (~10 mahina, "bade market ni disha")

Close > EMA = price te time-frame na average karta upar che → uptrend. Close < EMA = price average karta niche che → downtrend.

Jyare badhi 4 EMA ekj saathe close ni niche/upar hoy (etle badha time-frame ekmat hoy), te sauthi strong signal gani ye — etle j STRONG BUY ma EMA200 pan check thay che (short + medium + long term, badhu match thavu joiye), pan normal BUY ma fakt EMA10/20/50 j (short+medium).

getTrend() function (algoStrategy.js:191-201) aa EMA20/50/200 na relative order thi trend naam ape:

MACD (Moving Average Convergence Divergence)

MACD momentum indicator che — price ni speed/acceleration mape, direction nahi (EMA e direction batave). Formula (indicators.js:182-210):

MACD line   = EMA(12) − EMA(26)          [short EMA - long EMA]
Signal line = EMA(9) of MACD line
Histogram   = MACD line − Signal line

Aa j karan che ke strategy MACD ne EMA sathe combine kare — EMA batave "price kya che" (upar ke niche), MACD batave "momentum kai disha ma jai rahyu che" (vadhi rahyu che ke ghati rahyu che). Banne match thay (dono bullish, ke dono bearish) tyare j confident signal male.

Trade walkthrough ma je "MACD −2.11 > signal −4.85 (bullish)" jevu lakhyu che tema, actual value negative hoi shake to pan bullish gani shakay — matlab MACD line, signal line karta upar che (−2.11 > −4.85), bhale banne negative hoy. Sign nathi matter karto, comparison matter kare che.

3. BUY thay tyare shu check thay che

SBI config: buyLevel: "pivot", rsiMin: 30, useMacd: true (stockConfigs.js).

Normal BUY (isBuySignal, algoStrategy.js:204-220) — badhi conditions true hovi joiye:

  1. Close price > pivot level (buyLevel="pivot" etle plain pivot, na ke R1/R2/R3)
  2. Close > EMA10, EMA20, EMA50 (price uptrend ma hovo joiye)
  3. RSI(14) > 30 (rsiMin)
  4. MACD line > MACD signal (momentum bullish)

STRONG BUY (isStrongBuySignal, line 223-239) — badhu upar nu + extra:

  1. Upar na badha (pivot break, EMA10/20/50 upar)
  2. Close > EMA200 pan (long-term trend pan bullish)
  3. RSI(14) > 35 (rsiMin + 5, thodu stricter)
  4. MACD bullish

STRONG BUY = badha trend filters (short + medium + long term EMA, higher RSI bar) pass thay — matlab j strongest confirmation.

Jyare koi ek fire thay, available cash thi je share ave te badha kharidi levay (Math.floor(balance / close)), ane te j vaqte stop-loss + targets set thai jay:

Stop Loss = S1 (aajni pivot ni S1, jo entry thi niche hoy)
            fallback: S2, pachi entry × 0.97
risk       = entry − stopLoss
Target 1   = entry + risk × trig     (trig = 2 for SBI)
Target 2   = entry + risk × (trig × 1.5)
Target 3   = entry + risk × (trig × 2.25)

4. SELL kevi rite thay che

4 alag alag rite exit thai shake, je pela fire thay te chale (algoStrategy.js:461-483):

# Trigger Condition
1 Stop Loss / Trailing SL Hit Close ≤ current SL. Target 1 hit thaya pachi SL trail thay che (highest price × (1 − tsl%)) — SBI ma tsl=3%, etle price upar jay etlu SL pan upar khasti jay.
2 STRONG SELL Price < S2 AND < EMA20/50/200 badha, RSI < 40, MACD bearish, bearish-count ≥ 8, trend = "Strong Bearish" — ek j saathe badhu bearish
3 Max SL (fallback) Close < buyPrice × (1 − maxLossPercent). SBI ma maxLossPercent=3%, etle hard 3% loss thi niche jay to bhale koi bijo signal na hoy, exit thai jay
4 Normal SELL signal exitOnS2: true hovathi (SBI config): Close < aajni S2 pivot support → immediately exit. (Fallback rule "EMA20 niche + RSI<50 + MACD bearish" pan che, pan S2 rule pehla check thay che)

Position khali na hoy to disableFallback=false case ma, window ni last din pan force-exit thay ("End of Period").


5. Real Run: 2022-06-30 → 2022-11-30 (5 mahina, ₹5,000 capital)

Result: Algo +20.16% vs Buy&Hold +17.04% — 7 trades, 6 winning, 1 chhoti loss.

Trade 1 — 2022-06-30 → 2022-07-14 (+2.89%)

BUY @ ₹465.90 — pivot=459.93 tuti (close 465.90 > 459.93 ✓), EMA10=457.30 EMA20=457.45 EMA50=466.38 ni upar close, RSI=55 (>30 ✓), MACD −2.11 > signal −4.85 (bullish crossover shorubu thay chhe). Normal BUY (STRONG BUY nathi thayu kem ke close 465.90 hajay EMA200=478.53 ni niche hato).

SELL @ ₹479.35 — "Price < S2". 2022-07-14 na pivot S2 = 479.93 hatu, close 479.35 tenathi niche gayu → tarat j exit. Profit ₹134.50 (+2.89%).

Trade 2 — 2022-07-18 → 2022-08-08 (+6.87%)

BUY @ ₹490.30 — pivot=479.40 tuti gayu, RSI=64, EMA10/20/50 badhi upar, EMA200 (478.87) thi pan upar → STRONG BUY fire thayu.

SELL @ ₹524.00 — "Trailing SL Hit (T1 Hit, SL: ₹525.84)". Price vadhto gayo, Target 1 hit thayu etle SL trail thavanu shuru thayu (highest price ni 3% niche). Price thoduk pachhu padyu ane trailing SL (₹525.84) touch thayu — matlab profit lock thai gayo, position "give up" na thai. Profit ₹337 (+6.87%) — biggest winner ma aa trade.

Trade 3 — 2022-09-05 → 2022-09-16 (+4.25%)

BUY @ ₹538.90 — pivot=535.27 tuti, RSI=62, EMA10/20/50/200 badhi upar → STRONG BUY.

SELL @ ₹561.80 — "Price < S2". S2=562.25, close 561.80 tenathi niche → exit. Profit ₹229 (+4.25%).

Trade 4 — 2022-09-19 → 2022-09-21 (−0.45%)

BUY @ ₹572.25 — pivot=565.37 tuti, RSI=69 (bau strong momentum), badhu upar → STRONG BUY.

SELL @ ₹569.70 — "Price < S2" (2 din j ma). S2=569.85, close 569.70 sahej j niche gayu — bau nazuk margin thi exit thayu, matlab market turant j reverse thai gayu. Ek j chhoti loss aa 5-mahina ma: ₹22.95 (−0.45%). Aa strategy ni discipline batave che — chhoti loss lai levi, wait na karvi.

Trade 5 — 2022-10-18 → 2022-10-28 (+1.48%)

BUY @ ₹562.45 — pivot=537.52 tuti gayu (bau gap-up jevu), RSI=61, EMA badhi upar → STRONG BUY.

SELL @ ₹570.75 — "Price < S2". S2=573.35, close 570.75 niche → exit. Profit ₹83 (+1.48%).

Trade 6 — 2022-10-31 → 2022-11-14 (+4.06%)

BUY @ ₹573.80 — pivot=573.47 sahej j tuti, RSI=62, EMA10/20/50/200 badhi upar → STRONG BUY.

SELL @ ₹597.08 — "Trailing SL Hit (T1 Hit, SL: ₹597.08)". Target 1 hit thai gayu, price ₹614+ sudhi gayu hase, pachi trailing SL touch thayu exact ₹597.08 pe. Profit ₹232.80 (+4.06%).

Trade 7 — 2022-11-15 → 2022-11-30 (+0.27%)

BUY @ ₹600.85 — pivot=596.05 tuti, RSI=63, EMA badhi upar → STRONG BUY.

SELL @ ₹602.45 — "Price < S2". S2=604.45, close 602.45 niche gayu → exit. Nano profit ₹14.40 (+0.27%) — market range ma hatu etle chhoto move.


6. Pattern je aa run ma dekhay che