// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 04 — stochastic-RSI cross
// Purpose: parity test for the ta.rsi → ta.stoch → ta.sma double-smoothing chain
// with overbought/oversold-gated crossover entries.
//
//@version=6
strategy("Stochastic RSI", overlay=true, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)
// === Inputs ===
rsiLen = input.int(14, "RSI Length", minval=1)
stochLen = input.int(14, "Stoch Length", minval=1)
kSmooth = input.int(3, "K Smoothing", minval=1)
dSmooth = input.int(3, "D Smoothing", minval=1)
obLevel = input.int(80, "Overbought")
osLevel = input.int(20, "Oversold")
// === Calculations ===
rsiVal = ta.rsi(close, rsiLen)
stochK = ta.sma(ta.stoch(rsiVal, rsiVal, rsiVal, stochLen), kSmooth)
stochD = ta.sma(stochK, dSmooth)
// === Signals ===
longCond = ta.crossover(stochK, stochD) and stochK < osLevel
shortCond = ta.crossunder(stochK, stochD) and stochK > obLevel
// === Strategy ===
if longCond
strategy.entry("Long", strategy.long)
if shortCond
strategy.entry("Short", strategy.short)
// === Exit ===
if strategy.position_size > 0 and stochK > obLevel and ta.crossunder(stochK, stochD)
strategy.close("Long")
if strategy.position_size < 0 and stochK < osLevel and ta.crossover(stochK, stochD)
strategy.close("Short")