How to get a highest candle within the last 10 candles in mql5?

호진·2023년 3월 3일
0

MQL5

목록 보기
1/2

ArraySetAsSeries

The function sets the AS_SERIES flag to a selected object of a dynamic array, and elements will be
indexed like in timeseries.

bool ArraySetAsSeries(
	const void& array[], // array by reference
	bool flag // true denotes reverse order of indexing
);

CopyHigh

The function gets into high_array the history data of highest bar prices for the selected symbol-period
pair in the specified quantity. It should be noted that elements ordering is from present to past, i.e.,
starting position of 0 means the current bar.

When copying the yet unknown amount of data, it is recommended to use dynamic array as a target
array, because if the requested data count is less (or more) than the length of the target array,
function tries to reallocate the memory so that the requested data fit entirely.
If you know the amount of data you need to copy, it should better be done to a statically allocated
buffer, in order to prevent the allocation of excessive memory.
No matter what is the property of the target array - as_series=true or as_series=false. Data will be
copied so that the oldest element will be located at the start of the physical memory allocated for the
array. There are 3 variants of function calls.

- Call by the first position and the number of required elements

int CopyHigh(
	string symbol_name, // symbol name
	ENUM_TIMEFRAMES timeframe, // period
	int start_pos, // start position
	int count, // data count to copy
	double high_array[] // target array to copy
);

- Call by the start date and the number of required element

int CopyHigh(
	string symbol_name, // symbol name
	ENUM_TIMEFRAMES timeframe, // period
	datetime start_time, // start date and time
	int count, // data count to copy
	double high_array[] // target array to copy
);

ArrayMaximum

Searches for the largest element in the first dimension of a multidimensional numeric array.

int ArrayMaximum(
	const void& array[], // array for search
	int start = 0, // index to start checking with
	int count = WHOLE_ARRAY // number of checked elements
);

Code

void OnTick() {
	double HighestCandleM1;
	double High[];
	ArraySetAsSeries(High, true);
	CopyHigh(_Symbol, PERIOD_M1, 0, 11, High);
	HighestCandleM1 = ArrayMaximum(High, 0, 11);
	
	Comment("Highest candle within the last 10 candles : " + HighestCandleM1);
}

Result

profile
💭(。•̀ᴗ-)✧

0개의 댓글