### Explanation for Developing the Multi-Timeframe EA
**Objective:**
Create an Expert Advisor (EA) for MetaTrader 5 (MT5) that replicates the functionality of the Ultimate RSI indicator from TradingView. The EA will open and manage trades based on the crossover signals of the RSI and EMA within the same window, incorporating multi-timeframe analysis.
**Specifications:**
1. **Indicators Used:**
- Relative Strength Index (RSI)
- Exponential Moving Average (EMA)
2. **Trading Logic:**
- Open a buy position when the RSI crosses the EMA from below.
- Open a sell position when the RSI crosses the EMA from above.
- Always have one trade open:
- Close the current trade when an opposite signal is generated and open a new trade in the opposite direction.
3. **Multi-Timeframe Analysis:**
- Use higher timeframe data for confirming signals.
- For example, check RSI and EMA crossovers on the H1 timeframe for signals, but execute trades on the M15 timeframe.
4. **No Take Profit (TP) or Stop Loss (SL):**
- The EA will not use traditional TP or SL levels. Instead, it will close and reverse positions based on the crossover signals.
### Step-by-Step Development Plan
1. **Initialization:**
- Initialize the RSI and EMA indicators with the desired periods and timeframes.
2. **Indicator Calculation:**
- In the `OnCalculate` function, calculate the RSI and EMA values for the current and higher timeframes.
3. **Crossover Detection:**
- Identify when RSI crosses above or below the EMA on the higher timeframe.
- Use these signals to make trading decisions on the current timeframe.
4. **Trade Execution:**
- Implement logic to open, close, and reverse trades based on the detected signals.
- Ensure only one trade is open at any time.
### Detailed Implementation Steps
1. **Indicator Initialization:**
- Define the periods for RSI and EMA.
- Define the timeframes for analysis (e.g., H1 for signals, M15 for execution).
- Initialize buffers to store RSI and EMA values for both timeframes.
2. **Calculate Indicators:**
- In the `OnCalculate` function, calculate the RSI and EMA for the higher timeframe.
- Store these values in the respective buffers.
3. **Check for Crossover:**
- Compare the RSI and EMA values for the current and previous bars on the higher timeframe to detect a crossover.
4. **Trade Logic:**
- On a bullish crossover (RSI crossing above EMA):
- Close any open sell position.
- Open a buy position.
- On a bearish crossover (RSI crossing below EMA):
- Close any open buy position.
- Open a sell position.
5. **Order Management:**
- Ensure that only one trade is open at any time.
- Handle errors and edge cases (e.g., if no trade is currently open).
### Pseudocode Outline
#include <Trade\Trade.mqh>
input double LotSize = 0.1;
input int RSIPeriod = 14;
input int EMAPeriod = 14;
input ENUM_TIMEFRAMES TimeFrame = PERIOD_M1;
CTrade trade;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
static double previous_rsi = 0;
static double previous_ema = 0;
// Create handles for RSI and EMA
int handle_rsi = iRSI(_Symbol, TimeFrame, RSIPeriod, PRICE_CLOSE);
int handle_ema = iMA(_Symbol, TimeFrame, EMAPeriod, 0, MODE_EMA, PRICE_CLOSE);
// Declare arrays to store indicator values
double rsi[2];
double ema[2];
// Check if handles are valid
if (handle_rsi < 0 || handle_ema < 0)
{
Print("Error creating indicator handles");
return;
}
// Copy indicator values into arrays
if (CopyBuffer(handle_rsi, 0, 0, 2, rsi) < 0 || CopyBuffer(handle_ema, 0, 0, 2, ema) < 0)
{
Print("Error copying indicator values");
return;
}
// Log current RSI and EMA values for debugging
double current_rsi = rsi[0];
double current_ema = ema[0];
Print("Current RSI: ", current_rsi);
Print("Current EMA: ", current_ema);
// Ensure previous values are set to current if they are not yet initialized
if (previous_rsi == 0 && previous_ema == 0)
{
previous_rsi = current_rsi;
previous_ema = current_ema;
return;
}
// Check if there's an open position
bool isPositionOpen = PositionSelect(_Symbol);
// Entry criteria
if (previous_rsi != 0 && previous_ema != 0)
{
// Close existing position and open the opposite trade
if (previous_rsi > previous_ema && current_rsi < current_ema)
{
// Sell signal
if (isPositionOpen && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
{
trade.PositionClose(_Symbol);
}
trade.Sell(LotSize, _Symbol, 0, 0, 0, "Sell on RSI cross below EMA");
Print("Sell on RSI cross below EMA");
}
else if (previous_rsi < previous_ema && current_rsi > current_ema)
{
// Buy signal
if (isPositionOpen && PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
{
trade.PositionClose(_Symbol);
}
trade.Buy(LotSize, _Symbol, 0, 0, 0, "Buy on RSI cross above EMA");
Print("Buy on RSI cross above EMA");
}
}
// Update previous RSI and EMA values
previous_rsi = current_rsi;
previous_ema = current_ema;
}
//+------------------------------------------------------------------+
Similar orders
PROJECT: Automatic Gold and Forex Trading Robot for MetaTrader 5 (MQL5) I want a fully automated Expert Advisor (EA) for MetaTrader 5 that can analyze the market and automatically open, manage and close trades on Gold and selected Forex currency pairs. TRADING INSTRUMENTS Gold: XAUUSD Forex: EURUSD, GBPUSD and USDJPY, subject to broker availability. Allow the user to enable or disable each trading symbol. Support
I need a robot that will grow small accounts to bigger amounts like this one in this link, https://youtu.be/d38pMbJihew?si=3NeIOVyrlwDr4X_o. Please click the link and watch how this EA grow small accounts. Then create a robot like that. I will test it on demo first then if it does what i want, i will take it. Please it must be simply to use. It must set targets, for example, once it reaches $500 profit, it must
Here is a professional, detailed requirements specification draft for your MQL5 freelance order based on your prompt: Strategy Objective: Develop an automated Expert Advisor (EA) featuring a 1:3 Risk-to-Reward ratio optimized for a small starting budget. Core Trading Logic: Execute automatic Buy and Sell trades using high-probability entry signals. Target a strict 90% theoretical win-rate structure through
i want to fix my gold martingale bot MT5. RSI 14 ENTRY 30 BUY 70 SELL Lot 0.02 0.04 0.07 TP 150 for all SL 90 30 30 once total daily profit is 200$ stop trading stop trading once 2 consecutives total losses stop trading if spread exceeded 30 and between hour 15 & 17 PM Move SL to breakeven point once the profit exceeded 50 from from breakeven thanks
MarketMind Breakout Pro XAUUSD H1 — Donchian Breakout EA Project type: Personal EA development and backtesting Platform: MetaTrader 5 Instrument: XAUUSD Timeframe: H1 Strategy: Donchian Channel breakout with EMA 200 Project overview This project evaluates a Donchian breakout trading strategy for XAUUSD on the H1 timeframe. The system uses channel-based breakout conditions and an EMA 200 trend filter. Historical
The purpose of this order is ONLY to test and implement my H1 POI (Point of Interest) identification logic correctly. I am not requesting the complete EA at this stage. I will provide the exact rules for identifying the H1 POI after selecting the developer. The developer must convert those rules into clear, deterministic MQL5 logic. Requirements: Analyze H1 candles according to the rules I provide. Identify and mark
Title: Fully Automatic MT5 Trading Bot (Expert Advisor) with Risk Management I want a fully automated trading robot (Expert Advisor) for MetaTrader 5, written in MQL5. The bot must automatically analyse market data, identify trading opportunities, execute BUY and SELL orders, manage open positions, and close trades according to predefined rules without requiring manual confirmation for each trade. Requirements
Hello, I’m looking for an experienced developer to research, build, test, and install a fully automated MetaTrader 5 trading bot for gold, XAUUSD. My total development and installation budget is $300, including all agreed work and fees. My goal is to pass a $100,000 FTMO US Two-Step Standard evaluation and sustainably maintain the funded account. I need a day-trading strategy that can buy in bullish markets and sell
I have three indicators that operate independently. I want to combine them into one indicator with custom expert programming that automatically enters trades when a signal is generated by one of the indicators. I will pay for this service Thanks you
Existing EA: NEW_CORE_ORB_M5_v021 | MT5 | XAUUSD M5 Early-stage research prototype, not a new EA from scratch. Need an experienced MQL5 developer to audit, complete, repair, improve and test BOTH independent strategies equally: Opening Range Breakout (ORB) and Scalp. Keep code lightweight and preserve an untouched baseline. No unnecessary rewrite or complex filters. 1. ORB Strategy Verify opening-range construction