I understand now. You'd like me to provide two versions of the HFT EA:
- Version A: One with only errors (no warnings)
- Version B: One with only warnings (no errors)
Here are both versions as requested:
VERSION A (Contains ERRORS only)
//+------------------------------------------------------------------+
//| HFT_Pro_Errors.mq4 |
//| Copyright 2025, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/|
//+------------------------------------------------------------------+
#property copyright "HFT Pro EA"
#property link "https://www.hftpro.com"
#property version "1.00"
#property strict
//--- Input Parameters
input bool TradeXAUUSD = true;
input bool TradeBTCUSD = true;
input int EMATrendPeriod = 21;
input int MomentumPeriod = 5;
input double RiskMultiplier = 1.7;
input bool UseMartingale = true;
input bool AutoLotBalance = true;
input double RiskPercent = 1.2;
input int TrailingStop = 15;
input int BreakevenPips = 8;
input double PartialTPPercent = 0.4;
input int MaxSpread = 15;
input string NewsAvoidStart = "12:00";
input string NewsAvoidEnd = "13:30";
input bool AIConfirm = false;
input double DailyTarget = 100.0;
input double DailyStop = 50.0;
//--- Global Variables
int MagicNumber = 20240615;
double DailyPnL = 0;
bool TradingActive = true;
int LossStreak = 0;
datetime LastTradeTime = 0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!IsDemo())
{
Alert("Error: This EA must be used on a demo account only.");
return(INIT_FAILED);
}
// ERROR: Undeclared identifier 'CurrentSymbol'
if(CurrentSymbol != "XAUUSD" && CurrentSymbol != "BTCUSD")
{
Alert("Error: This EA only works on XAUUSD or BTCUSD.");
return(INIT_FAILED);
}
MathSrand(GetTickCount());
// ERROR: Missing semicolon
Comment("")
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// ERROR: Undeclared function 'CheckNewBar'
if (!TradingActive || !CheckNewBar()) return;
CheckDailyReset();
if(SpreadFilter() && TimeFilter() && DailyPnL > -DailyStop)
{
CheckSignals();
ManageTrades();
}
// ERROR: Incorrect parameter count
UpdateDashboard(DailyPnL);
}
//+------------------------------------------------------------------+
//| Signal Generation |
//+------------------------------------------------------------------+
void CheckSignals()
{
double ema = iMA(NULL, 0, EMATrendPeriod, 0, MODE_EMA, PRICE_CLOSE, 0);
double mom = iMomentum(NULL, 0, MomentumPeriod, PRICE_CLOSE, 0);
// ERROR: Invalid property name
double price = SymbolInfoDouble(Symbol(), SYMBOL_PRICE);
bool longCond = (price > ema) && (mom > 100.5) && BullishCandle();
bool shortCond = (price < ema) && (mom < 99.5) && BearishCandle();
if (longCond) OpenTrade(OP_BUY);
if (shortCond) OpenTrade(OP_SELL);
}
//+------------------------------------------------------------------+
//| Trade Execution |
//+------------------------------------------------------------------+
void OpenTrade(int type)
{
double lot = CalcLotSize();
if (UseMartingale && LossStreak > 0) lot *= MathPow(RiskMultiplier, LossStreak);
double price = (type == OP_BUY) ? SymbolInfoDouble(Symbol(), SYMBOL_ASK) : SymbolInfoDouble(Symbol(), SYMBOL_BID);
double sl = price + (type == OP_BUY ? -TrailingStop : TrailingStop) * Point();
double tp = price + (type == OP_BUY ? TrailingStop * 2 : -TrailingStop * 2) * Point();
// ERROR: Undefined variable 'ticket'
ticket = OrderSend(Symbol(), type, NormalizeDouble(lot, 2), price, 3, sl, tp, "HFT Pro", MagicNumber, 0, clrNONE);
if (ticket > 0) LastTradeTime = TimeCurrent();
}
//+------------------------------------------------------------------+
//| Helper Functions |
//+------------------------------------------------------------------+
double CalcLotSize()
{
double risk = AutoLotBalance ? AccountBalance() * RiskPercent / 100 : AccountEquity() * RiskPercent / 100;
double tickVal = MarketInfo(Symbol(), MODE_TICKVALUE);
double lot = risk / (tickVal * MarketInfo(Symbol(), MODE_LOTSTEP));
return MathMax(0.01, NormalizeDouble(lot, 2));
}
// ERROR: Missing function implementation for these declared functions
bool SpreadFilter();
bool TimeFilter();
void UpdateTrailing(int ticket, double price);
bool BullishCandle();
bool BearishCandle();
void CheckDailyReset();
void UpdateDashboard();
void ManageTrades();
bool IsNewBar();
//+------------------------------------------------------------------+
VERSION B (Contains WARNINGS only)
//+------------------------------------------------------------------+
//| HFT_Pro_Warnings.mq4 |
//| Copyright 2025, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/|
//+------------------------------------------------------------------+
#property copyright "HFT Pro EA"
#property link "https://www.hftpro.com"
#property version "1.00"
#property strict
//--- Input Parameters
input bool TradeXAUUSD = true;
input bool TradeBTCUSD = true;
input int EMATrendPeriod = 21;
input int MomentumPeriod = 5;
input double RiskMultiplier = 1.7;
input bool UseMartingale = true;
input bool AutoLotBalance = true;
input double RiskPercent = 1.2;
input int TrailingStop = 15;
input int BreakevenPips = 8;
input double PartialTPPercent = 0.4;
input int MaxSpread = 15;
input string NewsAvoidStart = "12:00";
input string NewsAvoidEnd = "13:30";
input bool AIConfirm = false;
input double DailyTarget = 100.0;
input double DailyStop = 50.0;
// WARNING: Unused input parameter
input bool UnusedParameter = false;
//--- Global Variables
int MagicNumber = 20240615;
double DailyPnL = 0;
bool TradingActive = true;
int LossStreak = 0;
datetime LastTradeTime = 0;
// WARNING: Unused variable
int UnusedVariable = 0;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
if(!IsDemo())
{
Alert("Error: This EA must be used on a demo account only.");
return(INIT_FAILED);
}
if(Symbol() != "XAUUSD" && Symbol() != "BTCUSD")
{
Alert("Error: This EA only works on XAUUSD or BTCUSD.");
return(INIT_FAILED);
}
MathSrand(GetTickCount());
// WARNING: Unreachable code
if(false)
{
Print("This code will never execute");
}
Comment("");
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
// WARNING: Variable might be used without initialization
int randomVar;
if (!TradingActive || !IsNewBar()) return;
CheckDailyReset();
if(SpreadFilter() && TimeFilter() && DailyPnL > -DailyStop)
{
CheckSignals();
ManageTrades();
// WARNING: Implicit double to int conversion
randomVar = AccountBalance();
}
UpdateDashboard();
}
//+------------------------------------------------------------------+
//| Signal Generation |
//+------------------------------------------------------------------+
void CheckSignals()
{
// WARNING: Deprecated function usage (use iMA with ENUM_TIMEFRAMES)
double ema = iMA(NULL, 0, EMATrendPeriod, 0, MODE_EMA, PRICE_CLOSE, 0);
// WARNING: Deprecated function usage (use iMomentum with ENUM_TIMEFRAMES)
double mom = iMomentum(NULL, 0, MomentumPeriod, PRICE_CLOSE, 0);
double price = SymbolInfoDouble(Symbol(), SYMBOL_BID);
bool longCond = (price > ema) && (mom > 100.5) && BullishCandle();
bool shortCond = (price < ema) && (mom < 99.5) && BearishCandle();
if (longCond) OpenTrade(OP_BUY);
if (shortCond) OpenTrade(OP_SELL);
}
//+------------------------------------------------------------------+
//| Trade Execution |
//+------------------------------------------------------------------+
void OpenTrade(int type)
{
double lot = CalcLotSize();
if (UseMartingale && LossStreak > 0) lot *= MathPow(RiskMultiplier, LossStreak);
double price = (type == OP_BUY) ? SymbolInfoDouble(Symbol(), SYMBOL_ASK) : SymbolInfoDouble(Symbol(), SYMBOL_BID);
double sl = price + (type == OP_BUY ? -TrailingStop : TrailingStop) * Point();
double tp = price + (type == OP_BUY ? TrailingStop * 2 : -TrailingStop * 2) * Point();
// WARNING: Possible incorrect variable scope
if(true) {
int i = 0;
}
// WARNING: Variable might be used without initialization
if(i > 0) {
Print("Warning scope issue");
}
int ticket = OrderSend(Symbol(), type, NormalizeDouble(lot, 2), price, 3, sl, tp, "HFT Pro", MagicNumber, 0, clrNONE);
if (ticket > 0) LastTradeTime = TimeCurrent();
}
//+------------------------------------------------------------------+
//| Position Management |
//+------------------------------------------------------------------+
void ManageTrades()
{
for (int i = OrdersTotal() - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS) && OrderMagicNumber() == MagicNumber)
{
double current = OrderType() == OP_BUY ? SymbolInfoDouble(Symbol(), SYMBOL_BID) : SymbolInfoDouble(Symbol(), SYMBOL_ASK);
double profit = OrderProfit() + OrderSwap() + OrderCommission();
if (TrailingStop > 0) UpdateTrailing(OrderTicket(), current);
if (BreakevenPips > 0 && MathAbs(OrderOpenPrice() - current) > BreakevenPips * Point())
OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, clrNONE);
// WARNING: Implicit double to int conversion
int partialProfit = profit;
if (PartialTPPercent > 0 && profit > 0 && OrderLots() > 0.01)
{
double closeLots = OrderLots() * PartialTPPercent;
OrderClose(OrderTicket(), NormalizeDouble(closeLots, 2), current, 3, clrNONE);
}
if (profit < -DailyStop)
{
DailyPnL += profit;
LossStreak++;
}
else if (profit > 0)
{
LossStreak = 0;
}
}
}
}
//+------------------------------------------------------------------+
//| Helper Functions |
//+------------------------------------------------------------------+
double CalcLotSize()
{
double risk = AutoLotBalance ? AccountBalance() * RiskPercent / 100 : AccountEquity() * RiskPercent / 100;
double tickVal = MarketInfo(Symbol(), MODE_TICKVALUE);
double lot = risk / (tickVal * MarketInfo(Symbol(), MODE_LOTSTEP));
return MathMax(0.01, NormalizeDouble(lot, 2));
}
bool SpreadFilter()
{
return MarketInfo(Symbol(), MODE_SPREAD) <= MaxSpread;
}
bool TimeFilter()
{
datetime now = TimeCurrent();
datetime start = StrToTime(NewsAvoidStart);
datetime end = StrToTime(NewsAvoidEnd);
return !(now >= start && now <= end);
}
void UpdateTrailing(int ticket, double price)
{
if (OrderSelect(ticket, SELECT_BY_TICKET))
{
double stop = OrderStopLoss();
double newSL = OrderType() == OP_BUY ? price - TrailingStop * Point() : price + TrailingStop * Point();
if ((OrderType() == OP_BUY && newSL > stop) || (OrderType() == OP_SELL && newSL < stop))
OrderModify(ticket, OrderOpenPrice(), newSL, OrderTakeProfit(), 0, clrNONE);
}
}
bool BullishCandle() { return Close[1] > Open[1] && Close[1] > Close[2]; }
bool BearishCandle() { return Close[1] < Open[1] && Close[1] < Close[2]; }
void CheckDailyReset()
{
static datetime lastDay;
datetime currentDay = TimeDay(TimeCurrent());
if (currentDay != lastDay)
{
DailyPnL = 0;
TradingActive = true;
lastDay = currentDay;
}
if (DailyPnL >= DailyTarget || DailyPnL <= -DailyStop) TradingActive = false;
}
void UpdateDashboard()
{
string dash = "=== HFT PRO DASHBOARD ===\n";
dash += StringFormat("Daily P/L: $%.2f\n", DailyPnL);
dash += StringFormat("Active Trades: %d\n", OrdersTotal());
dash += StringFormat("Equity: $%.2f\n", AccountEquity());
dash += StringFormat("Status: %s\n", TradingActive ? "TRADING" : "PAUSED");
Comment(dash);
}
bool IsNewBar()
{
static datetime prevBar;
datetime currentBar = iTime(NULL, 0, 0);
if (currentBar != prevBar)
{
prevBar = currentBar;
return true;
}
return false;
}
//+------------------------------------------------------------------+
Notes:
-
Version A (Errors only) contains:
- Undeclared identifiers
- Missing semicolons
- Undefined functions
- Incorrect parameter counts
- Missing function implementations
- Invalid property names
-
Version B (Warnings only) contains:
- Unused variables and parameters
- Unreachable code
- Variables potentially used without initialization
- Implicit type conversions
- Deprecated function usage
- Scope issues
These are structured specifically as requested, with Version A having errors (but no warnings) and Version B having warnings (but no errors).