MQL4 TUTORIAL - SIMPLE STANDALONE EMA STOCHASTICS EXPERT ADVISOR

preview_player
Показать описание

In this video, we are going to create an Expert Advisor that uses both the Exponential Moving Average (EMA) and the Stochastic Oscillator to determine trading signals. Let's see how we can do that.
To start, please click on the little button here or press F4 on your keyboard to open the MetaEditor.
The main function we are using is OnTick(). This function is executed every time a new price quote is received.
Inside the OnTick() function, we first determine our trading signal using the CheckEntryEMA() function. This function checks the relationship between two EMAs to determine if we have a buy or sell signal.
We also determine a filter value using the CheckEntrySTOCHASTIC() function. This function uses the Stochastic Oscillator to filter our signals.
If we have a buy signal from both the EMA and the Stochastic Oscillator, and there are no open orders, we place a buy order using the OrderSend function. We are buying 0.10 micro lots, and we have set a stop loss 1500 points below the Ask price and a take profit 50 points above the Ask price.
Similarly, if we have a sell signal from both the EMA and the Stochastic Oscillator, and there are no open orders, we place a sell order. The stop loss is set 1500 points above the Bid price and the take profit is set 50 points below the Bid price.
We then output our trading signal and filter value directly onto the chart using the Comment function.
Now, let's dive deeper into the CheckEntryEMA() function.
Here, we are calculating two EMAs for the current and previous candles. We are using a 20-period EMA and a 50-period EMA. If the 20-period EMA crosses above the 50-period EMA, we have a buy signal. Conversely, if the 20-period EMA crosses below the 50-period EMA, we have a sell signal.
Next, the CheckEntrySTOCHASTIC() function:
We are using the Stochastic Oscillator to filter our signals. We have set the K period to 5 and the D period to 3. If both the K and D values are below 20 and the K value crosses above the D value, we have a buy signal. If both the K and D values are above 80 and the K value crosses below the D value, we have a sell signal.
Once you've understood the code and made any necessary modifications, press F7 to compile it. If everything is correct, there should be no errors or warnings.
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.
Now, let's test our Expert Advisor. Go back to MetaTrader by pressing F4 or clicking on the icon. In MetaTrader, press Control and R to start the strategy tester. Pick the Expert Advisor we just created, enable the visual mode, and start a strategy test. You should now see the Expert Advisor in action on the chart.
If you're already a Premium course member and have an idea for a video like this one, please send us an email.
In this video, you've learned how to create an Expert Advisor using the EMA and Stochastic Oscillator with just a few lines of MQL4 code.
Thanks for watching, and I will see you in the next video!
Рекомендации по теме