Creating a TradingView Pine Script version 5 strategy for NQ futures with high probability requires a blend of:
- Volatility-based entry filtering.
- Volume spike identification to capture potential market turning points.
- Strict risk and position sizing management to keep the max drawdown within 0.05%.
The following script focuses on:
- High probability trades by entering on volume spikes during volatile periods.
- Setting stop loss and take profit based on volatility.
- Position size adjusted based on the defined risk per trade.
Strategy Design:
- Entry Criteria: Use a combination of ATR-based volatility filtering, trend-following, and volume spikes.
- Risk Management: A strict 0.05% risk per trade with position sizing based on volatility.
- Exit Management: Targeting a 2:1 risk-reward ratio to improve win rates.
Pine Script Strategy (Version 5):
pinescriptCopy code//@version=5
strategy("NQ Futures Strategy with Volume Spike and Risk Management", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=1)
// Parameters
risk_per_trade = 0.0005 // Max 0.05% risk per trade
atr_period = 14 // Period for ATR-based volatility estimation
take_profit_factor = 2 // Take profit as multiple of ATR
stop_loss_factor = 1 // Stop loss as multiple of ATR
volume_spike_factor = 2 // Minimum spike above average volume
// Volatility and Volume Estimation
atr = ta.atr(atr_period)
volatility_threshold = atr / close * 100 // ATR as a percentage of the price
avg_volume = ta.sma(volume, 20)
volume_spike = volume > (avg_volume * volume_spike_factor) // Volume spike criteria
// Entry Signals
ma_fast = ta.sma(close, 10)
ma_slow = ta.sma(close, 50)
longCondition = ta.crossover(ma_fast, ma_slow) and volatility_threshold > 0.5 and volume_spike
shortCondition = ta.crossunder(ma_fast, ma_slow) and volatility_threshold > 0.5 and volume_spike
// Risk and Position Sizing
account_balance = strategy.equity
max_risk = account_balance * risk_per_trade
position_size = max_risk / (atr * stop_loss_factor) // Position size based on ATR and risk
// Stop Loss and Take Profit Calculation
long_stop = close - (atr * stop_loss_factor)
long_target = close + (atr * take_profit_factor)
short_stop = close + (atr * stop_loss_factor)
short_target = close - (atr * take_profit_factor)
// Long Trade with Position Sizing, Stop Loss, and Take Profit
if (longCondition)
strategy.entry("Long", strategy.long, qty=position_size)
strategy.exit("Take Profit/Stop Loss", "Long", stop=long_stop, limit=long_target)
// Short Trade with Position Sizing, Stop Loss, and Take Profit
if (shortCondition)
strategy.entry("Short", strategy.short, qty=position_size)
strategy.exit("Take Profit/Stop Loss", "Short", stop=short_stop, limit=short_target)
// Visualization: Stop Loss and Take Profit
plot(longCondition ? long_stop : na, title="Long Stop Loss", color=color.red, linewidth=1, style=plot.style_dotted)
plot(longCondition ? long_target : na, title="Long Take Profit", color=color.green, linewidth=1, style=plot.style_dotted)
plot(shortCondition ? short_stop : na, title="Short Stop Loss", color=color.red, linewidth=1, style=plot.style_dotted)
plot(shortCondition ? short_target : na, title="Short Take Profit", color=color.green, linewidth=1, style=plot.style_dotted)
// Plot ATR and Volume Spike for Reference
plot(volatility_threshold, title="Volatility (ATR %)", color=color.blue, linewidth=1)
hline(0.5, "Volatility Threshold", color=color.purple)
plot(volume, title="Volume", color=color.gray, style=plot.style_columns)
plot(avg_volume * volume_spike_factor, title="Volume Spike Threshold", color=color.orange, linewidth=1)
Strategy Breakdown:
- Volatility Estimation:
- ATR is used as the volatility measure.
- We only enter trades when the volatility threshold (ATR as a percentage of close price) is above 0.5%.
- Volume Spike Detection:
- We calculate the average volume over 20 periods.
- A volume spike is defined as current volume exceeding twice the average volume over the past 20 periods.
- Entry Conditions:
- Long Entry: Occurs when a fast SMA (10-period) crosses above a slow SMA (50-period) with sufficient volatility and a volume spike.
- Short Entry: Occurs when a fast SMA crosses below a slow SMA with sufficient volatility and a volume spike.
- Risk Management and Position Sizing:
- Max Risk per Trade: Set to 0.05% of account balance.
- Position Size: Calculated based on the account’s ATR-adjusted max risk. This keeps the drawdown within safe limits.
- Stop Loss and Take Profit:
- Stop Loss: Set at one times ATR (adjustable with
stop_loss_factor
). - Take Profit: Set at two times ATR, aiming for a 2:1 risk-reward ratio.
- Stop Loss: Set at one times ATR (adjustable with
- Visualization:
- Stop Loss and Take Profit levels are drawn as dotted lines for each trade.
- The script also plots ATR-based volatility and volume threshold for clarity.
Notes:
- This script uses core risk management principles to control drawdowns while targeting high probability trades.
- The strategy seeks high-probability entries by filtering for trend-following signals in volatile markets and confirmation via volume spikes.
- Adjust
take_profit_factor
,stop_loss_factor
, and volume spike sensitivity to suit different market conditions and backtest for optimization.
This strategy needs thorough backtesting on historical NQ data to verify its probability of success and risk management efficacy. Adjustments to settings like ATR periods, SMA crossovers, and volume thresholds may improve its performance based on specific market conditions.