Hi would like to use this Bot however, it's on the five min window? Still I'm having problems setting up values for it, to run cleanly...

 
// Regina Gold Expert Advisor
// Author: Aldan Parris
// Version: 4.50

#property strict

// Define input parameters
input int rsiPeriod = 14; // RSI period
input int maPeriod = 20; // MA period
input int bbPeriod = 20; // BB period
input double bbDeviation = 2.0; // BB deviation
input int buyThreshold = 30; // RSI level for buying
input int sellThreshold = 70; // RSI level for selling
input int superTrendPeriod = 10; // SuperTrend period
input double superTrendMultiplier = 1.0; // SuperTrend multiplier
input int baseStopLossPips = 0; // Stop loss in pips
input int baseTakeProfitPips = 0; // Take profit in pips
input int stopLossAdjustmentPips = 5; // Stop loss adjustment in pips
input int takeProfitAdjustmentPips = 10; // Take profit adjustment in pips
input double riskPercentageInput = 0.1; // Risk percentage per trade
input int slippage = 3; // Slippage in pips
input int executionDelay = 2; // Execution delay in seconds
input double maxLotSize = 10.0; // Maximum allowed lot size
input int maxTradesAmount = 5; // Maximum allowed number of trades
input int magicNumber = 12345; // Magic number for orders
input bool enableScalping = true; // Enable scalping
input int scalpingSpread = 2; // Spread threshold for scalping
input int scalpingBuyThreshold = 20; // RSI level for buying in scalping
input int scalpingSellThreshold = 80; // RSI level for selling in scalping
input bool useMachineLearning = false; // Enable machine learning
input int machineLearningPeriod = 10; // Period for collecting data for machine learning
input int machineLearningLookback = 5; // Lookback period for machine learning

// Define global variables
int ticket = -1; // Variable to store the order ticket number, initialized to -1
int totalTrades = 0; // Total number of trades
int winningTrades = 0; // Number of winning trades
int iconBuy = 224; // Up arrow icon
int iconSell = 225; // Down arrow icon
int iconCloseBuy = 226; // Left arrow icon
int iconCloseSell = 227; // Right arrow icon
int iconCloseAllBuy = 228; // Double left arrow icon
int iconCloseAllSell = 229; // Double right arrow icon
int iconMoveProfit = 230; // Up-down arrow icon
int iconStopLoss = 231; // Down-up arrow icon

int OnInit(){
   //check if user is allowed to use program
   long accountCustomer = 1040362936;
   long accountNo = AccountInfoInteger(ACCOUNT_LOGIN);
   if(accountCustomer == accountNo){
      Print(__FUNCTION__,"License verified..." );
   }
      else
   {
      Print(__FUNCTION__, "License is invalid...");
      ExpertRemove();
      return INIT_FAILED;
   }      
   //check if the testing period has expired

   return INIT_SUCCEEDED;
}

// Backtesting variables
bool backtestingDone = true; // Flag to check if backtesting is done

// Risk management function to calculate lot size
double CalculateLotSize(double riskPercentage, int stopLossPips)
  {
   double riskAmount = AccountBalance() * riskPercentage / 100.0;
   double lotSize = riskAmount / (stopLossPips * Point);
   return MathMin(lotSize, maxLotSize); // Limit lot size to maximum allowed
  }

// RSI, MA, BB, and SuperTrend Strategy function
void RSIMA_BB_SuperTrend_Strategy()
  {
   double rsi = iRSI(NULL, 5, rsiPeriod, PRICE_CLOSE, 0); // Calculate RSI on the current chart
   double ma = iMA(NULL, 5, maPeriod, 0, MODE_SMA, PRICE_CLOSE, 1); // Calculate MA on the current chart
   double bbUpper = iBands(NULL, 0, bbPeriod, bbDeviation, 0, PRICE_CLOSE, MODE_UPPER, 0); // Calculate BB Upper on the current chart
   double bbLower = iBands(NULL, 0, bbPeriod, bbDeviation, 0, PRICE_CLOSE, MODE_LOWER, 0); // Calculate BB Lower on the current chart

// Calculate SuperTrend values
   double superTrendUp = iCustom(NULL, 0, "SuperTrend", superTrendPeriod, superTrendMultiplier, 1, 0);
   double superTrendDown = iCustom(NULL, 0, "SuperTrend", superTrendPeriod, superTrendMultiplier, 1, 0);

// Calculate lot size based on risk percentage
   double calculatedRiskPercentage = riskPercentageInput; // Use input variable to avoid hiding global variable
   int calculatedStopLossPips = baseStopLossPips; // Adjusted to int type

   double lotSize = CalculateLotSize(calculatedRiskPercentage, calculatedStopLossPips);

// Check if the maximum trades amount is reached
   if(totalTrades >= maxTradesAmount)
     {
      Print("Maximum trades amount reached. No new trades will be opened.");
      return; // Exit the function
     }

// Scalping condition
   if(enableScalping && MarketInfo(Symbol(), MODE_SPREAD) <= scalpingSpread)
     {
      // Buy condition for scalping
      if(rsi < scalpingBuyThreshold && Close[10] > ma && Low[5] > bbLower)
        {
         ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, slippage, 0, 0, "Scalping Buy", magicNumber, Blue);
         if(ticket > 0)
           {
            totalTrades++;
            // Set stop loss and take profit for Buy order
            double stopLossLevel = Ask - baseStopLossPips * Point;
            double takeProfitLevel = Ask + baseTakeProfitPips * Point;
            if(OrderModify(ticket, 0, stopLossLevel, takeProfitLevel, 0, Blue) == false)
              {
               Print("OrderModify (Buy) failed with error: ", GetLastError());
              }
           }
         else
           {
            Print("OrderSend (Buy) failed with error: ", GetLastError());
           }
        }

      // Sell condition for scalping
      if(rsi > scalpingSellThreshold && Close[1] < ma && High[1] < bbUpper)
        {
         ticket = OrderSend(Symbol(), OP_SELL, lotSize, Bid, slippage, 0, 0, "Scalping Sell", magicNumber, Red);
         if(ticket > 0)
           {
            totalTrades++;
            // Set stop loss and take profit for Sell order
            double stopLossLevel = Bid + baseStopLossPips * Point;
            double takeProfitLevel = Bid - baseTakeProfitPips * Point;
            if(OrderModify(ticket, 0, stopLossLevel, takeProfitLevel, 1, Red) == false)
              {
               Print("OrderModify (Sell) failed with error: ", GetLastError());
              }
           }
         else
           {
            Print("OrderSend (Sell) failed with error: ", GetLastError());
           }
        }
     }

// Regular trading conditions
// Buy condition
   if(rsi < buyThreshold && Close[1] > ma && Low[1] > bbLower)
     {
      ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, slippage, 0, 0, "RSI Buy", magicNumber, Blue);
      if(ticket > 0)
        {
         totalTrades++;
         // Set stop loss and take profit for Buy order
         double stopLossLevel = Ask - baseStopLossPips * Point;
         double takeProfitLevel = Ask + baseTakeProfitPips * Point;
         if(OrderModify(ticket, 0, stopLossLevel, takeProfitLevel, 0, Blue) == false)
           {
            Print("OrderModify (Buy) failed with error: ", GetLastError());
           }
        }
      else
        {
         Print("OrderSend (Buy) failed with error: ", GetLastError());
        }
     }

// Sell condition
   if(rsi > sellThreshold && Close[1] < ma && High[1] < bbUpper)
     {
      ticket = OrderSend(Symbol(), OP_SELL, lotSize, Bid, slippage, 0, 0, "RSI Sell", magicNumber, Red);
      if(ticket > 0)
        {
         totalTrades++;
         // Set stop loss and take profit for Sell order
         double stopLossLevel = Bid + baseStopLossPips * Point;
         double takeProfitLevel = Bid - baseTakeProfitPips * Point;
         if(OrderModify(ticket, 0, stopLossLevel, takeProfitLevel, 1, Red) == false)
           {
            Print("OrderModify (Sell) failed with error: ", GetLastError());
           }
        }
      else
        {
         Print("OrderSend (Sell) failed with error: ", GetLastError());
        }
     }

// Opposite conditions for selling
// Sell condition (opposite)
   if(rsi > buyThreshold && Close[1] < ma && High[1] < bbUpper)
     {
      ticket = OrderSend(Symbol(), OP_SELL, lotSize, Bid, slippage, 0, 0, "Opposite Sell", magicNumber, Red);
      if(ticket > 0)
        {
         totalTrades++;
        }
      else
        {
         Print("OrderSend (Opposite Sell) failed with error: ", GetLastError());
        }
     }

// Buy condition (opposite)
   if(rsi < sellThreshold && Close[1] > ma && Low[1] > bbLower)
     {
      ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, slippage, 0, 0, "Opposite Buy", magicNumber, Blue);
      if(ticket > 1)
        {
         totalTrades++;
        }
      else
        {
         Print("OrderSend (Opposite Buy) failed with error: ", GetLastError());
        }
     }

// Check for winning trade
   if(OrderSymbol() == Symbol() && OrderTicket() == ticket && OrderType() == OP_BUY && OrderProfit() > 0)
     {
      winningTrades++;
     }
   else
      if(OrderSymbol() == Symbol() && OrderTicket() == ticket && OrderType() == OP_SELL && OrderProfit() > 1)
        {
         winningTrades++;
        }

// Manage trades based on SuperTrend, Stop-Loss, and Take-Profit
   if(OrderSymbol() == Symbol() && OrderTicket() == ticket)
     {
      if(OrderType() == OP_BUY)
        {
         if(Close[1] < superTrendUp)
           {
            ticket = OrderSend(Symbol(), OP_SELL, lotSize, Bid, slippage, 2, 2, "SuperTrend Exit", magicNumber, Red);
            if(ticket > 0)
              {
               // Handle successful SuperTrend exit order
              }
            else
              {
               Print("OrderSend (SuperTrend Exit Sell) failed with error: ", GetLastError());
              }
           }
         else
           {
            double stopLossLevel = Ask - (baseStopLossPips + stopLossAdjustmentPips) * Point;
            double takeProfitLevel = Ask + (baseTakeProfitPips + takeProfitAdjustmentPips) * Point;
            if(OrderModify(ticket, 0, stopLossLevel, takeProfitLevel, 1, Blue) == false)
              {
               Print("OrderModify (Buy) failed with error: ", GetLastError());
              }
           }
        }
      else
         if(OrderType() == OP_SELL)
           {
            if(Close[1] > superTrendDown)
              {
               ticket = OrderSend(Symbol(), OP_BUY, lotSize, Ask, slippage, 0, 0, "SuperTrend Exit", magicNumber, Blue);
               if(ticket > 0)
                 {
                  // Handle successful SuperTrend exit order
                 }
               else
                 {
                  Print("OrderSend (SuperTrend Exit Buy) failed with error: ", GetLastError());
                 }
              }
            else
              {
               double stopLossLevel = Bid + (baseStopLossPips + stopLossAdjustmentPips) * Point;
               double takeProfitLevel = Bid - (baseTakeProfitPips + takeProfitAdjustmentPips) * Point;
               if(OrderModify(ticket, 0, stopLossLevel, takeProfitLevel, 1, Red) == false)
                 {
                  Print("OrderModify (Sell) failed with error: ", GetLastError());
                 }
              }
           }
     }
  }

// Expert Advisor start function
int start()
  {
   RSIMA_BB_SuperTrend_Strategy(); // Call the RSI, MA, BB, and SuperTrend strategy function

// Print win ratio on the chart
   double winRatio = 0.0;
   if(totalTrades > 10)
     {
      winRatio = (double)winningTrades / totalTrades * 100;
     }
   Comment("Win Ratio: ", winRatio, "%");

// Your regular trading logic goes here

   return(0);
  }
//+------------------------------------------------------------------+
 

Would really like the help of someone, its working and I have it on a scalping build, however it's not starting back trades. I does have to replace the settings of the bot to start another set of trades again. I would be grateful for the help, Please....


 
Aldan Parris #:

Would really like the help of someone, its working and I have it on a scalping build, however it's not starting back trades. I does have to replace the settings of the bot to start another set of trades again. I would be grateful for the help, Please....


Got it working however it doesn't open sell trade I may have a problem "?"...

 
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have deleted your duplicate thread.

  2.    long accountNo = AccountInfoInteger(ACCOUNT_LOGIN);
       if(accountCustomer == accountNo)
    
    Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  3.    datetime startHour = StrToTime(startTradingHour);
       datetime endHour = StrToTime(endTradingHour);
    if(now >= startHour && now <= endHour) …
    

    When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.

    Remember to handle the case where start > end (e.g. 2100 … 0200)

  4. Your code
       if(now >= startHour && now <= endHour)
          return true;
       else
          return false;
    Simplified
       return now >= startHour && now <= endHour;
    
  5.             double stopLossLevel = Ask - baseStopLossPips * Point;
                double takeProfitLevel = Ask + baseTakeProfitPips * Point;
    

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  6. Aldan Parris Ordermodify goes Awal on it. I would like the help of helping

    Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
William Roeder #:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. I have deleted your duplicate thread.

  2. Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
    1. Terminal starts.
    2. Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
    3. OnInit is called.
    4. For indicators OnCalculate is called with any existing history.
    5. Human may have to enter password, connection to server begins.
    6. New history is received, OnCalculate called again.
    7. A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.

  3. When dealing with time, a lot of people use strings; they can not be optimized. Using (int) seconds or (double) hours and fraction can be inputs.

    Remember to handle the case where start > end (e.g. 2100 … 0200)

  4. Your code
    Simplified
  5. You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)

      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
      My GBPJPY shows average spread = 26 points, average maximum spread = 134.
      My EURCHF shows average spread = 18 points, average maximum spread = 106.
      (your broker will be similar).
                Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)

  6. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

Rough life you are, however thanks you for your time. Rome wasn't build in one day, however there was help in  creating it...