MQL5 Ea code, no errors, but not compiling

 

This code doesn't compile any EA, can somebody help me?

//+------------------------------------------------------------------+
//| Expert settings                                                  |
//+------------------------------------------------------------------+
input string  EAName                 = "SMC-EURUSD-hft-5min"; // EA name
input int     MagicNumber            = 124;                    // Magic number for trades
input int     Deviation              = 3;                     // Deviation in points
input double  MaxSpread              = 0;                     // Max spread allowed for trading
input bool    AllowBuy               = true;                  // Allow buy trades
input bool    AllowSell              = true;                  // Allow sell trades
input int     KillzoneBeginHour      = 9;                     // Killzone begin hour
input int     KillzoneBeginMinute    = 30;                    // Killzone begin minute
input int     KillzoneEndHour        = 22;                    // Killzone end hour
input int     ATRPeriod              = 100;                   // ATR period for SL/TP/Offset
input int     StopLossPoints         = 142;                   // Stop loss level in points
input int     TakeProfitPoints       = 107;                   // Take profit level in points
input double  SL_Offset_ATR          = 0;                     // SL offset in ATR
input double  TP_Offset_ATR          = 0;                     // TP offset in ATR
input int     MaxOrders              = 2;                     // Maximum number of orders
input bool    TradeOnlyInWindow      = true;                  // Trade only in defined window
input double  RiskPercent            = 1.0;                   // Fixed risk percent

// Moving Average filter settings
input bool    UseMAFilter            = true;                  // Turn on/off MA filter
input ENUM_TIMEFRAMES MAFilterTF     = PERIOD_H4;             // TimeFrame for MA filter
input int     MAPeriod1              = 9;                     // MA1 period
input int     MAPeriod2              = 10;                    // MA2 period
input int     MAPeriod3              = 148;                   // MA3 period
input int     BarsForDiffMA          = 4;                     // Bars for calculate DiffMA
input ENUM_MA_METHOD MAMethod = MODE_SMA;                     // Moving Average method
input ENUM_APPLIED_PRICE MAApplyPrice = PRICE_CLOSE;          // MA applied price

// RSI filter settings
input bool    UseRSIFilter           = true;                  // Turn on/off RSI filter
input ENUM_TIMEFRAMES RSIFilterTF    = PERIOD_H3;             // TimeFrame for RSI filter
input int     RSIPeriod              = 11;                    // RSI period for fast
input double  OverbuyingLevel        = 70;                    // Overbuying level
input double  OversellingLevel       = 30;                    // Overselling level

// News filter settings
input bool    EnableNewsFilter       = false;                 // Enable news filter
input bool    ConsiderLowImpactNews  = false;                 // Consider low impact events
input bool    ConsiderMediumImpactNews = false;               // Consider medium impact events
input bool    ConsiderHighImpactNews = true;                  // Consider high impact events

// Day filter settings
input bool    EnableDayFilter        = false;                 // Enable day filter
input bool    TradeMonday            = true;                  // Trade on Monday
input bool    TradeTuesday           = true;                  // Trade on Tuesday
input bool    TradeWednesday         = true;                  // Trade on Wednesday
input bool    TradeThursday          = true;                  // Trade on Thursday
input bool    TradeFriday            = true;                  // Trade on Friday

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+



//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   // Check if trading is allowed
   if(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED)) return;
   
   // Check if within the trading window
   if(TradeOnlyInWindow && !IsWithinTradingWindow()) return;

   // Verify entry signals
   if(VerifyEntrySignal())
   {
      double lotSize = CalculateLotSize();
      OpenTrade(lotSize);
   }
}



//+------------------------------------------------------------------+
//| Verify entry signals                                             |
//+------------------------------------------------------------------+
bool VerifyEntrySignal()
  {
   if(UseMACDSignal() && (!UseMAFilter || UseMovingAverageFilter()) && (!UseRSIFilter || UseRSIFilter()))
     {
      return true;
     }
   return false;
  }

//+------------------------------------------------------------------+
//| MACD Signal Verification                                         |
//+------------------------------------------------------------------+
bool UseMACDSignal()
{
   // Create the MACD handle
   int macdHandle = iMACD(NULL, 0, 12, 26, 9, PRICE_CLOSE);
   
   if(macdHandle == INVALID_HANDLE)
   {
      Print("Failed to create MACD indicator handle");
      return false;
   }

   double macdMain[], macdSignal[];
   
   // Get the latest values for MACD line and Signal line
   if(CopyBuffer(macdHandle, 0, 0, 1, macdMain) <= 0 || 
      CopyBuffer(macdHandle, 1, 0, 1, macdSignal) <= 0)
   {
      Print("Failed to copy MACD values");
      IndicatorRelease(macdHandle);
      return false;
   }

   // Release the indicator handle to free up resources
   IndicatorRelease(macdHandle);

   // Check MACD line vs Signal line
   if(macdMain[0] > macdSignal[0])
      return true;  // Bullish signal
   if(macdMain[0] < macdSignal[0])
      return false; // Bearish signal

   return false;
}

//+------------------------------------------------------------------+
//| Moving Average Filter                                            |
//+------------------------------------------------------------------+
bool UseMovingAverageFilter()
{
   // Create handles for the three Moving Averages
   int ma1Handle = iMA(NULL, MAFilterTF, MAPeriod1, 0, MAMethod, MAApplyPrice);
   int ma2Handle = iMA(NULL, MAFilterTF, MAPeriod2, 0, MAMethod, MAApplyPrice);
   int ma3Handle = iMA(NULL, MAFilterTF, MAPeriod3, 0, MAMethod, MAApplyPrice);
   
   if(ma1Handle == INVALID_HANDLE || ma2Handle == INVALID_HANDLE || ma3Handle == INVALID_HANDLE)
   {
      Print("Failed to create Moving Average indicator handles");
      return false;
   }

   double ma1Value[], ma2Value[], ma3Value[];
   
   if(CopyBuffer(ma1Handle, 0, 0, 1, ma1Value) <= 0 ||
      CopyBuffer(ma2Handle, 0, 0, 1, ma2Value) <= 0 ||
      CopyBuffer(ma3Handle, 0, 0, 1, ma3Value) <= 0)
   {
      Print("Failed to copy Moving Average values");
      return false;
   }
   
   // Release the indicator handles to free up resources
   IndicatorRelease(ma1Handle);
   IndicatorRelease(ma2Handle);
   IndicatorRelease(ma3Handle);

   // Apply your condition to check the order of the MAs
   if(ma1Value[0] > ma2Value[0] && ma2Value[0] > ma3Value[0])
      return true;  // Bullish condition
   if(ma1Value[0] < ma2Value[0] && ma2Value[0] < ma3Value[0])
      return false; // Bearish condition

   return false;
}

//+------------------------------------------------------------------+
//| RSI Filter                                                       |
//+------------------------------------------------------------------+
bool UseRSIFilter()
{
   int rsiHandle = iRSI(NULL, RSIFilterTF, RSIPeriod, PRICE_CLOSE);
   
   if(rsiHandle == INVALID_HANDLE)
   {
      Print("Failed to create RSI indicator handle");
      return false;
   }

   double rsiValue[];
   if(CopyBuffer(rsiHandle, 0, 0, 1, rsiValue) <= 0)
   {
      Print("Failed to copy RSI values");
      return false;
   }

   if(rsiValue[0] > OverbuyingLevel) return false; // Overbought, avoid Long
   if(rsiValue[0] < OversellingLevel) return false; // Oversold, avoid Short
   
   // Release the indicator handle to free up resources
   IndicatorRelease(rsiHandle);

   return true;
}

//+------------------------------------------------------------------+
//| Calculate lot size based on risk management                      |
//+------------------------------------------------------------------+
double CalculateLotSize()
  {
   double accountEquity = AccountInfoDouble(ACCOUNT_EQUITY);
   double stopLoss = StopLossPoints * _Point;
   
   double lotSize = (accountEquity * RiskPercent / 100) / stopLoss;
   return NormalizeDouble(lotSize, 2);
  }

//+------------------------------------------------------------------+
//| Open Trade                                                       |
//+------------------------------------------------------------------+
void OpenTrade(double lotSize)
{
    double ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
    double bid = SymbolInfoDouble(_Symbol, SYMBOL_BID);
    MqlTradeRequest request;
    MqlTradeResult result;
    ZeroMemory(request);
    ZeroMemory(result);

    // Check if trade conditions are met and no current positions exist
    if(CheckTradeConditions() && PositionSelect(_Symbol) == false)
    {
        if(AllowBuy && AskTradeCondition())
        {
            request.action = TRADE_ACTION_DEAL;
            request.symbol = _Symbol;
            request.volume = lotSize;
            request.type = ORDER_TYPE_BUY;
            request.price = ask;
            request.deviation = Deviation;
            request.magic = MagicNumber;
            request.comment = "SMC Buy Order";
            request.type_filling = ORDER_FILLING_FOK;
            request.sl = ask - StopLossPoints * _Point;
            request.tp = ask + TakeProfitPoints * _Point;

            if(!OrderSend(request, result))
            {
                Print("OrderSend failed: ", result.retcode);
            }
        }
        if(AllowSell && BidTradeCondition())
        {
            request.action = TRADE_ACTION_DEAL;
            request.symbol = _Symbol;
            request.volume = lotSize;
            request.type = ORDER_TYPE_SELL;
            request.price = bid;
            request.deviation = Deviation;
            request.magic = MagicNumber;
            request.comment = "SMC Sell Order";
            request.type_filling = ORDER_FILLING_FOK;
            request.sl = bid + StopLossPoints * _Point;
            request.tp = bid - TakeProfitPoints * _Point;

            if(!OrderSend(request, result))
            {
                Print("OrderSend failed: ", result.retcode);
            }
        }
    }
}


//+------------------------------------------------------------------+
//| Check Trade Conditions                                           |
//+------------------------------------------------------------------+
bool CheckTradeConditions()
  {
   double spread = (SymbolInfoDouble(_Symbol, SYMBOL_ASK) - SymbolInfoDouble(_Symbol, SYMBOL_BID)) / _Point;
   
   if(MaxSpread > 0 && spread > MaxSpread) return false; // Check max spread
   
   return true;
  }

//+------------------------------------------------------------------+
//| Check if within trading window                                   |
//+------------------------------------------------------------------+
bool IsWithinTradingWindow()
{
   datetime currentTime = TimeCurrent();
   MqlDateTime tm;
   TimeToStruct(currentTime, tm);
   
   int currentHour = tm.hour;
   int currentMinute = tm.min;
   
   if ((currentHour > KillzoneBeginHour || 
       (currentHour == KillzoneBeginHour && currentMinute >= KillzoneBeginMinute)) &&
       (currentHour < KillzoneEndHour)) 
   {
       return true;
   }

   return false;
}


//+------------------------------------------------------------------+
//| Helper functions to check specific conditions                    |
//+------------------------------------------------------------------+
bool AskTradeCondition() { return true; }  // Implement specific logic
bool BidTradeCondition() { return true; }  // Implement specific logic

//+------------------------------------------------------------------+
//| Expert advisor entry point                                       |
//+------------------------------------------------------------------+
int OnStart()
  {
   // Main entry point if needed for specific logic
   return 0;
  }
 
int OnStart()
  {
   // Main entry point if needed for specific logic
   return 0;
  }
OnStart is for scripts only.
 
William Roeder #:
OnStart is for scripts only.

Thanks a lot

it seems there is something wrong with the logic. it doesn't make any trades
 
right click the symbol you're trading in the market watch window, click specification, and check what it says for Filling. Does it say fire or kill?
Also, check the strategy tester journal to see what it says when you try to backtest, and paste something here if you don't know what it means 
 
William Roeder #:
OnStart is for scripts only.

Yes, very true, it compiles a script. I tried it too.

 
I will work on converting it into a fully functional EA and return here for further discussion.
 
   int rsiHandle = iRSI(NULL, RSIFilterTF, RSIPeriod, PRICE_CLOSE);
   
   if(rsiHandle == INVALID_HANDLE) …
   double rsiValue[];
   if(CopyBuffer(rsiHandle, 0, 0, 1, rsiValue) <= 0)

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate/OnStart (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
          MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
          How to call indicators in MQL5 - MQL5 Articles (2010)