1. Introduction to Onbalance Volume Indicator (00:00 – 00:16)
    • Introduction to the Onbalance Volume Indicator, explaining its purpose and how it indicates potential price movements.
  2. Starting with MetaEditor in MetaTrader (00:16 – 00:41)
    • Instructions on opening MetaEditor in MetaTrader and creating a new Expert Advisor file named ‘SimpleIOBValue’.
  3. Setting Up the Expert Advisor (00:41 – 01:00)
    • Initial setup of the Expert Advisor, including removing unnecessary lines and preparing the code environment.
  4. Creating and Sorting the Array (01:00 – 01:15)
    • Creating a double array for the Expert Advisor and using ‘ArraySetAsSeries’ to sort the array from the current candle downwards.
  5. Defining the Onbalance Volume (01:15 – 01:52)
    • Using the ‘iOBV’ function to define the Onbalance Volume with the current symbol, period, and ‘VOLUME_TICK’.
  6. Filling the Array with Data (01:52 – 02:43)
    • Using ‘CopyBuffer’ to fill the Expert Advisor array with data for the Onbalance Volume Indicator.
  7. Calculating the Current Onbalance Value (02:43 – 03:12)
    • Calculating the current Onbalance Value by looking at the value for candle 0 in the Expert Advisor array.
  8. Creating Chart Output (03:12 – 03:52)
    • Using the ‘Comment’ function to create a chart output displaying the calculated Onbalance Value.
  9. Compiling and Testing in MetaTrader (03:52 – 04:35)
    • Instructions on compiling the code, resolving warnings, and testing the Expert Advisor in MetaTrader with a visualization of the Onbalance Volume Indicator.


In this video we are looking at this little Indicator, it’s the Onbalance Volume Indicator.
Investopedia ( says that the Onbalance Volume should show us that whenever the Indicator increases without a significant price change the price should follow and now we are going to find out how to automate the Onbalance Volume Indicator in MQL5.
To do that please click on a little button here or press F4 in your Metatrader, now you should see the Metaeditor window and here we click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this file: “SimpleIOBValue”, click on “Continue”, “Continue” and “Finish”.
Now you can delete everything above the “OnTick” function and let’s also remove the two comment lines here.
This is a very simple Indicator, we start by creating an array for the Expert Advisor (EAArray), this one will be a double array so it can hold floating type values, now we use “ArraySetAsSeries” to sort the array (EAArray) from the current candle downwards and to define the Onbalance Volume we use the included function that is called: “iOBV”, so let’s mark that and press F1, here we see that it uses the current symbol on the chart, the currently selected period on the chart and the third parameter is called: applied volume so let’s click on this link and we see that we could use the tick volume or the real volume. In our case we use “VOLUME_TICK”.
Now we use “CopyBuffer” to fill our Expert Advisor array (EAArray) according to the IOBV definition (IOBVDefinition) that we have created here for the first buffer… well, a buffer is in our case this line here, some Indicators have more than one buffer for example if I would “Insert/ Indicators/ Trend/ Bollinger Bands”, this one has three different lines, so it uses 3 buffers and the first buffers is always called buffer 0 (zero), the second buffer would be number one and so on. That’s because arrays are zero based in MQL5 so the first item in an array is always called by calling the index zero.
Let’s copy the data for 3 candles and the result will be stored in our EA array (EAArray).
To calculate the current Onbalance Value (IOBVVALUE) we now need to look at the value for candle 0 (zero) in our EA array (EAArray), remember this one is the current candle so this would be candle 0 (zero), candle 1, candle 2, and so on.
Finally we want to create a chart output that’s done with the “Comment” function and it will output the words: “The IOB Value is:” followed by the calculated value, so let’s compile that and this worked without any errors, we only have a minor warning – you see the little triangle here – I have used an int value, let’s try double recompile the code and now the warning is gone, so now that everything is finished we can click on the little button here or press F4 to go back to Metatrader.
And in Metatrader we click on: “View/ Strategy Tester”, I select a new file: “SimpleIOBValue”, mark the visualization option here and start a test.
…and here we are, this is the value and it’s also drawn on the chart here as you can see, it has one digit behind the dot and this digit is always zero so if I use an integer here recompile the code I will get the warning again but when I restart the test you will see that the digit and the dot are gone, I prefer it this way.
…and now you know how to calculate the Onbalance Volume and you have coded it yourself with a few lines of MQL5 code.


SimpleIOBValue.txt – Downloaded 149 times – 580.00 B