HI
i want some one to make the following MQL5 code work for me. the code has errors.
#include <Trade\Trade.mqh> // Include the trade library
// Define input parameters
input double lotSize = 0.1; // Lot size for trading
input int stopLoss = 50; // Stop Loss in pips
input int takeProfit = 100; // Take Profit in pips
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Subscribe to OnTrade() event
EventSetMillisecondTimer(60); // Set a timer to check conditions every 60 milliseconds
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Deinitialization function (if needed)
EventKillTimer(); // Kill the timer when deinitializing
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// Nothing to do here for conditions check, as we use OnTrade()
}
//+------------------------------------------------------------------+
//| Expert trade event handler |
//+------------------------------------------------------------------+
void OnTrade()
{
// Calculate the open and close prices of the previous day
double prevDayOpen = iOpen(Symbol(), PERIOD_D1, 1);
double prevDayClose = iClose(Symbol(), PERIOD_D1, 1);
// Check for Rule 1: Previous day was an uptrend
if (prevDayClose > prevDayOpen)
{
// Check if the current open price is between the previous day's open and close prices
double currentOpen = iOpen(Symbol(), PERIOD_D1, 0);
if (currentOpen > prevDayOpen && currentOpen < prevDayClose)
{
// Buy if the price breaks above the previous day's close price
double currentHigh = iHigh(Symbol(), PERIOD_D1, 0);
if (currentHigh > prevDayClose)
{
// Place a Buy order
double openPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
double stopLossPrice = openPrice - stopLoss * _Point;
double takeProfitPrice = openPrice + takeProfit * _Point;
int ticket = OrderSend(_Symbol, OP_BUY, lotSize, openPrice, 3, 0, 0, "", 0, clrNONE, 0, clrNONE);
if (ticket > 0)
{
// Order placed successfully - set Stop Loss and Take Profit
OrderSend(_Symbol, OP_SELL, lotSize, openPrice, 0, stopLossPrice, takeProfitPrice, "", 0, clrNONE, 0, clrNONE);
}
}
}
}
// Check for Rule 2: Opposite of Rule 1
if (prevDayClose < prevDayOpen)
{
// Check if the current open price is between the previous day's open and close prices
double currentOpen = iOpen(Symbol(), PERIOD_D1, 0);
if (currentOpen > prevDayOpen && currentOpen < prevDayClose)
{
// Sell if the price breaks below the previous day's close price
double currentLow = iLow(Symbol(), PERIOD_D1, 0);
if (currentLow < prevDayClose)
{
// Place a Sell order
double openPrice = SymbolInfoDouble(_Symbol, SYMBOL_BID);
double stopLossPrice = openPrice + stopLoss * _Point;
double takeProfitPrice = openPrice - takeProfit * _Point;
int ticket = OrderSend(_Symbol, OP_SELL, lotSize, openPrice, 3, 0, 0, "", 0, clrNONE, 0, clrNONE);
if (ticket > 0)
{
// Order placed successfully - set Stop Loss and Take Profit
OrderSend(_Symbol, OP_BUY, lotSize, openPrice, 0, stopLossPrice, takeProfitPrice, "", 0, clrNONE, 0, clrNONE);
}
}
}
}
}
Solicitudes similares
Hi, I have an existing MQL5 EA of around 18,000 lines that I would like you to review. It has two entry systems (Main + Scalper), many filters/parameters, risk management, and prop-firm functionality. The EA is already working, but I am struggling with optimization and obtaining robust backtest statistics. I would like to send you the complete source code so you can first review the architecture, strategy logic
Senior MQL5 Developer Required — XAUUSD & BTCUSD Algorithmic EA I am looking for an experienced MQL5 developer to design and build a robust MT5 Expert Advisor for XAUUSD (Gold) and BTCUSD . This is not a request for a basic RSI/EMA EA, martingale, grid, or recovery system . I want a properly engineered algorithmic trading system with a demonstrable trading rationale, robust risk management, reliable execution and
Project: Forex EA — EURUSD, Automating My Own Strategy Summary I currently trade EURUSD manually using my own tested strategy and am looking for an experienced MQL5 developer to automate it as an Expert Advisor (EA) for MetaTrader 5. What the bot should do Instrument: EURUSD Determine entry signals using multiple timeframes (higher timeframe for direction/trend, lower timeframe for precise entry timing) Place orders
Fully automated entry and exit of trades. Identify market trends using price action and reliable technical indicators. Trade major Forex pairs and XAU/USD (Gold). Automatic Stop Loss and Take Profit on every trade. Adjustable risk management, with default risk of 1% per trade. Maximum daily loss protection to stop trading after a specified loss. Break-even and trailing-stop functions. Adjustable lot size, risk %
Hello there, I am looking for a automated strategy for ninjatrader 5 Looking for a proven profit factor of 1.5 ( minimum ) on 15 mins time frame . I do MNQ futures I do not have the logic, but I like mean reverssion variable , plus RSI etc . that could make the automated tool robust and long lasting. i need fast response if you have
profitable EAs wanted with at least 3 to 5 years backtest. you be submit your proofs such as graphic results, backtesting results, and your demo or weekly the eas has traded
Date:29.08.2026 **TECHNICAL SPECIFICATIONS** PDF Attached for reference rest all details given below. Required: Creation, Integration and successful execution of trading algo/robot in MT5 using MT5 VPS. Brokers: Trades to be executed in both brokers Swissquote and Pepperstone. Symbols: All available in MT5. ** Common parameters for all executions: · Manual Start/Stop. · Session time (defined / always
I need an Expert Advisor called ZONDII Scalpers for MT5 (MQL5). Timeframe: M5 Pairs: XAUUSD / EURUSD BUY when: Price > EMA200 and EMA50 crosses above EMA200 and RSI(14) > 50 SELL when: Price < EMA200 and EMA50 crosses below EMA200 and RSI(14) < 50 Risk: Fixed lot 0.01, SL 300 points, TP 600 points, Trailing start 200 points / step 100 points. Filter: Max spread 30 points. Only 1 trade at a time. Inputs must be
I am looking for a professional MT5 EA developer to build a high-performance trading bot specifically for XAUUSD (Gold). My target is approximately 200% return within 3 months, while keeping the drawdown and risk as controlled as reasonably possible. Requirements: MT5 Expert Advisor (EA) XAUUSD only Fully automated trading Clear risk management Stop Loss and Take Profit on trades No martingale or grid strategy unless
Hello, I’m looking for an experienced MT5 developer to build a professional Expert Advisor (EA) for trading Gold (XAUUSD). My requirements: Platform: MT5 Instrument: XAUUSD (Gold) Fully automatic trading Both BUY and SELL trades Adjustable lot size Stop Loss and Take Profit Trailing Stop / Break Even Daily maximum loss limit Maximum drawdown protection Maximum number of open trades Trading hours/session filter Spread