MQL5 TUTORIAL – SIMPLE CHAIKIN EXPERT ADVISOR

This time we want to create an Expert Advisor for the Chaikin Indicator, it’s an oscillator.
When the blue line here crosses the dotted line from below, that is a buy signal and in the other case if the line crosses from above that’s a sell signal.
Now how can we create an Expert Advisor that is going to calculate the value and to create an output for the signal here on the chart?
To do that please click the little button here or press F4 on your keyboard, and now you should see the Metaeditor window and here you want to click on “File /New /Expert Advisor” from template (template), Continue. I will call this version “Simple Chaikin” (SimpleChaikin). Continue, continue and finish.
Now let’s delete everything above the “OnTick” function and the two comment lines.
Step one is to create a string variable for the signal – we will also call it signal and we do not assign any value because we are going to calculate that later on.
The next step is to create an array for several prices, it will be called: “myPriceArray” and we use the type double, so it can hold floating-point values.
Now we can define the properties of the Chaikin Expert Advisor by using the built-in function called: “iChaikin” for the current symbol on the chart and the period on the chart.
If you wonder why we use a 3 and a 10 – that’s also what you see here – because in the properties of the Chaikin Oscillator you will see a value for the Fast Moving Average and another one for the Slow Moving Average. This one is the 3, here is the 10 and we are going to use the Exponential Moving Average so our next parameter will be MODE_EMA.
In the last parameter we want to use the tick volume, so we use VOLUME_TICK. Now we are going to sort the price array from the current candle downwards, this can be done by using “ArraySetAsSeries” for the price array we have created here (myPriceArray) and with “CopyBuffer” we fill our defined EA for the Chaikin Indicator for one line; that’s buffer zero, from the current candle; that’s candle zero, for 3 candles – that’s the 3 here – and we store the result in our price array.
To get the value of the current candle we assign the value from candle zero of our price array to the variable called: “ChaikinValue” and to get the value of the last candle – so this one is the current candle, that’s candle zero and this would be candle one – so, we get the price information for candle one from our price array and assign it to a variable called: ”PreviousChaikinValue”.
Then when the blue signal line crossed the dotted line here from below – if ChaikinValue for candle zero is above zero now and if the previous ChaikinValue was below zero – that would be a cross over and in that case our signal would be buy, and we would like to sell if it crossed the zero line from above.
So, if the blue line is crossing from above here in MQL5 this would be: if ChaikinValue<0 and the PreviousChaikinValue>0, that would be a sell signal, so we assign it to our variable called: signal.
The last thing we need to do is to create a chart output by using the “Comment” function that will output the text: “ChaikinValue”, followed by the calculated value and in a new line we want to have the text: signal followed by the created signal.
Please don’t forget the closing bracket and when you are done you can click on the compile button here or press F7 and that should work without any errors or warnings, and if that is the case for you, please click here or press F4 to go back to Metatrader.
In Metatrader you want to click on “View/Strategy Tester” or press CTRL and R, and here you want to select the SimpleChaikin.ex5 file. Mark the visualization option here and start a test. And here we are!
Let’s speed it up and you will see that it is going to create buy or sell signals directly on your Forex chart and you have coded it yourself with a few lines of MQL5 code.

Download “MQL5 Tutorial - Simple Chaikin Expert Advisor” SimpleChaikin.txt – Downloaded 75 times – 1 KB