Strategies KB.ZH
Strategies

动态枢轴点结合黄金交叉策略优化系统-Dynamic-Pivot-Points-with-Golden-Cross-Optimization-System

ChaoZhang · PineScript · Trend Following · 2024-12-12 16:12:42

All strategies →

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

Read the Chinese version →

Source code (55 lines)
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-10 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Pivot Points & Golden Crossover Strategy", overlay=true)

// Inputs
length_short = input.int(50, title="Short Moving Average (Golden Cross)")
length_long = input.int(200, title="Long Moving Average (Golden Cross)")
pivot_length = input.int(5, title="Pivot Point Length")
lookback_pivots = input.int(20, title="Lookback Period for Pivots")

// Moving Averages
short_ma = ta.sma(close, length_short)
long_ma = ta.sma(close, length_long)

// Pivot Points
pivot_high = ta.valuewhen(ta.pivothigh(high, pivot_length, pivot_length), high, 0)
pivot_low = ta.valuewhen(ta.pivotlow(low, pivot_length, pivot_length), low, 0)

// Calculate golden crossover
golden_crossover = ta.crossover(short_ma, long_ma)
death_cross = ta.crossunder(short_ma, long_ma)

// Entry and Exit Conditions
long_entry = golden_crossover and close > pivot_high
short_entry = death_cross and close < pivot_low

// Exit conditions
long_exit = ta.crossunder(short_ma, long_ma)
short_exit = ta.crossover(short_ma, long_ma)

// Plot Moving Averages
plot(short_ma, color=color.blue, title="Short Moving Average")
plot(long_ma, color=color.orange, title="Long Moving Average")

// Plot Pivot Levels
plot(pivot_high, color=color.red, linewidth=1, style=plot.style_circles, title="Pivot High")
plot(pivot_low, color=color.green, linewidth=1, style=plot.style_circles, title="Pivot Low")

// Strategy Execution
if (long_entry)
    strategy.entry("Long", strategy.long)
if (long_exit)
    strategy.close("Long")

if (short_entry)
    strategy.entry("Short", strategy.short)
if (short_exit)
    strategy.close("Short")