OPEN-SOURCE SCRIPT

EMA + VWAP Strategy

86
# EMA + VWAP Crossover Strategy

## Overview
This is a trend-following intraday strategy that combines fast and slow EMAs with VWAP to identify high-probability entries. It's designed primarily for 5-15 minute charts and includes a smart filter to avoid trading when VWAP is ranging flat.

## How It Works

### Core Concept
The strategy uses three main components working together:
- **Fast EMA (9)** - Responds quickly to price changes and generates entry signals
- **Slow EMA (21)** - Acts as a trend filter to keep you on the right side of the market
- **VWAP** - Serves as a dynamic support/resistance level and the primary trigger for entries

### Entry Rules

**Long Entry:**
- EMA 9 crosses above VWAP (bullish momentum)
- EMA 9 is above EMA 21 (confirming uptrend)
- VWAP has a clear directional slope (not flat/ranging)
- Only during weekdays (Monday-Friday)

**Short Entry:**
- EMA 9 crosses below VWAP (bearish momentum)
- EMA 9 is below EMA 21 (confirming downtrend)
- VWAP has a clear directional slope (not flat/ranging)
- Only during weekdays (Monday-Friday)

### The VWAP Flat Filter
One of the key features is the VWAP slope filter. When VWAP is moving sideways (flat), it indicates the market is likely consolidating or ranging. The strategy skips these periods because crossover signals tend to be less reliable in choppy conditions. You'll see small gray diamonds at the top of the chart when VWAP is considered flat.

### Risk Management
The strategy uses a proper risk-reward approach with multiple stop loss options:

1. **ATR-Based (Recommended)** - Adapts to market volatility automatically. Default is 1.5x ATR(14), which gives your trades room to breathe while protecting capital.

2. **Swing Low/High** - Places stops at recent price structure points for a more technical approach.

3. **Slow EMA** - Uses the trend-defining EMA as your stop level, good for trend-following with wider stops.

4. **Fixed Percentage** - Simple percentage-based stops if you prefer consistency.

Take profits are automatically calculated based on your risk-reward ratio (default 2:1), meaning if you risk $100, you're aiming to make $200.

### Weekday Trading Filter
The strategy includes an option to trade only Monday through Friday. This is particularly useful for crypto markets where weekend liquidity can be thin and price action more erratic. You can toggle this on/off to test whether avoiding weekends improves your results.

### Visual Features
- **Color-coded background** - Green tint when EMA 9 is above EMA 21 (bullish bias), red tint when below (bearish bias)
- **ATR bands** - Dotted lines showing where stops would be placed (when using ATR stops)
- **Active trade levels** - Solid red line for your stop loss, green line for your take profit when you're in a position
- **Weekend highlighting** - Gray background on Saturdays and Sundays when weekday filter is active

## Best Practices

**Timeframe:** Designed for 5-minute charts but can be adapted to other intraday timeframes.

**Markets:** Works on any liquid market - stocks, forex, crypto, futures. Just make sure there's enough volume.

**Position Sizing:** The strategy uses percentage of equity by default. Adjust based on your risk tolerance.

**Backtesting Tips:**
- Test with and without the weekday filter to see which performs better on your instrument
- Try different ATR multipliers (1.0-2.5) to find the sweet spot between stop-outs and letting profits run
- Experiment with risk-reward ratios (1.5R, 2R, 3R) to optimize for your win rate

**What to Watch:**
- Win rate vs. profit factor balance
- How many trades are filtered out by the VWAP flat condition
- Performance difference between weekdays and weekends
- Whether the trend filter (EMA 21) is keeping you out of bad trades

## Parameters You Can Adjust
- Fast EMA length (default 9)
- Slow EMA length (default 21)
- VWAP flat threshold (default 0.01%)
- Stop loss type and parameters
- Risk-reward ratio
- Weekday trading on/off
- ATR length and multiplier

## Disclaimer
This strategy is for educational purposes. Past performance doesn't guarantee future results. Always test thoroughly on historical data and paper trade before risking real money. Use proper position sizing and never risk more than you can afford to lose.

---

*Built with Pine Script v5 for TradingView*

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.