ArgMax() returns bar index different than iHighest() | Guide me why?

 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {

                datetime tBegin = iTime(_Symbol,PERIOD_D1,0);
                datetime tEnd           = TimeCurrent();
                vector  high;           high.CopyRates(_Symbol,_Period,COPY_RATES_HIGH,tBegin,tEnd);
                PrintFormat("tBegin[%s] tEnd[%s] Max[%2d][%.2f]",TimeToString(tBegin),TimeToString(tEnd),high.ArgMax(),high.Max());
   
                int iBegin = iBarShift(_Symbol,_Period,iTime(_Symbol,PERIOD_D1,0))-1;
                int iMax         = iHighest(_Symbol,_Period,MODE_HIGH,(iBegin-0),0);
                PrintFormat("tBegin[%d][%s] Max[%2d][%.2f]",iBegin,TimeToString(iTime(_Symbol,_Period,iBegin)),iMax,iHigh(_Symbol,_Period,iMax));

/*
2024.08.01 18:33:48.495 ArgMax (XAUUSD,H1)      tBegin[2024.08.01 00:00] tEnd[2024.08.01 16:03] Max[ 3][2458.38]
2024.08.01 18:33:48.495 ArgMax (XAUUSD,H1)      tBegin[15][2024.08.01 01:00]                    Max[12][2458.38]
*/

}
//+------------------------------------------------------------------+

Is there a vector can be set AsSeries? Seems vectors dont follow timeseries settings.

Can vector/matrix be used to get Highest/Lowest bar which matches with the chart bars sequence or I am trying to achieve something which is not possible?

Regards.

 
Anil Varma:

Is there a vector can be set AsSeries? Seems vectors dont follow timeseries settings.

Can vector/matrix be used to get Highest/Lowest bar which matches with the chart bars sequence or I am trying to achieve something which is not possible?

Regards.

1. First of all, you code is buggy and could lead to different max (HH) for both method. Why are you subtracting 1 to iBegin ?

Should be :

int iBegin = iBarShift(_Symbol,_Period,tBegin);
int iMax   = iHighest(_Symbol,_Period,MODE_HIGH,iBegin+1,0);

2. Even if you could set a vector "AsSeries", it would not necessarily give you the same index ("chart bar sequence" as you said), because it depends of the starting index. (in your use case it would work because you used data from current candle, indexed AS 0, see point 3).

3. Provided the starting AS index of your data is 0, it's trivial to get the AS index from a vector index.

int vIndexHH    = high.ArgMax();
int vASIndexHH  = high.Size()-vIndexHH-1;
 
Alain Verleyen #:
First of all, you code is buggy and could lead to different max (HH) for both method. Why are you subtracting 1 to iBegin ?

Hi Alain

I need to have adjustment for XAUUSD Symbol which opens at 01:01 hrs instead of normal 00:00 hrs for Forex. If not subtract than it calculate 23:00 Hrs bar (H1) of previous day as Begin bar. Your suggestion (iBegin+1) makes sense ... thanks for it.

Point 2: my objective is to get idx of highest bar from previous completed bar[1] to first bar of the day. Current bar[0] I dont want to include.

Point 3: I will test it 

any comments which method is better in terms of CPU performance?

THANKS A LOT and regards.