PROTECTED SOURCE SCRIPT

EMA Fractal and vwap - FIMIDO

61
It is a testing only strategy with alerts - FOR MNQ and MES Futures

This script implements a multi-indicator-based approach to generate long (buy) and short (sell) signals, incorporating elements like Exponential Moving Averages (EMAs), WaveTrend, volume filters, Cumulative Volume Delta (CVD) trends, fractal prime zones, and Volume Weighted Average Price (VWAP) with trend-based coloring. It includes risk management features such as stop-loss, take-profit, position sizing based on account risk, daily loss limits, and trade pauses after losses. The strategy is highly configurable through user inputs, allowing traders to enable/disable various filters and trade types.
Important Note: This script is still in the testing phase. It has not been fully optimized or backtested across various market conditions, instruments, or timeframes. Users should thoroughly test it in a simulated environment before applying it to live trading, as it may contain bugs, inefficiencies, or unintended behaviors. Past performance in backtests does not guarantee future results, and trading involves significant financial risk.

Key Features and Structure
The script is structured into sections: inputs, functions, calculations, trading filters, strategy logic, plots, alerts, and visual elements. It operates as a strategy overlay on price charts, meaning it plots indicators directly on the main chart and executes hypothetical trades based on defined rules.

Strategy Parameters:

Initial capital: Starts with $50,000 (configurable).
Margin: 1% for both long and short positions.
Overlay: True, so it displays on the price chart.

Inputs
The script provides extensive user-configurable inputs grouped by category for ease of use:

Risk Management:

Risk % of Account: Percentage of equity risked per trade (default: 2%).
Risk-Reward Ratio: Multiplier for take-profit relative to stop-loss (default: 1.7).
Max Daily Loss %: Stops trading if daily losses exceed this threshold (default: 0.4%).
Stop-Loss Points Buffer: Adjusts stop-loss placement (default: -8.1 points).
Max Trades per Day: Limits trades per session (default: 3).
Pause Candles After Loss: Halts trading for a set number of bars after a losing trade (default: 19).


Trading Hours:

Start/End Hour: Restricts trading to specific hours (default: 6 AM to 9 AM, in 24-hour format).


Trade Types:

Enable Long/Short Trades: Toggles long (buy) or short (sell) positions (both default: true).


VWAP Filter Settings:

Use VWAP Filter: Requires buys above VWAP and sells below (default: true).
VWAP Trend Length: Period for trend calculation (default: 5 bars).
VWAP Trend Threshold: Minimum change for considering a trend (default: 0.0 points).
Disable Trades on Flat VWAP: Prevents trades when VWAP is gray (flat trend) (default: true).


EMA Settings:

EMA Master Length: A base EMA for general filtering (default: 6).
Separate EMA configurations for long and short trades, including smoothing types (RMA, SMA, EMA, WMA) and fast/slow lengths.


WaveTrend Settings:

Use WaveTrend: Enables momentum-based signals (default: false).
Channel, Average, and MA lengths for customization.


Volume Filter Settings:

Separate filters for long/short with MA lengths and threshold multipliers to ensure high-volume conditions.


CVD Trend Settings:

Use CVD for long/short: Filters based on volume delta trends using ATR multipliers and lengths.


Fractal Prime Zones Settings:

Use Fractal: Enables support/resistance zones based on fractals (default: true).
Length, sensitivity, and options to include volume delta or show labels.



These inputs allow for fine-tuning the strategy to different assets or market conditions.
Functions
Two main helper functions are defined:

f_wavetrend: Calculates WaveTrend values using EMAs on a custom source, producing two lines (WT1 and WT2) for crossover detection.
f_ema: A simple EMA wrapper (though it uses built-in ta.ema).
ma_function: A versatile moving average calculator supporting RMA, SMA, EMA, or WMA based on user selection.

Calculations
The core of the script involves computing multiple indicators:

VWAP: Based on HLC3 (high-low-close average), anchored daily. It's plotted with dynamic coloring: green for upward trend, red for downward, and gray for flat (based on slope over the trend length and threshold).
Volume Filters: SMA-based checks to ensure volume exceeds a threshold multiple.
EMAs: Custom fast/slow EMAs for long/short, with crossovers/crossunders generating signals.
WaveTrend: Momentum oscillator with cross detection for up/down signals.
CVD Trends: Bollinger-like bands using SMA and ATR multiples to detect uptrends (close above upper band) or downtrends.
Fractal Prime Zones: Advanced zones using prime numbers, ATR, and optional CVD. Calculates density-based upper/lower zones, identifies support/resistance, and generates buy/sell signals on zone breaks.
Trading Window and Counters: Checks time of day, resets daily trade counts, and manages pause after losses.
Risk Calculations: Dynamically computes position size based on risk amount, stop-loss distance, and equity.

Entry signals (buyTriangle and sellTriangle) combine these: All enabled filters must pass (e.g., EMA crossover, high volume, CVD trend, fractal signal, VWAP position, and trending VWAP if filtered).
Strategy Logic

Entry Conditions: Triggers long/short entries only if signals align, within trading hours, under max trades/day, not paused, and daily loss not exceeded.

Stop-loss: Placed below low (long) or above high (short) with buffer.
Position Size: Floored to nearest integer based on risk amount divided by per-unit risk.
Take-Profit: Set at entry price plus/minus (risk distance * RR ratio).


Exits: Via strategy.exit with stop and limit orders.
Loss Handling: Updates daily loss on trade close; pauses if loss occurs.
No Trades on Flat VWAP: If enabled, skips entries when VWAP trend is neutral (gray).

Plots and Visuals

Shapes: Triangles for buy (blue, below bar) and sell (red, above bar) signals.
VWAP Line: Colored dynamically.
Fractal Zones: Plotted with fill and optional labels for support/resistance.
Debug Plots: Characters for trading window, pause, and max trades exceeded.
TP/SL Lines: Drawn as arrows on entries.
Daily Loss Table: Displays current loss and limit in a bottom-right table.

Alerts

Generates alerts on entries with details: entry price, SL, TP.

This strategy emphasizes trend-following with filters to reduce false signals, but its complexity may lead to over-optimization. Again, as it is still in the testing phase, users are advised to backtest extensively, forward-test on demo accounts, and monitor for issues like slippage, commissions, or market regime changes before real-world use. If you need modifications or further analysis, let me know!

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.