In this tutorial, we will discuss a basic Moving Average strategy for Metatrader 4. The strategy will determine whether to open a trade based on the position of the current price relative to the Moving Average. Signal Variable Initialization First, we define a string variable named signal. This variable will be used to determine if we have a buy or sell signal. mql4Copy code string signal =""; Calculating the Moving Average The Moving Average provides an average of prices over a specified number of periods. Here, we calculate the Moving Average for the last 20 candles using the iMA function. mql4Copy code double MyMovingAverage = iMA(_Symbol, _Period, 20, 0, MODE_SMA, PRICE_CLOSE, 0); Determining Buy and Sell Signals We compare the Moving Average to the current price. If the Moving Average is below the current price, it indicates a buy signal. If it’s above, it indicates a sell signal. mql4Copy code if (MyMovingAverageClose[0]) { signal="sell"; } Order Execution If the signal is “buy” and there are no open orders, a buy order for 10 Microlot is placed. Similarly, if the signal is “sell”, a sell order is placed. mql4Copy code if (signal=="buy" && OrdersTotal()==0) OrderSend (_Symbol,OP_BUY,0.10,Ask,3,0,Ask+150_Point,NULL,0,0,Green); if (signal=="sell" && OrdersTotal()==0) OrderSend (_Symbol,OP_SELL,0.10,Bid,3,0,Bid-150_Point,NULL,0,0,Red); Chart Output Finally, the current signal is displayed on the chart for clarity. mql4Copy code Comment ("The current signal is: ",signal); That is basically it In this tutorial, we have detailed the creation of a basic Moving Average strategy in MQL4. This strategy uses the Moving Average to determine the position of the current price and decide on trade actions. Testing in a demo environment before live trading is recommended.

Not sure what to do? Click on the automated trading assistant below

  • MQL4-TUTORIAL-PLATIN-SYSTEM-MACD-OSCILLATOR In this video, we want to calculate…
  • MQL4 TUTORIAL BASICS - 81 SIMPLE SMA BUY TRAILING STOP In this video, we are going to create an expert…
  • MQL4 TUTORIAL BASICS - 122 SIMPLE AVERAGE TRUE RANGE BUY… In this video we are going to use the…
  • MQL4 TUTORIAL BASICS - 69 SIMPLE PRICE CORRELATION In this video we are going to create an expert…
  • MQL4 TUTORIAL BASICS - 74 SIMPLE ENVELOPES INDICATOR In this video we are going to create an expert…
  • MQL4 TUTORIAL BASICS - 72 SIMPLE TRIPPLE EMA In this video we are going to create an expert…
  • MQL4 Tutorial - Simple RSI Expert Advisor What you see here on the chart is the RSI…
  • MQL4 TUTORIAL BASICS - 70 SIMPLE BWMFI OSCILLATOR In this video we are going to calculate the Bill…
  • MQL4 TUTORIAL - SIMPLE WPR EXPERT ADVISOR In this video we are going to create an Expert…
  • MQL4 TUTORIAL - 131 STANDALONE EMA MACD EXPERT ADVISOR In this video we are going to create an…

The post MQL4 TUTORIAL – SIMPLE MOVING AVERAGE STRATEGY appeared first on MQL4TUTORIAL.COM.