fly7680: Inspired by the code in the documents, so I can go back to the current time:
how can I subtract 3 minutes to the current time?
datetime dtvar = TimeCurrent() - 180; // 3 min * 60 sec = 180 sec
Great thanks!
I'm doing some tests with writing on my data files, but I have some problems....This is my code:
datetime var1= TimeCurrent() - 180;
string var2= TimeToString(var1,TIME_DATE|TIME_MINUTES);
datetime time_alert;
extern bool Audible_Alerts = true;
double myPoint;
void myAlert(string type, string message)
{
int handle;
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | RSIlevel "+Symbol()+","+Period()+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
else if(type == "RsiLevel")
{
handle = FileOpen("RSIlevel.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
if(handle != INVALID_HANDLE)
{
FileSeek (handle, 0, SEEK_END);
FileWrite(handle, type+ "|" +Symbol()+ "," +var2+ "|"+message);
FileClose(handle);
}
}
}
string var2= TimeToString(var1,TIME_DATE|TIME_MINUTES);
datetime time_alert;
extern bool Audible_Alerts = true;
double myPoint;
void myAlert(string type, string message)
{
int handle;
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | RSIlevel "+Symbol()+","+Period()+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
else if(type == "RsiLevel")
{
handle = FileOpen("RSIlevel.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
if(handle != INVALID_HANDLE)
{
FileSeek (handle, 0, SEEK_END);
FileWrite(handle, type+ "|" +Symbol()+ "," +var2+ "|"+message);
FileClose(handle);
}
}
}
The problem is that even by varying the seconds value to be subtracted from TimeCurrent, the final risltato is wrong. I do not understand why.
I think the mistake is to refresh, the first compilation of the code, the time is right, in the following signals, the time remains the same as the first.
tips to solve?
I should have solved including the variables within the function, confirmed to me that it's all written politely well?
void myAlert(string type, string message)
{
datetime var1= TimeCurrent() - 120;
string var2= TimeToString(var1,TIME_DATE|TIME_MINUTES);
int handle;
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | RSIlevel "+Symbol()+","+Period()+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
else if(type == "RsiLevel")
{
handle = FileOpen("RSIlevel.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
if(handle != INVALID_HANDLE)
{
FileSeek (handle, 0, SEEK_END);
FileWrite(handle, type+ "|" +Symbol()+ ","+Period()+ ","+var2+ "|"+message);
FileClose(handle);
}
}
}
{
datetime var1= TimeCurrent() - 120;
string var2= TimeToString(var1,TIME_DATE|TIME_MINUTES);
int handle;
if(type == "print")
Print(message);
else if(type == "error")
{
Print(type+" | RSIlevel "+Symbol()+","+Period()+" | "+message);
}
else if(type == "order")
{
}
else if(type == "modify")
{
}
else if(type == "RsiLevel")
{
handle = FileOpen("RSIlevel.txt", FILE_TXT|FILE_READ|FILE_WRITE|FILE_SHARE_READ|FILE_SHARE_WRITE, ';');
if(handle != INVALID_HANDLE)
{
FileSeek (handle, 0, SEEK_END);
FileWrite(handle, type+ "|" +Symbol()+ ","+Period()+ ","+var2+ "|"+message);
FileClose(handle);
}
}
}
fly7680:
You are not using "var1" or "var2" anywhere in your code! How are you using them to test or alter the functionality? You will have to show that part of the code and explain what it is you are expecting!
I should have solved including the variables within the function, confirmed to me that it's all written politely well?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Inspired by the code in the documents, so I can go back to the current time:
how can I subtract 3 minutes to the current time?
I tried to write the code so it does not work