# How can we calculate highest and lowest candle close between specifed EA working hours

Hi dear friends and admins,

One of my expert advisor is running only between 09.30-18.10 hours.

I want to find, in 1 minute chart, highest and lowest candle close between that hours, anyone can help me?

Here is some code:

```
#include <Trade\PositionInfo.mqh>
...

input int      robotCalismaSaati = 09;  //Ea start hour
input int      robotCalismaDakikasi = 30; //Ea start minute
input int      robotDurmaSaati = 18;  //Ea stop hour
input int      robotDurmaDakikasi = 10; //Ea stop minute

int someIndicatorDefinition;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
someIndicatorDefinition = iCustom(Symbol...

return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//--- we work only at the time of the birth of new bar
static datetime PrevBars=0;
datetime time_0=iTime(0);
if(time_0==PrevBars)
return;
PrevBars=time_0;

MqlDateTime islemzamani;
datetime zaman = TimeCurrent();
TimeToStruct(zaman,islemzamani);
int robotTradeBaslamaZamani = (robotCalismaSaati*3600) + (robotCalismaDakikasi*60);
int robotTradeSonlanmaZamani = (robotDurmaSaati*3600) + (robotDurmaDakikasi*60);
int robotAnlikZaman = (islemzamani.hour*3600) + (islemzamani.min*60);
ZeroMemory(islemzamani);

double closeM1[];
ArraySetAsSeries(closeM1,true);
CopyClose(Symbol(),PERIOD_M1,0,5,closeM1);

double ... [];
ArraySetAsSeries (...,true);
CopyBuffer(someIndicatorDefinition,3,0,100,...);

//Sell  Close ---------------------------------------------------------------------------------------------
if(
(closeM1[1] > ...[1])
||
( robotAnlikZaman >= robotTradeSonlanmaZamani)
)
if(sell_islem_sayisi>0)
ClosePositions(POSITION_TYPE_SELL);
// Buy Close ---------------------------------------------------------------------------------------------
if(
( closeM1[1] < ...[1] )
||
( robotAnlikZaman >= robotTradeSonlanmaZamani)
)
if(buy_islem_sayisi>0)
ClosePositions(POSITION_TYPE_BUY);

// Open buy ---------------------------------------------------------------------------------

if(
buy_islem_sayisi==0
&& sell_islem_sayisi==0
)
{
//--- check condition on BUY
if(

(robotAnlikZaman > robotTradeBaslamaZamani && robotAnlikZaman < robotTradeSonlanmaZamani )
&&
closeM1[1] > Highest m1 candle of robot start hours & minutes  <------------------------------------------------------------------

)
{
if() {}
m_trade.Buy(...);
}

// Open sell: ----------------------------------------------------------------------------------
//--- check condition on SELL
else
if (
(robotAnlikZaman > robotTradeBaslamaZamani && robotAnlikZaman < robotTradeSonlanmaZamani )
&&
closeM1[1] < Lowest m1 candle of robot start hours & minutes  <------------------------------------------------------------------
)

{
if() {...}
m_trade.Sell(...);
}
}

void OnTradeTransaction(const MqlTradeTransaction &trans,
const MqlTradeRequest &request,
const MqlTradeResult &result)
{
//---

}

...```

Cuneyt Ates:

Hi dear friends and admins,

One of my expert advisor is running only between 09.30-18.10 hours.

I want to find, in 1 minute chart, highest and lowest candle close between that hours, anyone can help me?

Here is some code:

Use this indicator.

Files: