Strategies KB.ZH
Strategies

均线交叉空头反转量化策略SMA20-50-智能空单交易系统-SMA20-50-Bearish-Trend-Reversal-Quantitative-Trading-System

ianzeng123 · PineScript · Trend Following · 2025-04-01 13:45:34

All strategies →

No English write-up in the source (no author description).

Read the Chinese version →

Source code (51 lines)
/*backtest
start: 2025-01-01 00:00:00
end: 2025-03-31 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=6
strategy("SMA20/50 Short-Only Strategy", overlay=true, initial_capital=5000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)

// Input sources and calculations
src = close
sma20 = ta.sma(src, 20)
sma50 = ta.sma(src, 50)

// Generate sell signal when sma20 crosses below sma50
sellSignal = ta.crossunder(sma20, sma50)

// Generate exit signal when sma20 crosses above sma50
exitSignal = ta.crossover(sma20, sma50)

// Plot SMAs
plot(sma20, color = color.blue, title = "SMA 20")
plot(sma50, color = color.black, title = "SMA 50")

// Plot sell signal
plotshape(sellSignal, style = shape.triangledown, location = location.abovebar, color = color.red, size = size.tiny, title = "Sell Signal")

// Plot exit signal
plotshape(exitSignal, style = shape.xcross, location = location.belowbar, color = color.green, size = size.tiny, title = "Exit Signal")

// Add label for sell signals
if sellSignal
    label.new(bar_index, high, text="SELL", color = color.red, style = label.style_label_down, textcolor = color.white, size = size.small)

// Add label for exit signals
if exitSignal
    label.new(bar_index, low, text="EXIT", color = color.green, style = label.style_label_up, textcolor = color.white, size = size.small)

// Strategy entry and exit - SHORT ONLY
if sellSignal
    strategy.entry("Short", strategy.short)

if exitSignal
    strategy.close("Short")

// Strategy performance stats
var cumPnL = 0.0
if strategy.closedtrades > 0
    cumPnL := strategy.netprofit