https://mql5tutorial.com/?s=awesome
In this video, we are going to create an Expert Advisor that uses the Awesome Oscillator to generate buy and sell signals. Let's see how we can do that.
We begin by starting Metaeditor, which can be done by clicking the little icon or pressing F4. The code starts by including the Trade.mqh file, which allows us to use the trading functions provided by the CTrade class. We create an instance of CTrade named trade to handle our trading operations.
Next, we define a user input variable called SignalValue, set to 0.0001, which will be used to determine the threshold for our buy and sell signals.
The OnTick function is where our main logic resides. First, we calculate the Ask price by retrieving the current ask price for the symbol and normalizing it to the number of digits required. Similarly, we calculate the Bid price by retrieving the current bid price and normalizing it.
We then create a string variable named signal to store our buy or sell signal. An array named PriceInformation is created to hold the price data, and we set it to be sorted from the current candle downwards using ArraySetAsSeries.
Price data is copied into the PriceInformation array using CopyRates, which retrieves data for the current symbol and period, starting from the current candle and going back three candles.
A separate array named PriceArray is defined to store the Awesome Oscillator values. We define the Awesome Oscillator using iAO, which takes the current symbol and period as parameters. The PriceArray is also sorted from the current candle downwards.
We then copy the Awesome Oscillator values into the PriceArray using CopyBuffer, specifying the indicator handle, buffer index, starting position, and number of values to copy. The Awesome Oscillator value for the current candle is calculated and normalized to six decimal places.
If the Awesome Oscillator value is greater than the SignalValue, we set the signal to "buy". Conversely, if the value is less than the negative SignalValue, the signal is set to "sell".
For trading operations, if the signal is "sell" and there are no open positions, we execute a sell order for 0.10 Lots, which is equivalent to 10 Micro Lots, at the Bid price with a take profit set 150 points below the Bid. Similarly, if the signal is "buy" and there are no open positions, we execute a buy order for 0.10 Lots at the Ask price with a take profit set 150 points above the Ask.
Finally, we create a chart output using the Comment function to display the current signal, Awesome Oscillator value, and the buy and sell signal values.
Once the code is complete, we press F7 to compile it. If this was too fast for you or if you don't understand what all the code is doing, you might want to check out the Premium course on our website, or watch one of the basic videos first.
If the compilation is successful, we return to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, select the Expert Advisor we just created, enable visual mode, and start a strategy test. We should then see the Expert Advisor on the chart.
If you are already a Premium course member and have an idea for a video like this one, feel free to send us an email. In this video, we have learned how to create an Expert Advisor using the Awesome Oscillator to generate buy and sell signals with just a few lines of MQL code. Thanks for watching, and I will see you in the next video.
Watch video MQL5 TUTORIAL - Awesome Oscillator explained ( in 4 min) online without registration, duration hours minute second in high quality. This video was added by user MQL5 Tutorial 03 October 2024, don't forget to share it with your friends and acquaintances, it has been viewed on our site 172 once and liked it 8 people.