strategy · own pane · open source

Stochastic crossover strategy (14, 3, 3)

Stochastic %K/%D crossover: buy a bullish cross below 20, exit when %K rises above 80. Plain-English rules, copyable code and a backtest with costs included. Deepwick Script runs a subset of Pine Script.

v1Updated 3 Oct 2026▲ 0 users
Running…
Loading chart…

What the Stochastic Crossover strategy does

Classic Stochastic %K/%D crossover long-only: enter when %K crosses above %D inside the oversold zone, exit when %K leaves the overbought zone.

  • 14/3/3 with 20/80 thresholds is the textbook setting.
  • Raise Length to filter noise; lower it for snappier reversals.
  • Pair with an RSI divergence or volume confirmation for cleaner entries.

Entry and exit rules

    Language reference: Deepwick Script.

    Default inputs

    InputDefaultMinMax
    %K Length14550
    %K Smoothing3110
    %D Smoothing3110
    Oversold20545
    Stop Loss %20.510
    Take Profit %6020

    How Deepwick fills this strategy

    • Market orders fill at the next bar's open.
    • Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
    • Gaps fill at the open.
    • Commission is charged on every fill, and slippage applies to market and stop fills, as set in strategy().

    More on how backtests work

    Source code

    Deepwick Script, a subset of Pine Script · read-only

    //@version=6
    strategy("Stochastic Cross", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
    len = input.int(14, "%K Length", minval=5, maxval=50, step=1)
    kSmooth = input.int(3, "%K Smoothing", minval=1, maxval=10, step=1)
    dSmooth = input.int(3, "%D Smoothing", minval=1, maxval=10, step=1)
    oversold = input.int(20, "Oversold", minval=5, maxval=45, step=1)
    stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
    tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
    colorLine = input.color("color.blue", "Color  Line")
    colorMid = input.color("color.orange", "Color  Mid")
    colorUp = input.color("color.green", "Color  Up")
    colorDown = input.color("color.red", "Color  Down")
    colorNeutral = input.color("color.gray", "Color  Neutral")
    hh = ta.highest(high, len)
    ll = ta.lowest(low, len)
    kRaw = 100.0 * (close - ll) / (hh - ll)
    k = ta.sma(kRaw, kSmooth)
    d = ta.sma(k, dSmooth)
    longSignal = strategy.position_size == 0 and ta.crossover(k, d) and k < oversold
    exitSignal = strategy.position_size > 0 and k > 80
    if longSignal
        strategy.entry("Long", strategy.long)
    if strategy.position_size > 0
        strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
    if exitSignal
        strategy.close("Long", comment="Stoch exit")
    hline(80, "Overbought", color=colorNeutral, linestyle=hline.style_dashed)
    hline(20, "Oversold", color=colorNeutral, linestyle=hline.style_dashed)
    p__K = plot(k, "%K", color=colorLine, linewidth=2)
    p__D = plot(d, "%D", color=colorMid)
    plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
    plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
    alertcondition(longSignal, "Stoch long entry", "Stochastic crossed up inside oversold")
    alertcondition(exitSignal, "Stoch exit", "Stochastic left overbought")
    

    Run it in Deepwick

    1. Open a chart of any crypto pair or CFD.
    2. Click “Scripts” and add this strategy.
    3. Press Run and read the trades in the Strategy Tester.
    Start free

    FAQ

    Is this the slow or the fast Stochastic?

    It is the slow Stochastic: %K is smoothed with a 3-period SMA, and %D is a 3-period SMA of that.

    Is this the Stochastic RSI strategy?

    No. Stochastic RSI applies the stochastic formula to RSI values. See the Stochastic RSI indicator page; a Stoch RSI strategy page is not published yet.

    Why only crosses below 20?

    Requiring the cross inside oversold filters out mid-range crosses, which are the noisiest. Raise the Oversold input to get more trades.

    Comments

    No comments yet.

    Sign in to comment.