How to get counted candles since start?

호진·2023년 3월 10일
0

MQL5

목록 보기
2/2

Code

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick() {
	// create a price array
	MqlRates priceData[];
	
	// sort the array from the current candle downwards
	ArraySetAsSeries(priceData, true);
	
	// copy candle prices for 3 candles into array
	CopyRates(_Symbol, _Period, 0, 3, priceData);
	
	// create a counter for the candle
	static int candleCounter;
	
	// create DateTime variable for the last time stamp
	static datetime timeStampLastCheck;
	
	// create DateTime variable for the current candle
	datetime timeStampCurrentCandle;
	
	// read time stamp for current candle in array
	timeStampCurrentCandle = priceData[0].time;
	
	// if the current time stamp is different from last time
	if (timeStampCurrentCandle != timeStampLastCheck) {
		// remember current timestamp for next time
		timeStampLastCheck = timeStampCurrentCandle;
		
		// add 1 to the candleCounter
		candleCounter += 1;		
	} 
	
	Comment("Counted candles since start : ", candleCounter);	
}
//+------------------------------------------------------------------+

Output

profile
💭(。•̀ᴗ-)✧

0개의 댓글