I'm beginner in MQL 4 and building my first EA. I want that the EA will buy or sell everyday from 9:00 to 10:59 depends on High and Low of H1 candle starting at 8:00 same day and sell it if it reaches the stoploss or profit target. It is actually working in that time, but sometimes it is not buying or selling the order too early. You can see it in the statement from 19.8.2016, which i attach. Can you please help me fix this error. I really don't know, where the mistake is. And it is not caused by computer or user account. Tested on two different computers on two different account and it is still work the same. Thank you for you answers.
GunSpawn
PS: Sorry for my bad English
Here is my code:
//+------------------------------------------------------------------+//| Test.mq4 |//| Copyright 2016, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright"Copyright 2016, MetaQuotes Software Corp."#property link"https://www.mql5.com"#property version"1.00"externdouble StopLoss_v_Pipech = 200;
externdouble Profit_Target_v_Pipech = 200;
externdouble Velikost_pozice = 0.01;
//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---Print("assa");
//---return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+//| Expert deinitialization function |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
int D = DayOfWeek(); // zjistí den v týdnu (neděle=0 … pátek=5)int m = TimeMinute(TimeCurrent()); // zjistí aktuální minutuint h = TimeHour(TimeCurrent()); // zjistí aktuální hodinuint ticket, close;
double SL = StopLoss_v_Pipech * Point;
double PT = Profit_Target_v_Pipech * Point;
int Magic_number = 1552;
string Text;
MqlTick last_tick;
/*Print("Current bar for GBPUSD+ H1: ",iTime("GBPUSD+",PERIOD_H1,1),", ", iOpen("GBPUSD+",PERIOD_H1,1),", ",
iHigh("GBPUSD+",PERIOD_H1,1),", ", iLow("GBPUSD+",PERIOD_H1,1),", ",
iClose("GBPUSD+",PERIOD_H1,1),", ", iVolume("GBPUSD+",PERIOD_H1,1));
*///closefor (int p = 0;p < OrdersTotal();p++)
{
if (OrderSelect(p, SELECT_BY_POS, MODE_TRADES) == true &&
D >= 0 && h == 10 && m == 31 && OrderMagicNumber() == Magic_number)
{
if (OrderType() == OP_BUY)
{ close = OrderClose(OrderTicket(),Velikost_pozice,Bid,2,Yellow); }
if (OrderType() == OP_SELL)
{ close = OrderClose(OrderTicket(),Velikost_pozice,Ask,2,Yellow); }
}
}
//projde všechny příkazyfor (int q = 0;q < OrdersTotal();q++)
{
//pokud je nějaké číslo rovno našemu, return 0if (OrderSelect(q,SELECT_BY_POS, MODE_TRADES) && OrderMagicNumber() == Magic_number)
{ return0;}
}
//buyif (SymbolInfoTick(Symbol(),last_tick))
{
if ((D >= 0 && h == 9 && m >= 00) && last_tick.ask >= iHigh(Symbol(),PERIOD_H1,1))
{
ticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,0,Ask-SL,Ask+PT,Text, Magic_number,0,Blue);
//symbol = měnový pár (univ.)//cmd = typ příkazu (market order = okamžitý, limit = za kolik se to má koupit, stop = za kolik se to má maximálně koupit//volume = velikost pozice v lotech//price = cena, za kterou vstupujeme (ask = buy, bid = sell)//slippage = max. odchylka příkazu//stoploss = podmínka ukončení odbchodu pokud jde obchod proti nám(ask = aktuální tržní cena)//takeprofit = podmínka ukončení obchodu, když jde s námi//comment = komentář //magic = identifikační číslo příkazu//expiration = doba platnosti (pouze pro čekající pokyny)//arrow_color = barva grafu
}
elseif ((D >= 0 && h == 10 && m >= 00) && last_tick.ask >= iHigh(Symbol(),PERIOD_H1,2))
{
ticket = OrderSend(Symbol(),OP_BUY,0.01,Ask,0,Ask-SL,Ask+PT,Text, Magic_number,0,Blue);
}
//sellelseif ((D >= 0 && h == 9 && m >= 00) && last_tick.ask <= iLow(Symbol(),PERIOD_H1,1))
{
ticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,0,Bid+SL,Bid-PT,Text, Magic_number,0,Red);
}
elseif ((D >= 0 && h == 10 && m >= 00) && last_tick.ask <= iLow(Symbol(),PERIOD_H1,2))
{
ticket = OrderSend(Symbol(),OP_SELL,0.01,Bid,0,Bid+SL,Bid-PT,Text, Magic_number,0,Red);
}
}
}
//+------------------------------------------------------------------+
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.
Good day,
I'm beginner in MQL 4 and building my first EA. I want that the EA will buy or sell everyday from 9:00 to 10:59 depends on High and Low of H1 candle starting at 8:00 same day and sell it if it reaches the stoploss or profit target. It is actually working in that time, but sometimes it is not buying or selling the order too early. You can see it in the statement from 19.8.2016, which i attach. Can you please help me fix this error. I really don't know, where the mistake is. And it is not caused by computer or user account. Tested on two different computers on two different account and it is still work the same. Thank you for you answers.
GunSpawn
PS: Sorry for my bad English
Here is my code: