Perhaps first we need to clearly define what you expect the code to do.
Although it might seem to be a simple EA, working with time isn't the easiest place to begin.
Most EAs are designed to work when a new tick comes in. But, you don't know when the next tick is going to arrive. It depends on the instrument, the time of day, the day of the week and so on.
If you are happy to accept "on the first tick that arrives after 10:14:00" then life becomes easier.
If you want "a trade to be placed at exactly 10:14:00" then it gets more complicated.
Perhaps first we need to clearly define what you expect the code to do.
Although it might seem to be a simple EA, working with time isn't the easiest place to begin.
Most EAs are designed to work when a new tick comes in. But, you don't know when the next tick is going to arrive. It depends on the instrument, the time of day, the day of the week and so on.
If you are happy to accept "on the first tick that arrives after 10:14:00" then life becomes easier.
If you want "a trade to be placed at exactly 10:14:00" then it gets more complicated.
Which are you looking for?
I think we have thick every minutes and it possible to use 10:14 but i know this is not stable that we have thick on every seconds like 10:14:00" !
Is your code work with first case? can you explain how it work ? it isn't clear for me !
how can i do it for second case ? is this true for second case?:
#define DAY 86400// day is 86400 seconds #define HOUR 3600// hour is 3600 seconds #define MINUTE 60// minute is 60 seconds #define SECOND 1
And can we use this code for Hundredth of a second(centisecond ) and millisecond:(is it possible to use it in real trading ? is there this Accuracy in trading? )
#define DAY 86400// day is 8'640'000 centiseconds #define HOUR 3600// hour is 360'000 centiseconds #define MINUTE 60// minute is 6'000 centiseconds #define SECOND 0.01 // second is 0.01 centiseconds #define CENTISECOND1
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.
{
datetime now = TimeCurrent();
if(now >= NextTrade)
{
if(OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0) < 0)
{
printf("OrderSend() failed. Error code: %i", GetLastError());
}
else
{
datetime midnight = now - (now % DAY);
NextTrade = midnight + DAY + StartHour*HOUR + StartMinute*MINUTE;
printf("Next Trade scheduled for %s", TimeToString(NextTrade));
}
}
}
datetime midnight = now - (now % DAY);
NextTrade = midnight + DAY + StartHour*HOUR + StartMinute*MINUTE;
if(now >= NextTrade){
if(OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0) < 0)
:
and then
and then we shouldn't do this ??
then write :
Thanks so much for your help and your time
Perhaps first we need to clearly define what you expect the code to do.
Although it might seem to be a simple EA, working with time isn't the easiest place to begin.
Most EAs are designed to work when a new tick comes in. But, you don't know when the next tick is going to arrive. It depends on the instrument, the time of day, the day of the week and so on.
If you are happy to accept "on the first tick that arrives after 10:14:00" then life becomes easier.
If you want "a trade to be placed at exactly 10:14:00" then it gets more complicated.
Which are you looking for?
Perhaps first we need to clearly define what you expect the code to do.
Although it might seem to be a simple EA, working with time isn't the easiest place to begin.
Most EAs are designed to work when a new tick comes in. But, you don't know when the next tick is going to arrive. It depends on the instrument, the time of day, the day of the week and so on.
If you are happy to accept "on the first tick that arrives after 10:14:00" then life becomes easier.
If you want "a trade to be placed at exactly 10:14:00" then it gets more complicated.
Which are you looking for?
Is your code work with first case? can you explain how it work ? it isn't clear for me !
how can i do it for second case ? is this true for second case?:
#define HOUR 3600 // hour is 3600 seconds
#define MINUTE 60 // minute is 60 seconds
#define SECOND 1
input double Lots = 0.1;
input int TP = 200;
input int SL = 200;
input string comment = "MyOrder";
input int magic = 1234;
input int StartHour = 14;
input int StartMinute = 15;
input int StartSecond = 16;
datetime NextTrade = StartHour*HOUR + StartMinute*MINUTE + StartSecond*SECOND;
//+--------------------------------------------------------------------------------------+
//| OnInit() |
//+--------------------------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+--------------------------------------------------------------------------------------+
//| OnDeinit() |
//+--------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+--------------------------------------------------------------------------------------+
//| OnTick() |
//+--------------------------------------------------------------------------------------+
void OnTick()
{
datetime now = TimeCurrent();
if(now >= NextTrade)
{
if(OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0) < 0)
{
printf("OrderSend() failed. Error code: %i", GetLastError());
}
else
{
datetime midnight = now - (now % HOUR);
NextTrade = midnight + HOUR + StartHour*HOUR + StartMinute*MINUTE + StartSecond*SECOND;
printf("Next Trade scheduled for %s", TimeToString(NextTrade));
}
}
}
And can we use this code for Hundredth of a second(centisecond ) and millisecond:(is it possible to use it in real trading ? is there this Accuracy in trading? )
#define HOUR 3600 // hour is 360'000 centiseconds
#define MINUTE 60 // minute is 6'000 centiseconds
#define SECOND 0.01 // second is 0.01 centiseconds
#define CENTISECOND 1
input double Lots = 0.1;
input int TP = 200;
input int SL = 200;
input string comment = "MyOrder";
input int magic = 1234;
input int StartHour = 14;
input int StartMinute = 15;
input int StartSecond = 16;
input int StartCentiSecond = 885;
datetime NextTrade = StartHour*HOUR + StartMinute*MINUTE + StartSecond*SECOND + StartCentiSecond*CENTISECOND ;
//+--------------------------------------------------------------------------------------+
//| OnInit() |
//+--------------------------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+--------------------------------------------------------------------------------------+
//| OnDeinit() |
//+--------------------------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+--------------------------------------------------------------------------------------+
//| OnTick() |
//+--------------------------------------------------------------------------------------+
void OnTick()
{
datetime now = TimeCurrent();
if(now >= NextTrade)
{
if(OrderSend(Symbol(),OP_BUY,Lots,Ask,1,0,Ask+(TP*Point),comment,magic,0,0) < 0)
{
printf("OrderSend() failed. Error code: %i", GetLastError());
}
else
{
datetime midnight = now - (now % HOUR);
NextTrade = midnight + HOUR + StartHour*HOUR + StartMinute*MINUTE + StartSecond*SECOND + StartCentiSecond*CENTISECOND;
printf("Next Trade scheduled for %s", TimeToString(NextTrade));
}
}
}
Again ,Thanks so much