The specifications:
This EA uses the RSI exclusively for trade opens and closes. The RSI crosses 50 moving upward and alerts the EA to watch. When it reaches 53 it triggers a buy order. When the RSI reaches 70, it triggers a close order. Conversely, when the RSI crosses 50 moving downward, it alerts the EA. When it reaches 47 it triggers a sell order. This order is closed at RSI 30. There is also a contingency if the RSI crosses over the 50 moving the opposite direction that the trade would close.
As much is in the existing code.
Currently, the EA will only open and close one trade in the Strategy Tester. I would like you to modify the EA to operate according to these specifications.
I would also like you to add a trailing stop that can be adjusted.
Here is the existing code:
// Global Variables
enum StateType {WATCHING, LONG_ENTRY, SHORT_ENTRY, CLOSE_TRADE};
StateType state = WATCHING;
double LotSize = 0.1; // Lot size
double StopLoss = 20.0 * Point; // Stop loss in price difference
double TakeProfit = 100.0 * Point; // Take profit in price difference
int slippage = 3;
int RSI_Period = 14;
// OnTick function
void OnTick() {
double currentRSI = iRSI(Symbol(), 0, RSI_Period, PRICE_CLOSE, 0);
double previousRSI = iRSI(Symbol(), 0, RSI_Period, PRICE_CLOSE, 1);
if (state == WATCHING) {
if (currentRSI > 50 && previousRSI <= 50) {
state = LONG_ENTRY;
} else if (currentRSI < 50 && previousRSI >= 50) {
state = SHORT_ENTRY;
}
}
if (state == LONG_ENTRY && currentRSI >= 53) {
PlaceLongOrder();
} else if (state == SHORT_ENTRY && currentRSI <= 47) {
PlaceShortOrder();
}
if (state == CLOSE_TRADE) {
CloseTrade(currentRSI);
}
}
// Function to place a long order
void PlaceLongOrder() {
if (OrdersTotal() == 0) {
double price = Ask;
int ticket = OrderSend(Symbol(), OP_BUY, LotSize, price, slippage, price - StopLoss, price + TakeProfit, "Buy Order", 0, 0, clrGreen);
if (ticket > 0) state = CLOSE_TRADE;
}
}
// Function to place a short order
void PlaceShortOrder() {
if (OrdersTotal() == 0) {
double price = Bid;
int ticket = OrderSend(Symbol(), OP_SELL, LotSize, price, slippage, price + StopLoss, price - TakeProfit, "Sell Order", 0, 0, clrRed);
if (ticket > 0) state = CLOSE_TRADE;
}
}
// Function to close the trade based on RSI
void CloseTrade(double currentRSI) {
for (int i = 0; i < OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol()) {
if ((OrderType() == OP_BUY && currentRSI >= 70) || (OrderType() == OP_SELL && currentRSI <= 30)) {
bool closed = OrderClose(OrderTicket(), OrderLots(), (OrderType() == OP_BUY ? Bid : Ask), 3, clrRed);
if (closed) state = WATCHING;
} else if ((OrderType() == OP_BUY && currentRSI < 50) || (OrderType() == OP_SELL && currentRSI > 50)) {
closed = OrderClose(OrderTicket(), OrderLots(), (OrderType() == OP_BUY ? Bid : Ask), 3, clrRed);
if (closed) state = WATCHING;
}
}
}
}
Ähnliche Aufträge
I am an independent trader and entrepreneur based in Côte d’Ivoire. I work in financial markets, analyze trading opportunities, and provide digital financial services. I am also interested in international trade, online business, and developing long-term business activities
Hello, I am interested in developing a professional MT5 Expert Advisor similar in functionality and technical sophistication to your reference product, Institutional SMC Robot: https://www.mql5.com/en/market/product/187011 I want to develop my own independent EA based on advanced Smart Money Concepts (SMC), with a strong focus on institutional price action, liquidity and market structure. The key functionalities I
Specify your Requirements Specification here point by point. Try to describe your requirements briefly and clearly, so that your potential developer is able to correctly assess its complexity and cost, as well as the required execution time. A bad or too generic description will result in your order being ignored, or you will spend a lot of time negotiating the details with each applicant. Remember: It is better to
Project Brief: Multi-Asset EA/Indicator Optimization, Debugging, and Futures Strategy Refinement 1. Project Overview & Objective I am looking for an experienced algorithmic developer to inspect, debug, optimize, and enhance an existing automated trading system. The system combines custom indicators and execution logic across Forex and Futures markets. The primary goals of this project are: Debug existing logic
I am looking for an experienced MQL5 developer to build a fully automated MetaTrader 5 Expert Advisor (EA) optimized primarily for XAUUSD (Gold), featuring a clean Tkinter-style telemetry dashboard control concept or customizable input parameters. 1. Core Strategy Rules (Full-Body Engulfing) Signal Identification: The EA must scan completed candles across multiple selectable timeframes (e.g., 1M, 5M, 15M, 30M, 1H)
I want NinjaTrader to behave like Tradovate. When I hover over a candlestick, the cursor should automatically snap to the center of that candle across all open charts. For example, when I hover over a 30-minute candle, the cursor should align with the center of the corresponding candles on the 15-minute and other chart timeframes. I also want vertical lines drawn on one chart to automatically align with the center of
I need an experienced MQL5 developer to create a semi-automated trade execution assistant for MetaTrader 5. Please read before applying: I only want developers who have already built a similar project at least once (a trading panel with trade management). If you have done it before, attach screenshots or links of the MT5 panels or dashboards you made. If you have never built something like this, or you cannot show
I am commissioning the development and reverse-engineering of a commercial-grade, multi-strategy quantitative trading portfolio modeled on proven institutional frameworks (Reference methodology: https://whop.com/the-agent-algo/products/ ). The goal is to develop a standalone, fully owned commercial trading system covering Nasdaq (NQ) and Gold (XAUUSD) with an integrated licensing engine ready for commercial
USD54 Applications The bot should open trades when the price breaks out of the band by a specified percentage, for example, 0.10%. If the price breaks above the band, the bot should open a long position. If the price breaks below the band, it should open a short position. The bot should also open trades when the price touches a band: Bullish band cross: When a bullish cross occurs between the bands, the bot should
#property strict #property version "1.00" #property description "EMA Trend + Pullback + Engulfing EA" // Include the standard MT5 trade library. #include <Trade/Trade.mqh> CTrade trade; //============================================================== // INPUT SETTINGS //============================================================== // Trend indicators input int FastEMA = 20; input int SlowEMA = 50; // Pullback