i need help in correcting the code especially when compiling.thanks

 
// Define the necessary global variables
double monthlyProfit = 0.0;              // Tracks monthly profit
double ProfitTarget = 1000.0;            // Monthly profit target
bool allowNewTrade = true;               // Flag to allow new trades
datetime monthStart;                     // Stores the timestamp of the month's start
int MaxOrders = 5;                       // Maximum number of open orders allowed
int RSI_Period = 14;                     // RSI period
double RSI_Overbought = 70.0;            // RSI overbought level
double RSI_Oversold = 30.0;              // RSI oversold level
int Bands_Period = 20;                   // Bollinger Bands period
double Bands_Deviation = 2.0;            // Bollinger Bands deviation
double StopLossPips = 50.0;              // Default stop loss in pips
double TakeProfitPips = 50.0;            // Default take profit in pips

// Colors for Buy and Sell orders
double Buy_Orders = Green;
double Sell_Orders = Red;

// Constants for price action
#define PRICE_CLOSE 0
#define OP_BUY 0
#define OP_SELL 1

// Declare the missing identifiers
#define MODE_UPPER 1   // For Bollinger Bands' upper band
#define MODE_LOWER 2   // For Bollinger Bands' lower band

double GetOrderProfit(int ticket) {
   return HistoryOrderGetDouble(ticket,ORDER_PROFIT ); // Returns the profit of the specific order
}
//double OrderProfit() {
   //return HistoryOrderGetDouble(ORDER_PROFIT); // Correctly call the built-in function without any parameter
//}


datetime OrderCloseTime(int ticket) {
   return HistoryOrderGetInteger(ticket, ORDER_TIME_EXPIRATION); // Returns the close time of a specific order
}

int OrderType(int ticket) {
   return HistoryOrderGetInteger(ticket, ORDER_TYPE); // Returns the type of a specific order (buy/sell)
}

// Update monthly profit based on closed trades
monthlyProfit = CalculateMonthlyProfit();

double CalculateMonthlyProfit()
{
   double totalProfit = 0.0;

   // Iterate through the order history
   for (int i = 0; i < OrdersHistoryTotal(); i++)
   {
      // Select an order from the history
      if (OrderSelect(i, "SELECT_BY_POS", "MODE_HISTORY"))
      {
         // Check if the order was closed during the current month
         if (TimeMonth(OrderCloseTime()) == TimeMonth(TimeCurrent()))
         {
            // Add the profit of the closed order to totalProfit
            totalProfit += GetOrderProfit(OrderTicket());
         }
      }
   }

   return totalProfit;  // Return the total monthly profit
}
// Function to return the month of a given time
int TimeMonth(datetime TimeCurrent) 
{
   MqlDateTime dt;
   TimeToStruct(TimeCurrent, dt);
   return (int)dt.month;
}

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   // Initialize variables
   monthStart = TimeCurrent();  // Set the month start time
   monthlyProfit = 0.0;         // Initialize monthly profit
   allowNewTrade = true;        // Allow trading initially
   
   // Check if lot size and capital are valid
   double capital = AccountInfoDouble(ACCOUNT_EQUITY);
   if (capital < 100.0)  // Minimum capital requirement
   {
      Print("Insufficient capital. Minimum required is $100.");
      return INIT_FAILED;
   }
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   //---
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
   // Check if a new month has started
   if (TimeMonth(monthStart) != TimeMonth(TimeCurrent()))
   {
      monthStart = TimeCurrent();
      monthlyProfit = 0.0;  // Reset monthly profit at the start of the month
   }

   // Update lot size based on equity
   double equity = AccountInfoDouble(ACCOUNT_EQUITY);
   double lotSize = CalculateLotSize(equity);

   // Check if total profit this month reached $1000 (or more)
   if (monthlyProfit >= ProfitTarget)
   {
      allowNewTrade = true;  // Continue trading after reaching target
   }

   // Check the number of open positions
   if (CountOpenOrders() < MaxOrders && allowNewTrade)
   {
      // Perform market analysis (RSI, Bollinger Bands, etc.)
      double rsiValue = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE);
      double upperBand = iBands(NULL, 0, Bands_Period, Bands_Deviation, 0, PRICE_CLOSE);
      double lowerBand = iBands(NULL, 0, Bands_Period, Bands_Deviation, 0, PRICE_CLOSE);
      double currentVolume = CalculateVolumePercentage();

      // Trading logic for buy and sell
      if (rsiValue < RSI_Oversold && SymbolInfoDouble(Symbol(), SYMBOL_BID) < lowerBand)
      {
         // Buy condition
         OpenBuy(lotSize, currentVolume);
      }
      else if (rsiValue > RSI_Overbought && SymbolInfoDouble(Symbol(), SYMBOL_ASK) > upperBand)
      {
         // Sell condition
         OpenSell(lotSize, currentVolume);
      }
   }

}

//+------------------------------------------------------------------+
//| Calculate Lot Size based on Account Equity                       |
//+------------------------------------------------------------------+
double CalculateLotSize(double equity)
{
   double riskPerTrade = 0.01; // Risk 1-2% of current equity balance
   double stopLossPips = StopLossPips * _Point;
   double lotSize = (riskPerTrade * equity) / stopLossPips;

   // Ensure minimum lot size of 0.01
   if (lotSize < 0.01) lotSize = 0.01;

   return lotSize;
}

//+------------------------------------------------------------------+
//| Count Open Orders                                                 |
//+------------------------------------------------------------------+
int CountOpenOrders()
{
   int totalOrders = 0;

   for (int i = 0; i < OrdersTotal(); i++)
   {
      if (OrderSelect(i, "SELECT_BY_POS") && (OrderType(i) == OP_BUY || OrderType(i) == OP_SELL))
      {
         totalOrders++;
      }
   }

   return totalOrders;
}

//+------------------------------------------------------------------+
//| Calculate Volume Percentage                                       |
//+------------------------------------------------------------------+
double CalculateVolumePercentage()
{
   // For simplicity, assume that 100% is the maximum volume observed, e.g., 1000 units
   double maxVolume = 1000.0;  // Example value, adjust to your needs
   double currentVolume = iVolume(NULL, 0, 0);  // Get current tick volume
   double volumePercentage = (currentVolume / maxVolume) * 100.0;
   return volumePercentage;
}

//+------------------------------------------------------------------+
//| Open Buy Order with Volume-based Take Profit                      |
//+------------------------------------------------------------------+
void OpenBuy(double lotSize, double volumePercentage)
{
   double sl = SymbolInfoDouble(Symbol(), SYMBOL_BID) - StopLossPips * _Point;
   double tp = SymbolInfoDouble(Symbol(), SYMBOL_BID) + TakeProfitPips * _Point;

   // Extend take profit if volume is >= 80%
   if (volumePercentage >= 80)
   {
      tp = SymbolInfoDouble(Symbol(), SYMBOL_BID) + ExtendTakeProfitBasedOnVolume(true);
   }

   if (!OrderSend(Symbol(), OP_BUY, lotSize, SymbolInfoDouble(Symbol(), SYMBOL_BID), 10, sl, tp, "Buy Order", 0, 0, Green))
   {
      Print("Error opening buy order: ", GetLastError());
   }
}

//+------------------------------------------------------------------+
//| Open Sell Order with Volume-based Take Profit                    |
//+------------------------------------------------------------------+
void OpenSell(double lotSize, double volumePercentage)
{
   double sl = SymbolInfoDouble(Symbol(), SYMBOL_ASK) + StopLossPips * _Point;
   double tp = SymbolInfoDouble(Symbol(), SYMBOL_ASK) - TakeProfitPips * _Point;

   // Extend take profit if volume is >= 80%
   if (volumePercentage >= 80)
   {
      tp = SymbolInfoDouble(Symbol(), SYMBOL_ASK) - ExtendTakeProfitBasedOnVolume(false);
   }

   if (!OrderSend(Symbol(), OP_SELL, lotSize, SymbolInfoDouble(Symbol(), SYMBOL_ASK), 10, sl, tp, "Sell Order", 0, Red))
   {
      Print("Error opening sell order: ", GetLastError());
   }
}

//+------------------------------------------------------------------+
//| Extend Take Profit Based on Volume                               |
//+------------------------------------------------------------------+
double ExtendTakeProfitBasedOnVolume(bool isBuy)
{
   double currentVolumePercentage = CalculateVolumePercentage();
   double extendedPips = 0;

   // Check if the volume is decreasing to 30%
   while (currentVolumePercentage > 30)
   {
      currentVolumePercentage = CalculateVolumePercentage();
      
      // Dynamically increase the take profit distance if volume remains high
      extendedPips += 5;  // Increase take profit by 5 pips for every check
      Sleep(1000);  // Wait for 1 second before checking again
   }
   
   // Ensure the extended take profit is at least 50 pips more than initial
   extendedPips = MathMax(extendedPips, 50 * _Point);
   
   if (isBuy)
      return extendedPips * _Point;
   else
      return -extendedPips * _Point;
}

errors experiencing;
PositionInfo.mqh                        
DealInfo.mqh                    
'monthlyProfit' - unexpected token, probably type is missing?   RCV2.mq5        57      1
'CalculateMonthlyProfit' - undeclared identifier        RCV2.mq5        57      17
')' - expression expected       RCV2.mq5        57      40
variable already defined        RCV2.mq5        57      1
   see declaration of variable 'monthlyProfit'  RCV2.mq5        14      8
ambiguous access, can be one of:        RCV2.mq5        95      4
   0. variable 'monthlyProfit'  RCV2.mq5        14      8
   1. variable 'monthlyProfit'  RCV2.mq5        14      8
ambiguous access, can be one of:        RCV2.mq5        125     7
   0. variable 'monthlyProfit'  RCV2.mq5        14      8
   1. variable 'monthlyProfit'  RCV2.mq5        14      8
ambiguous access, can be one of:        RCV2.mq5        133     8
   0. variable 'monthlyProfit'  RCV2.mq5        14      8
   1. variable 'monthlyProfit'  RCV2.mq5        14      8
possible loss of data due to type conversion    RCV2.mq5        143     56
possible loss of data due to type conversion    RCV2.mq5        144     56
'ORDER_PROFIT' - undeclared identifier  RCV2.mq5        41      40
'HistoryOrderGetDouble' - no one of the overloads can be applied to the function call   RCV2.mq5        41      11
could be one of 2 function(s)   RCV2.mq5        41      11
   built-in: double HistoryOrderGetDouble(ulong,ENUM_ORDER_PROPERTY_DOUBLE)     RCV2.mq5        41      11
   built-in: bool HistoryOrderGetDouble(ulong,ENUM_ORDER_PROPERTY_DOUBLE,double&)       RCV2.mq5        41      11
possible loss of data due to type conversion from 'long' to 'datetime'  RCV2.mq5        49      4
possible loss of data due to type conversion from 'long' to 'int'       RCV2.mq5        53      4
'OrdersHistoryTotal' - undeclared identifier    RCV2.mq5        64      24
')' - expression expected       RCV2.mq5        64      43
'OrderSelect' - wrong parameters count  RCV2.mq5        67      11
   built-in: bool OrderSelect(ulong)    RCV2.mq5        67      11
'OrderCloseTime' - wrong parameters count       RCV2.mq5        70      24
   datetime OrderCloseTime(int) RCV2.mq5        48      10
'OrderTicket' - undeclared identifier   RCV2.mq5        73      43
')' - expression expected       RCV2.mq5        73      55
'month' - undeclared identifier RCV2.mq5        85      19
'OrderSelect' - wrong parameters count  RCV2.mq5        189     11
   built-in: bool OrderSelect(ulong)    RCV2.mq5        189     11
possible loss of data due to type conversion from 'long' to 'double'    RCV2.mq5        205     25
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
Please, don't request help for ChatGPT (or other A.I.) generated code. It generates horrible code, mixing MQL4 and MQL5. Please use the Freelance section for such requests — https://www.mql5.com/en/job