Golden Crossover Strategy by saketpansari

By saketpansari

Performance Metrics

Description

What this strategy does?This strategy trades EMA crossovers with an optional trend filter, and works on any timeframe you apply it to (daily, weekly, intraday, etc.). It is designed for swing-style long-only trading and backtesting.• It plots three EMAs:• Fast EMA – default 21 periods• Slow EMA – default 50 periods• Trend EMA – default 200 periods (used as a higher timeframe trend filter)• It enters long when the Fast EMA crosses above the Slow EMA, and• It exits when the Fast EMA crosses below the Slow EMA.• Entry and exit are executed on the next bar after the cross, using “on bar close” execution.Because it’s a strategy (not just an indicator), you can view full backtest stats in TradingView’s Strategy Tester.________________________________________How the entries and exits work1. The script calculates EMAs on the close of the current chart timeframe.2. When a bar closes and the Fast EMA has just moved from below the Slow EMA to above it, that bar is marked as a Bull Cross.3. The strategy then enters long on the next bar, using 100% of available equity by default.4. When the Fast EMA moves from above the Slow EMA to below it, that bar is marked as a Bear Cross, and the strategy exits the long position on the next bar.The labels “Bull Cross” and “Bear Cross” on the chart show you exactly where the EMAs crossed, which makes it easy to visually verify trades.________________________________________Trend EMA filter (optional)There is an optional Trend EMA filter:• If Use Trend EMA Filter is ON (default):• Long trades are taken only when the current close is above the Trend EMA.• This helps avoid going long in strong downtrends.• If it is OFF:• The strategy will take all Fast/Slow EMA crossovers, regardless of the Trend EMA.You can adjust the trend length (default 200) to experiment with different trend filters (for example 100, 150, etc.).________________________________________Inputs and how to use themIn the Inputs tab:• Fast EMA Length• Default 21.• Controls the faster moving average. Lower values = more sensitive, more trades.• Slow EMA Length• Default 50.• Controls the slower moving average. Higher values = smoother, fewer but larger trades.• Trend EMA Length (Filter EMA)• Default 200.• Used as the trend filter. Only relevant when the Trend EMA filter is enabled.• Use Trend EMA Filter (Only Longs Above Trend EMA)• If checked: only go long when price is above the Trend EMA.• If unchecked: ignore the Trend EMA and trade every EMA 21/50 cross.• Start Year / Month / Day• The first date from which the strategy is allowed to trade.• Bars before this date are ignored for entries/exits.• End Year / Month / Day• The last date up to which the strategy is allowed to trade.• Bars after this date will force-close any open position and no new trades are taken.This date filter lets you backtest specific time windows even if your TradingView plan does not allow changing the overall “Testing start date” in the Strategy Tester itself.________________________________________How to use on different timeframesThe strategy automatically adapts to whatever timeframe you choose:• If your chart is on Daily, EMAs are daily and “next bar” means next day.• If your chart is on Weekly, EMAs are weekly and “next bar” means next week.• If your chart is on intraday (e.g., 75 minutes), EMAs are on that intraday data and “next bar” is the next intraday candle.No code changes are needed; just change the chart timeframe and the strategy recalculates.________________________________________How to read and verify the signals• Visual crosses:• Green “Bull Cross” label below the bar = Fast EMA crossed above Slow EMA.• Red “Bear Cross” label above the bar = Fast EMA crossed below Slow EMA.• Trades:• Entry markers appear on the bar after a Bull Cross, if within date range and (optionally) above the Trend EMA.• Exit markers appear on the bar after a Bear Cross, if within date range.You can open Strategy Tester → List of Trades and click any trade; TradingView will highlight entry/exit on the chart, letting you cross-check with the EMA crosses.Please let me know if you find any bugs in this script so that I can try to rectify that. Please feel free to give suggestions to improve this strategy. You can email at spansari@gmail.com or Tweet me saketpansariDisclaimer: I have no experience in coding. All this is done with help of AI.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView