MQL5 TUTORIAL - IOSMA Oscillator explained (in 4 min)

MQL5 Tutorial
MQL5 Tutorial
98 بار بازدید - ماه قبل -
https://mql5tutorial.com/?s=iosma

In this video, we are going to create an Expert Advisor that uses the Moving Average of Oscillator (OsMA) to generate buy and sell signals. Let's see how we can do that.

We start Metaeditor by clicking the little icon or pressing F4.

First, we include the Trade.mqh library, which provides trading functions. We create an instance of the CTrade class to handle trading operations.

Inside the OnTick function, we calculate the Ask price using the SymbolInfoDouble function with the SYMBOL_ASK parameter and normalize it to the number of digits specified by _Digits. Similarly, we calculate the Bid price using the SYMBOL_BID parameter.

We create a string variable named signal to store the trading signal. We also create an array named myIOSMAArray to hold the OsMA values. The ArraySetAsSeries function is used to sort the array from the current candle downwards.

We define the properties for the OsMA indicator using the iOsMA function, specifying the symbol, period, fast EMA period (12), slow EMA period (26), signal SMA period (9), and the price type (PRICE_CLOSE). We then copy the OsMA values for the current and the last two candles into the myIOSMAArray using the CopyBuffer function.

Next, we calculate the current OsMA value by accessing the first element of myIOSMAArray and the last OsMA value by accessing the second element of the array.

We check if the current OsMA value has crossed the zero line from above, indicating a sell signal, and set the signal variable to "sell". Similarly, if the current OsMA value has crossed the zero line from below, indicating a buy signal, we set the signal variable to "buy".

If the signal is "sell" and there are no open positions, we execute a sell order for 0.10 lots (10 micro lots) using the trade.Sell function. The parameters include the lot size, symbol (NULL), Bid price, take profit (Bid + 300 points), stop loss (Bid - 250 points), and a comment (NULL).

If the signal is "buy" and there are no open positions, we execute a buy order for 0.10 lots (10 micro lots) using the trade.Buy function. The parameters include the lot size, symbol (NULL), Ask price, take profit (Ask - 300 points), stop loss (Ask + 250 points), and a comment (NULL).

Finally, we output the current signal to the chart using the Comment function.

To compile the code, press F7. If this was too fast for you or if you don't understand what all the code is doing, you may want to check out the Premium course on our website or watch one of the basic videos first.

If the compilation is successful, we go back to MetaTrader by pressing F4 or clicking on the icon. Back in MetaTrader, we press Control and R to start the strategy tester, pick the Expert Advisor that we have just created, enable the visual mode, and start a strategy test. We should 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, you can send us an email.

In this video, we have learned how to create an Expert Advisor that uses the OsMA indicator to generate buy and sell signals. With just a few lines of MQL code, we have coded an Expert Advisor that can trade based on these signals.

Thanks for watching, and I will see you in the next video.
ماه قبل در تاریخ 1403/04/27 منتشر شده است.
98 بـار بازدید شده
... بیشتر