Hi Guys!
I need Help with the Code of an EA.
So I created my EA, and Now No compile Errors exist anymore, but the Problem is, it doesnt Take any trades..
Let me summarize the Logic fast
So, there is a Candle Time variable.
The High and Low of the Candle will be used as Zone and then we wait for a Candle breakout, with the specified min. ATR Settings and SMA Settings.
And Entry on Close, so the Candle needs to Close above/under the Zone for a Buy/sell and it's Rest of Body or Wick should Touch the Zone. (I will send some Pictures to clarify the logic)
Also spreads Settings, is to make TP smaller and SL wider, so you dont get Wicked Out/dont reach your tp..
And thats how SL works:
If it's a buy, SL will be the Low of that Candle that we used in the Settings (Here 10:00)
And If it's a sell, it will be the high of that candle
ofcourse because of spreads Settings, it will get wider (Here 2 Pips)
And Im also Not Understanding how to Programm the Max Orders code
So yeah Here is the Code:
I tried to ask chatgpt But litterally gave me the Code lightly updated with many comments..
Didnt Help me, thats why I want to ask you Guys, so you hopefully can Help me fixing it.
Yeah thats the Code, it Took a Lot of effort, but it keeps Not working, thanks in Advance for helping
I need Help with the Code of an EA.
So I created my EA, and Now No compile Errors exist anymore, but the Problem is, it doesnt Take any trades..
Let me summarize the Logic fast
So, there is a Candle Time variable.
The High and Low of the Candle will be used as Zone and then we wait for a Candle breakout, with the specified min. ATR Settings and SMA Settings.
And Entry on Close, so the Candle needs to Close above/under the Zone for a Buy/sell and it's Rest of Body or Wick should Touch the Zone. (I will send some Pictures to clarify the logic)
Also spreads Settings, is to make TP smaller and SL wider, so you dont get Wicked Out/dont reach your tp..
And thats how SL works:
If it's a buy, SL will be the Low of that Candle that we used in the Settings (Here 10:00)
And If it's a sell, it will be the high of that candle
ofcourse because of spreads Settings, it will get wider (Here 2 Pips)
And Im also Not Understanding how to Programm the Max Orders code
So yeah Here is the Code:
MQL4:
// Define parameters input string candleTime = "10:00"; Input int maxOrders = 1; input int tpPips = 200; input int magicNumber = 282518; input double lots = 0.01; input int atrPeriod = 14; input double minAtrLevel = 1.00; input int smaPeriod = 200; input int bePoints = 100; input int trailStartPoints = 110; input int trailStepPoints = 50; input int trailStopPoints = 300; input int spreadPips = 2; // Global variables double zoneHigh, zoneLow; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Add any initialization code here return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Check if it's the specified candle time if (TimeHour(TimeCurrent()) == StringToInteger(StringSubstr(candleTime, 0, 2)) && TimeMinute(TimeCurrent()) == StringToInteger(StringSubstr(candleTime, 3, 2))) { zoneHigh = High[1]; zoneLow = Low[1]; // Check if the ATR level meets the criteria double atrValue = iATR(_Symbol, 0, atrPeriod); if (atrValue >= minAtrLevel * Point) { // Check for buy condition if (Close[1] > zoneHigh && Close[1] > iMA(_Symbol, 0, smaPeriod, 0, MODE_SMA, PRICE_CLOSE, 0)) { // Buy logic double entryPriceBuy = Ask; double slPriceBuy = zoneLow - spreadPips * Point; double tpPriceBuy = entryPriceBuy + tpPips * Point - spreadPips * Point; ModifyOrder(entryPriceBuy, slPriceBuy, tpPriceBuy); } // Check for sell condition else if (Close[1] < zoneLow && Close[1] < iMA(_Symbol, 0, smaPeriod, 0, MODE_SMA, PRICE_CLOSE, 0)) { // Sell logic double entryPriceSell = Bid; double slPriceSell = zoneHigh + spreadPips * Point; double tpPriceSell = entryPriceSell - tpPips * Point + spreadPips * Point; ModifyOrder(entryPriceSell, slPriceSell, tpPriceSell); } } } } // Function to modify order void ModifyOrder(double entryPrice, double slPrice, double tpPrice) { // Apply spread adjustment slPrice += spreadPips * Point; tpPrice -= spreadPips * Point; int ticket = OrderSend(_Symbol, OP_BUY, lots, entryPrice, 3, slPrice, tpPrice, "Buy Order", magicNumber, 0, Blue); // Check if the order is opened successfully if (ticket > 0) { Print("Order opened successfully. Ticket: ", ticket); } else { Print("Error opening order. Error code: ", GetLastError()); } } //+------------------------------------------------------------------+
I tried to ask chatgpt But litterally gave me the Code lightly updated with many comments..
Didnt Help me, thats why I want to ask you Guys, so you hopefully can Help me fixing it.
MQL4:
// Define parameters input string candleTime = "10:00"; input int tpPips = 200; input int magicNumber = 282518; input double lots = 0.01; input int atrPeriod = 14; input double minAtrLevel = 1.00; input int smaPeriod = 200; input int bePoints = 100; input int trailStartPoints = 110; input int trailStepPoints = 50; input int trailStopPoints = 300; input int spreadPips = 2; // Global variables double zoneHigh, zoneLow; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { // Add any initialization code here return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { // Check if it's the specified candle time if (TimeHour(TimeCurrent()) == StringToInteger(StringSubstr(candleTime, 0, 2)) && TimeMinute(TimeCurrent()) == StringToInteger(StringSubstr(candleTime, 3, 2))) { zoneHigh = High[1]; zoneLow = Low[1]; // Check if the ATR level meets the criteria double atrValue = iATR(_Symbol, 0, atrPeriod); if (atrValue >= minAtrLevel * Point) { // Check for buy condition if (Close[1] > zoneHigh && Close[1] > iMA(_Symbol, 0, smaPeriod, 0, MODE_SMA, PRICE_CLOSE, 0)) { // Buy logic double entryPriceBuy = Ask; double slPriceBuy = zoneLow - spreadPips * Point; double tpPriceBuy = entryPriceBuy + tpPips * Point - spreadPips * Point; ModifyOrder(entryPriceBuy, slPriceBuy, tpPriceBuy); } // Check for sell condition else if (Close[1] < zoneLow && Close[1] < iMA(_Symbol, 0, smaPeriod, 0, MODE_SMA, PRICE_CLOSE, 0)) { // Sell logic double entryPriceSell = Bid; double slPriceSell = zoneHigh + spreadPips * Point; double tpPriceSell = entryPriceSell - tpPips * Point + spreadPips * Point; ModifyOrder(entryPriceSell, slPriceSell, tpPriceSell); } } } } // Function to modify order void ModifyOrder(double entryPrice, double slPrice, double tpPrice) { // Apply spread adjustment slPrice += spreadPips * Point; tpPrice -= spreadPips * Point; int ticket = OrderSend(_Symbol, OP_BUY, lots, entryPrice, 3, slPrice, tpPrice, "Buy Order", magicNumber, 0, Blue); // Check if the order is opened successfully if (ticket > 0) { Print("Order opened successfully. Ticket: ", ticket); } else { Print("Error opening order. Error code: ", GetLastError()); } } //+------------------------------------------------------------------+
Yeah thats the Code, it Took a Lot of effort, but it keeps Not working, thanks in Advance for helping
Attachments
-
Screenshot_2024-03-07-20-00-09-383_net.metaquotes.metatrader5-edit.jpg102.6 KB · Views: 3
-
Screenshot_2024-03-07-20-01-40-664_net.metaquotes.metatrader5-edit.jpg99.1 KB · Views: 3
-
Screenshot_2024-03-07-20-02-52-812_net.metaquotes.metatrader5-edit.jpg97.8 KB · Views: 2
-
Screenshot_2024-03-07-20-05-24-413_net.metaquotes.metatrader5-edit.jpg108 KB · Views: 2
-
Screenshot_2024-03-07-20-07-10-423_net.metaquotes.metatrader5-edit.jpg101.6 KB · Views: 2
-
Screenshot_2024-03-08-07-11-39-365_net.metaquotes.metatrader5-edit.jpg115.4 KB · Views: 3
Last edited by a moderator: