I am seeking some advice on an issue that is not very clear to me.
In a 1 Min chart the last Close[] price - when does it take place, is it at the 1:45:59sec or 1:46:00? If the second case is correct, is the close[1]=open[0]?
My question tries to solve a problem in which I am trying to detect the last closing price of a candle as I would like to compare it with the previous one. In the case that last close[] takes place at 1:46:00 then I can use Time[0] to detect it. However I am very sure how to detect it when at 1:45:59sec.
Any help will be highly appreciated.
The price at the close of the preious bar is Close[1]
The price at the close 2 bars ago is Close[2]
The price at the open of the preious bar is Open[1]
The price at the open of the current bar is Open[0]
You get the picture.
The values will be acurate for the timeframe of the chart you are looking at.
You can you iClose() or iOpen() if you want to look at a different time frame than your chart but this will "hardcode" the timeframe being used (not a bad thing depending on what you want).
Do NOT try to look for a price at a time near the close of the bar by specifying the time. The close price of a bar is defined as the price of the last tick in the "time window" of the bar. There could be more than 1 tick in the final second, or there could be none. This would lead to inconsistent results from your code.
Good luck
whocares
Hi whocares,
I am very new to this forum and i would like to ask your advice on an issue that is not very clear to me.
Any help will be highly appreciated.
The frame of my code is attached.
M
/
//+------------------------------------------------------------------+
//| Global Variables
//+------------------------------------------------------------------+
//Datetime
datetime MyTime0;
..........
.........
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//Initialization of Variables/////////////////////////////////////////////////////////////////////////////////////////////
//Time[] indicates the time that the bars Open.
MyTime0=Time[0];
..........................................................................................
.................................................................................
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (Time[0]>MyTime0)
{
....................................................................................
}
//Reset MyTime0 to current Time
MyTime0=Time[0];
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
...................................................................................................
return(0);
}
Hi whocares,
I am very new to this forum and i would like to ask your advice on an issue that is not very clear to me.
Any help will be highly appreciated.
The frame of my code is attached.
M
I'm not sure exactly what you are trying to do, but if i understand it correctly, you could do it with time. ie, say you're on 5m charts, bar opens at 11:00. the bar will close at 11:05. next one will close, 11:10, etc...(those may not be the EXACT close and open times but you get the idea :D). so what you could do is judge the opening of a new bar based on that? im not really sure if that helps, but it might get some creative juices flowin. hope it helps =\
Hi whocares,
I am very new to this forum and i would like to ask your advice on an issue that is not very clear to me.
I am trying to determine what is the best and safest way to detect a new bar in a EA program. Until now, i am using the frame below.Any help will be highly appreciated.
The frame of my code is attached.
M
/
//+------------------------------------------------------------------+
//| Global Variables
//+------------------------------------------------------------------+
//Datetime
datetime MyTime0;
.......... .........
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//Initialization of Variables/////////////////////////////////////////////////////////////////////////////////////////////
//Time[] indicates the time that the bars Open.
MyTime0=Time[0];
..........................................................................................
.................................................................................
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if (Time[0]>MyTime0)
{
....................................................................................
}
//Reset MyTime0 to current Time
MyTime0=Time[0];
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
...................................................................................................
return(0);
}
You are on the right track. make a small change like below.
You need to update the Mytime0 var only when if the it is not the same (inside the if statement)
int start()
{
if (Time[0]>MyTime0)
{
....................................................................................
//Reset MyTime0 to current Time
MyTime0=Time[0];
}
}
return(0);
}
whocares
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In a 1 Min chart the last Close[] price - when does it take place, is it at the 1:45:59sec or 1:46:00? If the second case is correct, is the close[1]=open[0]?
My question tries to solve a problem in which I am trying to detect the last closing price of a candle as I would like to compare it with the previous one. In the case that last close[] takes place at 1:46:00 then I can use Time[0] to detect it. However I am very sure how to detect it when at 1:45:59sec.
Any help will be highly appreciated.