Strategy · Pine Script v6 · On the chart

SHODAN9 Katana

by Narymunt

SHODAN9 Katana is a trend-following strategy that generates trading signals using Heikin-Ashi candle color transitions.

View on GitHub

GitHub stars4on the repository
Pine versionv6current
Lines of code98
Settings3inputs
LicenceBSD-3-Clause
Last update5 months ago31 May 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

98 lines of Pine Script v6 from katana.pinescript, published under BSD-3-Clause. Keep the author's credit and licence lines when you reuse it.

katana.pinescript
//@version=6
strategy("SHODAN9 Katana", overlay=true, pyramiding=0,process_orders_on_close=true)

// --- parametry SAR (do podglądu na wykresie)
start = input.float(0.02, "SAR start")
increment = input.float(0.24, "SAR increment")
maximum = input.float(0.24,  "SAR max")

// --- Parabolic SAR (dla wizualizacji)
var bool  uptrend    = false
var float EP         = na
var float SAR        = na
var float AF         = start
var float nextBarSAR = na

if bar_index > 0
    firstTrendBar = false
    SAR := nextBarSAR
    if bar_index == 1
        float prevSAR = na
        float prevEP  = na
        lowPrev  = low[1]
        highPrev = high[1]
        closeCur = close
        closePrev = close[1]
        if closeCur > closePrev
            uptrend := true
            EP := high
            prevSAR := lowPrev
            prevEP := high
        else
            uptrend := false
            EP := low
            prevSAR := highPrev
            prevEP := low
        firstTrendBar := true
        SAR := prevSAR + start * (prevEP - prevSAR)
    if uptrend
        if SAR > low
            firstTrendBar := true
            uptrend := false
            SAR := math.max(EP, high)
            EP := low
            AF := start
    else
        if SAR < high
            firstTrendBar := true
            uptrend := true
            SAR := math.min(EP, low)
            EP := high
            AF := start
    if not firstTrendBar
        if uptrend
            if high > EP
                EP := high
                AF := math.min(AF + increment, maximum)
        else
            if low < EP
                EP := low
                AF := math.min(AF + increment, maximum)
    if uptrend
        SAR := math.min(SAR, low[1])
        if bar_index > 1
            SAR := math.min(SAR, low[2])
    else
        SAR := math.max(SAR, high[1])
        if bar_index > 1
            SAR := math.max(SAR, high[2])
    nextBarSAR := SAR + AF * (EP - SAR)

// --- Heiken-Ashi z regularnych świec
haSym = ticker.heikinashi(syminfo.tickerid)
[haO, haH, haL, haC] = request.security(haSym, timeframe.period, [open, high, low, close])

haBull = haC >= haO
haBear = haC <  haO
firstGreen = haBull and not haBull[1]   // pierwsza zielona po czerwonych
firstRed   = haBear and not haBear[1]   // pierwsza czerwona po zielonych

// --- Wejścia/wyjścia
if barstate.isconfirmed
    if firstGreen
        // zamknij short, jeśli otwarty
        if strategy.position_size < 0
            strategy.cancel("Short")
        // otwórz long
        strategy.entry("Long", strategy.long)
    if firstRed
        // zamknij long, jeśli otwarty
        if strategy.position_size > 0
            strategy.cancel("Long")
        // otwórz short
        strategy.entry("Short", strategy.short)


// --- Rysowanie SAR
plot(SAR,        "SAR",          style=plot.style_cross, linewidth=3, color=color.orange)
plot(nextBarSAR, "Next bar SAR", style=plot.style_cross, linewidth=3, color=color.aqua)

Overview

SHODAN9 Katana enters long positions on the first green Heikin-Ashi candle after a series of red candles and enters short positions on the first red candle following green ones, closing opposing trades upon reversal. The script calculates and plots custom Parabolic SAR levels directly on the price chart. Users can adjust the SAR start, increment, and maximum values. The strategy does not include defined stop loss or take profit rules.

Details

Published by

Narymunt on GitHub

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Candlestick patterns

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
SAR startfloat0.02start
SAR incrementfloat0.24increment
SAR maxfloat0.24maximum
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

Pin Bar Magic v1

by Alorse
330 stars

This strategy trades price action pin bar patterns aligned with moving average trend alignment on the main price chart. It defines uptrends or downtrends using a fan arrangement of three moving averages (6 EMA, 18 EMA, and 50 SMA). Entry conditions require a b

Strategy v4 Candlestick patternsTrend
Updated 2 months ago · None stated GitHub repository of Pin Bar Magic v1
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy

ESU2023-10M - V1

by dearvn
257 stars

ESU2023-10M - V1 is an intraday trend-reversal strategy designed for index futures contracts on the price chart. It calculates a 3-period moving average of candle highs and lows alongside specific three-bar price action patterns to detect short-term swing high

Strategy v5 TrendCandlestick patterns
Updated 6 weeks ago · None stated GitHub repository of ESU2023-10M - V1
106 stars

This strategy trades the three-candle strike pattern filtered by trend direction and time sessions. It calculates market regime using linear regression and exponential or smoothed moving averages to distinguish between ranging and trending conditions. Risk man

Strategy v5 Candlestick patternsTrend
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Candle Strike Strategy

Consecutive Up/Down Strategy

by TWODS-CAPITAL
37 stars

This strategy tracks consecutive bullish and bearish candlestick closes relative to the preceding bar. It enters a long position when price closes higher for a specified number of consecutive bars, and enters a short position when price closes lower for a desi

Strategy v5 Candlestick patternsTrend
Updated 3 years ago · MIT GitHub repository of Consecutive Up/Down Strategy

DI Engulfing A002

by ruckard
13 stars

This strategy executes trades based on candlestick engulfing patterns aligned with a 200-period exponential moving average trend filter. It enters long positions when a bullish engulfing candle follows three consecutive bearish candles while price trades above

Strategy v5 Candlestick patternsTrend
Updated 1 year ago · None stated GitHub repository of DI Engulfing A002

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