# Lowest price of a given period

Hello everybody,

in the Expert that I am writing, I would need to identify the minimum price that occurred in the time interval between the opening of a market order and the current moment.

As far as I know, the iLowest is not useful in this case, because the beginning of the period (opening of the market order) and the end of the period (the current moment, i.e. the tick in progress) in general do not coincide with openings and / or candle closures ...

Thanks in advance for your feedback or suggestions!

Use the order open and close time and iHighest/Lowest on M1 frame over the total time span the position was open.

Marco vd Heijden:

Use the order open and close time and iHighest/Lowest on M1 frame over the total time span the position was open.

Hi Marco, thanks for reply.

Yes, this is a good approximation, but it does not guarantee that you will get the correct value. In fact, the order may have been opened during the minute, for example at "18:00:30".

As far as I know, the M1 timeframe will start at "18:00:00" or "18:01:00". Is this correct? Or is there any other workaround to consider?

M1 frame renews every minute so if you take all M1 bars that are between your opentime and openprice and closetime and closeprice then you will have the full time and price span.

If you need a more precise method then you have to monitor price for as long as the trade is open and record two variables high and low and simply apply two rules:

```double highest,lowest;

if(High > Highest)
{
Highest = High;
}

if(Low < Lowest)
{
Lowest = Low;
}```

That will leave you with the highest and lowest price within the tick resolution.

Note that this method does not include the spread parameter so the result may still vary depending on what you are trying to do.

`double highest=DBL_MIN,lowest=DBL_MAX;`

Marco vd Heijden:

M1 frame renews every minute so if you take all M1 bars that are between your opentime and openprice and closetime and closeprice then you will have the full time and price span.

If you need a more precise method then you have to monitor price for as long as the trade is open and record two variables high and low and simply apply two rules:

That will leave you with the highest and lowest price within the tick resolution.

Note that this method does not include the spread parameter so the result may still vary depending on what you are trying to do.
Ok, I think that using M1 frame will be enough for my need. Thank you for your support!

Hi Marco,

I'm trying to use M1 frame. Below the source code:

```bool Already_Processed=false;
int Wk_Ticket, Magic=123456;
void OnTick()
{
if(Already_Processed==false)
{
Wk_Ticket=OrderSend(Symbol(),OP_BUY,1,Ask,0,0,0,NULL,Magic,0, clrNONE);
if(Wk_Ticket<0)
{
Print("OrderSend failed. Error = ",_LastError);
}
else
{
Print("OrderSend Successful. Ticket = ",Wk_Ticket);
Print(" ");
Print("Reading Order");
int total=OrdersTotal();
for(int pos=0;pos<total;pos++)
{
if(OrderSelect(pos,SELECT_BY_POS)==true)
{
if(OrderMagicNumber()==Magic)
{
Print("Found Order # ",OrderTicket(), " - OrderOpenTime = ", OrderOpenTime());
int Wk_Shift=iBarShift(Symbol(),PERIOD_M1,OrderOpenTime(), false);
Print("Wk_Shift = ", Wk_Shift, " - _LastError = ", _LastError);
}
}
}
}
Already_Processed=true;
}
}
```

Now the problem is that the iBarShift generates the error code 4074. Please note that I am testing the EA on strategy tester with H1 frame, but I'm trying to use the M1 in the iBarShift function.

This is the output in the journal:

```2021.04.24 17:48:42.460 GBPUSD.,H1: 176421 tick events (24 bars, 177421 bar states) processed in 0:00:12.078 (total time 0:00:14.141)
2021.04.24 17:48:42.460 2020.09.24 23:57:31  Tester: order #1 is closed
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 GBPUSD.,H1: Wk_Shift = 0 - _LastError = 4074
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 GBPUSD.,H1: Found Order # 1 - OrderOpenTime = 2020.09.24 00:00:00
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 GBPUSD.,H1: Reading Order
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 GBPUSD.,H1:
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 GBPUSD.,H1: OrderSend Successful. Ticket = 1
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 GBPUSD.,H1: open #1 buy 1.00 GBPUSD. at 1.27235 ok
2021.04.24 17:48:30.369 2020.09.24 00:00:00  Test_001 test started
2021.04.24 17:48:28.316 TestGenerator: current spread 55 used
```

Many thanks in advance for any help on this!

Reason: