MQL5 TUTORIAL – SIMPLE IFRAMA STANDALONE EXPERT ADVISOR

video
play-sharp-fill

 

Introduction to Simple IFRAMA Standalone Expert Advisor (00:00 – 00:02)

  • Introduction to the tutorial on creating a Standalone Expert Advisor for the Fractal Adaptive Moving Average (IFRAMA) indicator in MQL5.

Overview of IFRAMA Indicator (00:02 – 00:13)

  • Brief explanation of the IFRAMA indicator, represented by the blue line on the chart, and its use in automated trading. The goal is to create an Expert Advisor that opens positions based on this indicator.

Programming the Expert Advisor in MetaEditor (00:13 – 00:28)

  • Instructions on opening MetaEditor in MetaTrader and creating a new Expert Advisor file named ‘SimpleIFRAMAStandaloneEA’. Initial setup and code preparation.

Importing Trade.mqh and Initializing Variables (00:28 – 01:04)

  • Steps to import the ‘Trade.mqh’ file and create an instance of the ‘CTrade’ class. Initializing variables for Ask and Bid prices.

Setting Up Price Array and IFRAMA Definition (01:04 – 02:25)

  • Creating a price array using ‘MqlRates’ and sorting it with ‘ArraySetAsSeries’. Defining the IFRAMA Expert Advisor using the ‘iFrAMA’ function.

Configuring IFRAMA Parameters and Filling Arrays (02:25 – 03:24)

  • Setting up parameters for the IFRAMA indicator and using ‘CopyBuffer’ to fill the FramaArray with data.

Calculating IFRAMA Value and Signal Conditions (03:24 – 04:15)

  • Calculating the IFRAMA value and creating conditions for ‘sell’ and ‘buy’ signals based on its comparison with the high and low prices of the last candle.

Executing Trades Based on Signals (04:15 – 04:50)

  • Executing sell or buy trades using ‘trade.Sell’ or ‘trade.Buy’ based on the calculated signal and the absence of open positions.

Displaying Signal on Chart and Testing (04:50 – 05:29)

  • Using the ‘Comment’ function to display the current signal on the chart. Instructions for compiling the code and testing the Expert Advisor in MetaTrader.

 

In this video we are going to trade this little Indicator; it’s the Fractal Adaptive Moving Average and we are going to create a Standalone Expert Advisor that is actually going to open positions.
Now how can we do that?
First please click on the little button here or press F4 in your Metatrader and now you should see the Metaeditor window and here you want to click on: “File/ New/ Expert Advisor (template)” from template, “Continue”, I will call this version: “SimpleIFRAMAStandaloneEA” click on “Continue”, “Continue” and “Finish”, now we delete everything above the “OnTick” function and the two comment lines here.
So first let’s use the “include” function to import the file: “Trade.mqh”, it comes with a few useful trading functions that we are going to use to open new positions. We use it to create an instance of “CTrade” that will be called: “trade”.
Inside of the “OnTick” function we just need to calculate the Ask price and the Bid price, those are needed to open new positions. We get the Ask price by using “SymbolInfoDouble“ for the current symbol on the chart and with “SYMBOL_ASK” we will get delivered the price we want. For the Bid price we would use “SYMBOL_BID” and “NormalizeDouble” and “_Digits” are used to calculate the number of digits behind the dot, which might be different from one currency pair to another.
We also create string for the signal; please don’t assign a value right now because that is going to be calculated later. Let’s use “MqlRates” to create a price array (myPriceArray), “MqlRates” is a structure that stores the information about prices, volumes and spread.
Let’s sort the array (myPriceArray) downwards by using “ArraySetAsSeries” and fill the array (myPriceArray) with data for 3 candles by using “CopyRates” for the current symbol and the current period. We start from the current candle 0 (zero) and we store the prices for 3 candles in our price array (myPriceArray).
Now we need another array for the Expert Advisor, this one will be called: “FramaArray”, our frama definition (FramaDefinition) can be created by using the internal function: “iFrAMA” that comes with MQL5, it needs a few parameters; the first one is for the current symbol on the chart, the second one for the period, it’s calculated based on 14 candles and if you click on “Insert/ Indicators/ Trend/ Fractal Adaptive Moving Average” you will see that we use 14 candles and we have a shift value of 0 (zero) – that’s what we use here – and the calculation is based on the close price.
We also need to sort this one from the current candle downwards once again by using “ArraySetAsSeries” for our frama array (FramaArray).
Let’s use “CopyBuffer” according to the frama definition (FramaDefinition) that we have created here for the first buffer in the Indicator – that’s the blue line – from the current candle 0 (zero) and we store the values for 3 candles in our frama array (FramaArray) and now we can calculate our frama value (FramaValue) by looking at candle 1 in the frama array (FramaArray) and we want to sell if the frama value (FramaValue) is above the last candle high – so if our frama value (FramaValue) is bigger than the high for candle 1 in our price array (myPriceArray) we assign the word “sell” to our signal.
There is also a buy signal; we want to buy if the frama value (FramaValue) is below the last candle low – so if frama value (FramaValue) is below the low of candle 1 in our price array (myPriceArray) we would assign the word “buy” to our signal.
Here comes the order; if the signal equals sell and “PositionsTotal” is less than 1 – in other words we don’t have any open positions – we use “trade.Sell” to sell 10 micro lot.
In the other case we buy 10 micro lot if the signal equals buy and we have no open positions; in this case we use “trade.Buy” to buy 10 micro lot.
Finally we create a chart output by using the “Comment” function, it will output the text: ”The current signal is:” followed by the “signal” and now if you are ready you can click on the “Compile” button here or press F7, that should work without any errors here and in that case please click here or press F4 to go back to Metatrader.
In Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please pick the file: “SimpleIFRAMAStandaloneEA.ex5”, enable the visualization mode here and start your test.
…and here we are! We have just opened our first sell trade here, this is our first position and in this little video you learned how to output buy and sell signals for the Fractal Adaptive Moving Average and how to automatically open positions in a Standalone Expert Advisor and you have coded it yourself with a few lines of MQL5 code.

Download “MQL5 TUTORIAL - SIMPLE IFRAMA STANDALONE EXPERT ADVISOR”

SimpleIFRAMAStandaloneEA.txt – Downloaded 341 times – 1.83 KB