0bps

Strategy vault / Trend following

Golden Cross Strategy

The golden cross strategy generates long signals when the fast EMA crosses above the slow SMA and exits longs when the fast EMA crosses below the slow SMA. It aims to capture long-term trend reversals using the…

Author
ChaoZhang
Complexity
Starter · 53 lines
Parameters
2
Backtest bar
2m · intraday
Tested on
BTC/USDT · futures

Strategy Overview

The golden cross strategy generates long signals when the fast EMA crosses above the slow SMA and exits longs when the fast EMA crosses below the slow SMA. It aims to capture long-term trend reversals using the golden crossovers between two moving averages.

Strategy Logic

  1. Calculate the 50-period fast EMA as the representative of short-term trend.

  2. Calculate the 200-period slow SMA as the representative of long-term trend.

  3. When the fast EMA crosses above the slow SMA, it signals the start of an upward long-term trend, go long.

  4. When the fast EMA crosses below the slow SMA, it signals the start of a downward long-term trend, close long positions.

Crossovers represent changes in market supply/demand dynamics and psychology, serving as signals for long-term trend shifts. The periods of the fast and slow lines can be adjusted based on different assets and timeframes.

Advantages of the Strategy

  • Uses dual moving averages to identify major trend reversal points

  • Golden crosses form clear long and exit signals

  • Flexible parameter adjustment, adaptable to various markets

  • Simple backtesting and live tuning

  • Combinable with other factors

Risk Warnings

  • Potential lagging of moving averages

  • Prevent false breakout occurrences

  • Hard to determine precise entry and exit timing

  • Internal swings may cause losses in trends

Conclusion

The golden cross strategy judges long-term trend shifts by comparing fast and slow moving average golden crosses, forming a widely used long-term strategy concept. Parameters can be adjusted and combined with other factors to improve strategy performance for different markets.

Parameters

NameDefaultWhat it controls
v_input_150Fast EMA Buy
v_input_2200Slow SMA Buy

Source Pine Script

/*backtest
start: 2023-09-07 00:00:00
end: 2023-09-14 00:00:00
period: 2m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3


strategy("GoldenCross Strategy by Clefsphere",overlay=true, initial_capital=10000,default_qty_type=strategy.percent_of_equity,default_qty_value=100)

// testStartYear = input(2013, "Start Year")
// testStartMonth = input(3, "Start Month")
// testStartDay = input(1, "Start Day")
// testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)

// testStopYear = input(2018, "Stop Year")
// testStopMonth = input(8, "Stop Month")
// testStopDay = input(5, "Stop Day")
// testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)

// testPeriodBackground = input(title="Background", type=bool, defval=true)
// testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na


sma1Period = input(50, "Fast EMA Buy")
sma2Period = input(200, "Slow SMA Buy")

// testPeriod() =>
//     time >= testPeriodStart and time <= testPeriodStop ? true : false

sma1val=sma(close,sma1Period)
sma2val=sma(close,sma2Period)


plot(sma1val,color=blue,linewidth=1)
plot(sma2val,color=orange,linewidth=1)

long=crossover(sma1val,sma2val)
short=crossunder(sma1val,sma2val)


// if testPeriod()
if long
    strategy.entry("buy",strategy.long)
    
if short
    strategy.close("buy")
        
plot(low,color= sma1val > sma2val ? green:  red,style=columns,transp=90,linewidth=1)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-15. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Golden-Cross-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open