OPEN-SOURCE SCRIPT

Simplified MA Crossover Strategy with toggle RSI/ATR options

1. Strategy Overview
MA Crossover Logic: The strategy uses two simple moving averages (short and long) to generate buy/sell signals.

Buy Signal: When the short MA crosses above the long MA.

Sell Signal: When the short MA crosses below the long MA.

Filters: The strategy includes optional RSI and ATR filters to refine entry conditions.

Risk Management: Includes stop-loss, take-profit, and position sizing based on a percentage of equity.

2. Inputs
MA Lengths:

shortLength: Length of the short MA (default: 9).

longLength: Length of the long MA (default: 21).

RSI Filter:

enableRSI: Toggle to enable/disable the RSI filter.

rsiLength: RSI calculation period (default: 14).

rsiOverbought: Overbought threshold (default: 70).

rsiOversold: Oversold threshold (default: 30).

ATR Filter:

enableATR: Toggle to enable/disable the ATR filter.

atrLength: ATR calculation period (default: 14).

minATR: Minimum ATR threshold for trade entry (default: 0.005).

Risk Management:

stopLossPerc: Stop-loss percentage (default: 0.5%).

riskRewardRatio: Risk-reward ratio for take-profit calculation (default: 2).

riskPercentage: Percentage of equity to risk per trade (default: 2%).

3. Indicators
Moving Averages:

shortMA: Short-term simple moving average.

longMA: Long-term simple moving average.

RSI: Relative Strength Index for filtering overbought/oversold conditions.

ATR: Average True Range for volatility filtering.

4. Trade Conditions
Long Condition:

Short MA crosses above the long MA.

RSI is below the overbought level (if RSI filter is enabled).

ATR is above the minimum threshold (if ATR filter is enabled).

Short Condition:

Short MA crosses below the long MA.

RSI is above the oversold level (if RSI filter is enabled).

ATR is above the minimum threshold (if ATR filter is enabled).

5. Risk Management
Position Sizing:

positionSize: Calculated based on the percentage of equity to risk and the stop-loss level.

Take-Profit and Stop-Loss:

takeProfitLevel: Calculated using the risk-reward ratio.

stopLossLevel: Calculated using the stop-loss percentage.

6. Trade Execution
Long Entry:

Triggers when the long condition is met.

Sets a take-profit and stop-loss level.

Short Entry:

Triggers when the short condition is met.

Sets a take-profit and stop-loss level.

7. Plotting
Moving Averages:

Short MA (blue) and Long MA (red) are plotted on the chart.

RSI Levels:

Overbought (red) and oversold (green) levels are plotted as horizontal lines.

ATR:

ATR is plotted in orange.

Trade Signals:

Buy signals are marked with a green "BUY" label below the bar.

Sell signals are marked with a red "SELL" label above the bar.

8. Customization
You can adjust the input parameters (e.g., MA lengths, RSI/ATR settings, risk management values) to suit your trading preferences.

Disable/enable filters (RSI and ATR) using the enableRSI and enableATR inputs.

9. Notes
This strategy is designed for educational purposes and should be thoroughly tested before use in live trading.

Consider optimizing the parameters (e.g., MA lengths, RSI/ATR thresholds) for specific markets or timeframes.

Ensure proper backtesting and forward testing to evaluate performance under different market conditions.

Declinazione di responsabilità