Most efficient way to access values defined for each timeframe? - page 2

 
Paul Anscombe #:
Don’t search what is effectively a static index use a cross ref function or switch

I'm not sure I inderstand what you mean...

*edit* are you saying that in the backend, for what I'm doing, a switch operator or cross ref function would be more efficient than the ArrayBsearch function? I can imagine that since the ArrayBsearch function does more than just return the index of the value I search for but also returns the index of the closest value if it can't find the exact one searched for. That later part could make the function less efficient for the way I'm using it depending on how it's coded in the backend.

*edit* also, with a switch operator, I can assign the settings to their specific vars as soon as I find the corresponding timeframe without having to record the index so I guess that's another reason why it might be more efficient.

*edit* I just changed my code to use a switch operator instead of searching an array, after giving it more thought, I do think it's more efficient (even if the speed difference is in fractions of milliseconds). I also like how it's easier to understand the code like this and allows me to use different types of vars if ever I want to for example add a string with the timeframe name to the list later.

switch(_Period) {
	case PERIOD_M1: setting1 = "setting 1"; setting2 = "setting 2"; break;
	case PERIOD_M2: setting1 = "setting 1"; setting2 = "setting 2"; break;
	case PERIOD_M3: setting1 = "setting 1"; setting2 = "setting 2"; break;
	// etc for all timeframes in MT5 ...
	case PERIOD_MN1: setting1 = "setting 1"; setting2 = "setting 2"; break;
}

Thanks to R4tna C and Paul Anscombe for the advice and examples!