View the value in the OnCalculate parameter - MetaTrader 5 Script - MT4/MT5 Resources


This is a utility for junior indicator programmers or others who want to see OnCalculate and some other provided value functions.
Indicators show:
1) The latest value provided by the most recent OnCalculate call.
2) The previous value from the last OnCalculate call.
3) The first value when OnCalculate is executed for the first time.
4) The series value of each array, as_series or not_series, can be changed by clicking on the display.
Version 1.10 added the ability to dynamically change whether an array is set to a series - just click on the text. Additionally, the window bar and first visible bar values are dynamically set as the chart changes. The ON/OFF display indicates what will happen to OnCalculate's settings the next time it is executed, and what happened the last time it was executed.
Version 1.20 added the ability to choose to have the indicator set the array to as_series or not_series, also by clicking on the text. The indicator now also displays both ends of the time array and both ends of the iMA buffer. These changes are intended to make the difference between as_series and not_series arrays obvious. Additionally, the OnTimeEvent handler is now used to refresh the display as needed instead of displaying it for each quote. This reduces the execution time of OnCalculate from about 300 milliseconds to less than 1 millisecond - the code that checks the execution time is left in OnCalculate, just uncomment it to display the execution milliseconds.
This figure shows the values displayed by the OnCalculate_Values utility. Note the three values separated by a "/" separating "most recent value", "previous value", and "first value". OnCalculate values are set to "as_series" or "not_series" in each OnCalculate event - when "Set Array" is "ON", otherwise they remain as terminal defaults. Please note the value after the array name in parentheses, which indicates which bar the value comes from - the index "0" value, or "the value at the largest index".

The code implements a single indicator line, the opening price chart for each bar provided by iMA; the purpose is to provide a buffer to use the "BarsCalculated" function and display the display of the indicator when set to "as_series" or "not_series". Clicking iMA_Val[0] only sets the iMA buffer to as_series or not_series once when clicked; the iMA indicator array is not set every time OnCalculate is called.
An array collection holds the properties of each display object (OBJ_LABEL) in the display:

The "ArrayGetAsSeries" function is used to determine if the arrays in the OnCalculate parameter are time series arrays, and the display shows the result (As_Series or Not_Series) - the display shows that these arrays were not series initially, or from one call to the next after being set to series (the SetAsSeries function only sets them as series on opening, it lets them revert to default on closing - it does not set "As Series" to false).
The 3-member array ary_OnCalcVals holds 1) the most recent value, 2) the previous value, and 3) the first value found in the OnCalculate parameter. The CopyNewToOld and MoveNewTo functions obtain the current value of each display parameter and place it in the history storage provided by ary_OnCalcVals.
Attachment download
📎 oncalculate_values.mq5 (73.28 KB)
Source: MQL5 #23841
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •