MQL4 BASICS - CREATE YOUR OWN AUTOTRADING EXPERT ADVISORS FOR FREE

Using Built-in Indicators in MQL4

Indicators are vital tools in trading, assisting traders in deciphering market patterns and informing trading decisions. MQL4 provides a vast range of built-in technical indicators, allowing for extensive analysis directly within the MetaTrader 4 platform.

Understanding Built-in Indicators

MQL4's built-in indicators are divided into several categories based on their primary function:

Implementing Built-in Indicators in MQL4

To use a built-in indicator within an MQL4 script or Expert Advisor (EA), you'll typically use the `iIndicatorName` function. Here's an example of how to implement a Simple Moving Average (SMA):


// Define the parameters sperately, if you want to. 

int period = 14;             // Period of SMA

int shift = 0;              // Shift

int applied_price = PRICE_CLOSE; 

// Applied price - You can also use 0 instead of PRICE_CLOSE, or 1 instead of PRICE_OPEN and so on....

// Call the Moving Average Indicator using iMA (Any indicator starts with an "i" then the short form of its name). MetaEditor will automatically start to guess what you are typing and will also show you what values are needed for each indicator...

double SimpleMA = iMA(Symbol(), PERIOD_CURRENT, period, shift, MODE_SMA, applied_price, 0);

// We are using our pre-defined values of "period", "shift" and "applied_price", but you don't have to do that if you don't want to.

// You can alsp use 0 instead of period current, 1 for 1 minute timeframe, 5 for 5 minute, etc...

// You could instead do this:

double SimpleMA = iMA(Symbol(), 0, 25, 0, MODE_SMA, 0, 0);

// If you want your moving average to have customizable options you could also put the "int period" at the very top of your EA as an external option instead, using:

extern int period="25";

// Then you could change the period from the EA properties while testing different periods on the strategy tester and or in live trading...


    

This example demonstrates how to get the value of a 14-period SMA for the current symbol and period.

Advantages of Using Built-in Indicators

Conclusion

Built-in indicators in MQL4 offer traders a powerful toolset for technical analysis without the need for external tools or platforms. By understanding how to implement and interpret these indicators, traders can enhance their algorithmic strategies and make more informed trading decisions.

NEXT UP: Writing Custom Indicators in MQL4