I need some help with this EA coding

 

Hello guys, i have trading strategies that i want to implement as EA, im not very good with coding so i try to code with the help of CGPT but when i finish and try it in mt4 and strategy tester, they are nothing happen and strategy tester also shows no result. I didnt know what happen because there is no error. I give you guys my coding, feel free to email me if you guys want to help personally. Million thanks in advance


// Define inputs/parameters
input double lotSize = 0.01;
input int takeProfit = 40;
input int stopLoss = 30;
input bool enterInEngulfingBox = true; // Setting to control whether to enter in Engulfing box

// Define variables
int h1EngulfingColor = Green; // Color for H1 Engulfing (Bullish)
int h1EngulfingBearishColor = Orange; // Color for H1 Engulfing (Bearish)
int m15LineColor = Blue; // Color for M15 Support/Resistance Lines

// Define global variables to store last detected H1 Engulfing and prices
datetime lastEngulfingTime = 0;
double lastHighestPrice = 0.0;
double lastLowestPrice = 0.0;

// Your entry logic goes here
void EnterTrade(double entryPrice, int tradeType) {
    int slippage = 3; // You can adjust the slippage value

    // Calculate stop loss and take profit levels
    double slPrice, tpPrice;
    if (tradeType == OP_BUY) {
        slPrice = entryPrice - stopLoss * Point;
        tpPrice = entryPrice + takeProfit * Point;
    } else {
        slPrice = entryPrice + stopLoss * Point;
        tpPrice = entryPrice - takeProfit * Point;
    }

    // Open the trade
    int ticket = OrderSend(Symbol(), tradeType, lotSize, entryPrice, slippage, slPrice, tpPrice, "EA Trade", 0, 0, tradeType == OP_BUY ? Green : Red);
    
    if (ticket > 0) {
        Print("Trade opened successfully. Ticket: ", ticket);
    } else {
        Print("Error opening trade. Error code: ", GetLastError());
    }
}

// Function to check for H1 Engulfing
void CheckH1Engulfing() {
    int currentBar = 0;
    double close = 0.0, low = 0.0, high = 0.0;

    // Loop through the last two bars (current and previous) on the H1 timeframe
    for (int i = 1; i >= 0; i--) {
        // Get the high and low of the current bar
        high = iHigh(Symbol(), 60, i);
        low = iLow(Symbol(), 60, i);

        // Get the open and close of the current bar
        double open = iOpen(Symbol(), 60, i);
        close = iClose(Symbol(), 60, i);

        // Check for Bullish Engulfing
        if (close > open && close > iClose(Symbol(), 60, i + 1) && open < iOpen(Symbol(), 60, i + 1)) {
            DrawEngulfingBox("BullishEngulfing", high, low, h1EngulfingColor);
        }
        // Check for Bearish Engulfing
        else if (close < open && close < iClose(Symbol(), 60, i + 1) && open > iOpen(Symbol(), 60, i + 1)) {
            DrawEngulfingBox("BearishEngulfing", high, low, h1EngulfingBearishColor);
        }

        currentBar++;
    }

    // Your entry logic for sell
    if (lastEngulfingTime > 0 && lastLowestPrice > 0) {
        if (close < lastLowestPrice && enterInEngulfingBox) {
            // Entry in the M15 horizontal lines zone
            EnterTrade(lastLowestPrice, OP_SELL);
        } else if (!enterInEngulfingBox) {
            // Entry at the engulfing point
            EnterTrade(low, OP_SELL);
        }
    }

    // Your entry logic for buy
    if (lastEngulfingTime > 0 && lastHighestPrice > 0) {
        if (close > lastHighestPrice && enterInEngulfingBox) {
            // Entry in the M15 horizontal lines zone
            EnterTrade(lastHighestPrice, OP_BUY);
        } else if (!enterInEngulfingBox) {
            // Entry at the engulfing point
            EnterTrade(high, OP_BUY);
        }
    }
}



// Function to draw rectangular boxes on the chart
void DrawEngulfingBox(string name, double high, double low, color boxColor) {
    int corner = 0; // Choose a corner (0: top-left, 1: top-right, 2: bottom-left, 3: bottom-right)
    int xDistance = 1; // Set the x-distance from the corner
    int yDistance = 3; // Set the y-distance from the corner

    // Create the rectangular box
        if (ObjectCreate(0, name, OBJ_RECTANGLE_LABEL, corner, 0, 0)) {
        Print("Box created successfully");
        ObjectSetInteger(0, name, OBJPROP_COLOR, boxColor);
        ObjectSetInteger(0, name, OBJPROP_CORNER, corner);
        ObjectSetInteger(0, name, OBJPROP_XDISTANCE, xDistance);
        ObjectSetInteger(0, name, OBJPROP_YDISTANCE, yDistance);
        ObjectSetDouble(0, name, OBJPROP_PRICE1, high);
        ObjectSetDouble(0, name, OBJPROP_PRICE2, low);
    }
}


// Function to check for M15 Support/Resistance Lines
void CheckM15SupportResistance() {
    // Find last highest and lowest prices in the specified range
    int rangeBars = 50; // Adjust this value based on your preference
    lastHighestPrice = iHigh(Symbol(), 15, iHighest(Symbol(), 15, MODE_HIGH, rangeBars, 0));
    lastLowestPrice = iLow(Symbol(), 15, iLowest(Symbol(), 15, MODE_LOW, rangeBars, 0));

    // Draw horizontal lines based on last highest and lowest prices
    DrawHorizontalLine("LastHighestPriceLine", lastHighestPrice, m15LineColor);
    DrawHorizontalLine("LastLowestPriceLine", lastLowestPrice, m15LineColor);
}

// Function to draw horizontal lines on the chart
void DrawHorizontalLine(string name, double price, color lineColor) {
    datetime currentTime = iTime(Symbol(), 0, 0);

    if (ObjectCreate(0, name, OBJ_TREND, 0, currentTime, price)) {
        ObjectSetInteger(0, name, OBJPROP_COLOR, lineColor);
        ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, true);
    }
}

// Start function
int start() {
    // Check for H1 Engulfing
    if (Period() == 60) {
        CheckH1Engulfing();
    }

    // Check for M15 Support/Resistance Lines after an H1 Engulfing
    if (Period() == 15 && lastEngulfingTime > 0) {
        CheckM15SupportResistance();
    }

    return(0);
}


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(60);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+