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/parametersinputdouble lotSize = 0.01;
inputint takeProfit = 40;
inputint stopLoss = 30;
inputbool enterInEngulfingBox = true; // Setting to control whether to enter in Engulfing box// Define variablesint 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 pricesdatetime lastEngulfingTime = 0;
double lastHighestPrice = 0.0;
double lastLowestPrice = 0.0;
// Your entry logic goes herevoid EnterTrade(double entryPrice, int tradeType) {
int slippage = 3; // You can adjust the slippage value// Calculate stop loss and take profit levelsdouble 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 tradeint 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 Engulfingvoid 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 timeframefor (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 bardouble open = iOpen(Symbol(), 60, i);
close = iClose(Symbol(), 60, i);
// Check for Bullish Engulfingif (close > open && close > iClose(Symbol(), 60, i + 1) && open < iOpen(Symbol(), 60, i + 1)) {
DrawEngulfingBox("BullishEngulfing", high, low, h1EngulfingColor);
}
// Check for Bearish Engulfingelseif (close < open && close < iClose(Symbol(), 60, i + 1) && open > iOpen(Symbol(), 60, i + 1)) {
DrawEngulfingBox("BearishEngulfing", high, low, h1EngulfingBearishColor);
}
currentBar++;
}
// Your entry logic for sellif (lastEngulfingTime > 0 && lastLowestPrice > 0) {
if (close < lastLowestPrice && enterInEngulfingBox) {
// Entry in the M15 horizontal lines zone
EnterTrade(lastLowestPrice, OP_SELL);
} elseif (!enterInEngulfingBox) {
// Entry at the engulfing point
EnterTrade(low, OP_SELL);
}
}
// Your entry logic for buyif (lastEngulfingTime > 0 && lastHighestPrice > 0) {
if (close > lastHighestPrice && enterInEngulfingBox) {
// Entry in the M15 horizontal lines zone
EnterTrade(lastHighestPrice, OP_BUY);
} elseif (!enterInEngulfingBox) {
// Entry at the engulfing point
EnterTrade(high, OP_BUY);
}
}
}
// Function to draw rectangular boxes on the chartvoid 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 cornerint yDistance = 3; // Set the y-distance from the corner// Create the rectangular boxif (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 Linesvoid CheckM15SupportResistance() {
// Find last highest and lowest prices in the specified rangeint 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 chartvoid 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 functionint start() {
// Check for H1 Engulfingif (Period() == 60) {
CheckH1Engulfing();
}
// Check for M15 Support/Resistance Lines after an H1 Engulfingif (Period() == 15 && lastEngulfingTime > 0) {
CheckM15SupportResistance();
}
return(0);
}
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//--- create timerEventSetTimer(60);
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//--- destroy timerEventKillTimer();
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
//---
}
//+------------------------------------------------------------------+//| Timer function |//+------------------------------------------------------------------+voidOnTimer()
{
//---
}
//+------------------------------------------------------------------+//| Tester function |//+------------------------------------------------------------------+doubleOnTester()
{
//---double ret=0.0;
//---//---return(ret);
}
//+------------------------------------------------------------------+//| ChartEvent function |//+------------------------------------------------------------------+voidOnChartEvent(constint id,
constlong &lparam,
constdouble &dparam,
conststring &sparam)
{
//---
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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