Gehen Sie mit der App Player FM offline!
MQL5 TUTORIAL – SIMPLE AWESOME STANDALONE EXPERT ADVISOR
Manage episode 408595723 series 1376757
This time we are going to create a standalone Expert Advisor to trade the Awesome Oscillator, it will output buy and sell signals directly on the chart and whenever the line is crossed here we either get a sell signal when it’s below the dotted line or we would get a buy signal as soon as it crosses the line like right now the bars are above and now we consider that to be a buy signal.
Now how can we create an Expert Advisor in MQL5 that is able to not only output the signals on the chart but to automatically trade them?
To do that please click on the little icon here or press F4 on your keyboard 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 file: “SimpleAwesomeStandaloneEA”, click on “Continue”, “Continue” and “Finish”.
Now you can delete everything above the “OnTick” function and the two comment lines here.
We start by including the file “Trade.mqh”, this one comes with MQL5 and it makes it possible to create an instance from the class “CTrade” that will be called: “trade” and we are going to use it to open positions later on. Before we do that we calculate the Ask price and the Bid price that is done by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price and “SYMBOL_BID” will give us the Bid price.
With “NormalizeDouble” and “_Digits” we automatically calculate the right number of digits because the current currency pair has 5 digits behind the dot but there are also other currency pairs with 3 digits behind the dot.
Now we need a signal variable that will be a string variable so it can contain text later on right now we don’t assign any values because we need to calculate them later on.
With “MqlRates” we create a price information array (PriceInformation), that function here stores the information about the prices, the volumes and the spread.
Now we sort the array from the current candle downwards by using “ArraySetAsSeries” and with “CopyRates” we fill it for the current symbol and the currently selected period on the chart from candle 0 (zero) for 3 candles and we store the data in our price information array (PriceInformation).
Let’s create another array called: “PriceArray” that one will hold the data for our Oscillator, so let’s use the integrated “iAO” function of MQL5 to define the Awesome Oscillator Indicator for the current symbol and the current period on the chart. This array (PriceArray) also needs to be sorted from the current candle downwards so we use “ArraySetAsSeries” for this one and now we use “CopyBuffer” to fill our price array (PriceArray) for the first buffer – that’s the line here – from the current candle 0 (zero) for 3 candles and store the information for the Expert Advisor in our price array (PriceArray).
And to calculate the Expert Advisor for the current candle we simply look at the value of candle 0 (zero) in our price array (PriceArray), we also use “NormalizeDouble” and a 6 to get six digits behind the dot like here and the result will be stored in the Awesome Oscillator value (AwesomeOscillatorValue) and if that value is above 0 (zero) we consider that to be a buy signal and now we assign the word: “buy” to our signal.
Otherwise if the value (AwesomeOscillatorValue) is below 0 (zero), so if the Awesome Oscillator value (AwesomeOscillatorValue) is less than 0 (zero) we assign the word: “sell” to our signal and if the signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open position – we use “trade.Sell” to sell 10 micro lot.
Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot.
The last thing is to create a chart output by using the “Comment” function to output the text: “The current signal is:” and the calculated “signal” directly on our chart.
Okay, if you’re done you can click on the “Compile” button here or press F7, that should work without any errors and in that case you can click on the little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please select the new file: “SimpleAwesomeStandaloneEA”, let’s also mark the visualization option here and start a test.
…and here we are, our Expert Advisor is working, actually we have opened the first automated trade and now you know how to code the Awesome Oscillator Standalone Expert Advisor and you have coded it yourself with a few lines of MQL5 code.
The post MQL5 TUTORIAL – SIMPLE AWESOME STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
27 Episoden
Manage episode 408595723 series 1376757
This time we are going to create a standalone Expert Advisor to trade the Awesome Oscillator, it will output buy and sell signals directly on the chart and whenever the line is crossed here we either get a sell signal when it’s below the dotted line or we would get a buy signal as soon as it crosses the line like right now the bars are above and now we consider that to be a buy signal.
Now how can we create an Expert Advisor in MQL5 that is able to not only output the signals on the chart but to automatically trade them?
To do that please click on the little icon here or press F4 on your keyboard 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 file: “SimpleAwesomeStandaloneEA”, click on “Continue”, “Continue” and “Finish”.
Now you can delete everything above the “OnTick” function and the two comment lines here.
We start by including the file “Trade.mqh”, this one comes with MQL5 and it makes it possible to create an instance from the class “CTrade” that will be called: “trade” and we are going to use it to open positions later on. Before we do that we calculate the Ask price and the Bid price that is done by using “SymbolInfoDouble” for the current symbol on the chart, “SYMBOL_ASK” will give us the Ask price and “SYMBOL_BID” will give us the Bid price.
With “NormalizeDouble” and “_Digits” we automatically calculate the right number of digits because the current currency pair has 5 digits behind the dot but there are also other currency pairs with 3 digits behind the dot.
Now we need a signal variable that will be a string variable so it can contain text later on right now we don’t assign any values because we need to calculate them later on.
With “MqlRates” we create a price information array (PriceInformation), that function here stores the information about the prices, the volumes and the spread.
Now we sort the array from the current candle downwards by using “ArraySetAsSeries” and with “CopyRates” we fill it for the current symbol and the currently selected period on the chart from candle 0 (zero) for 3 candles and we store the data in our price information array (PriceInformation).
Let’s create another array called: “PriceArray” that one will hold the data for our Oscillator, so let’s use the integrated “iAO” function of MQL5 to define the Awesome Oscillator Indicator for the current symbol and the current period on the chart. This array (PriceArray) also needs to be sorted from the current candle downwards so we use “ArraySetAsSeries” for this one and now we use “CopyBuffer” to fill our price array (PriceArray) for the first buffer – that’s the line here – from the current candle 0 (zero) for 3 candles and store the information for the Expert Advisor in our price array (PriceArray).
And to calculate the Expert Advisor for the current candle we simply look at the value of candle 0 (zero) in our price array (PriceArray), we also use “NormalizeDouble” and a 6 to get six digits behind the dot like here and the result will be stored in the Awesome Oscillator value (AwesomeOscillatorValue) and if that value is above 0 (zero) we consider that to be a buy signal and now we assign the word: “buy” to our signal.
Otherwise if the value (AwesomeOscillatorValue) is below 0 (zero), so if the Awesome Oscillator value (AwesomeOscillatorValue) is less than 0 (zero) we assign the word: “sell” to our signal and if the signal equals sell and “PositionsTotal” is below 1 – in other words we don’t have any open position – we use “trade.Sell” to sell 10 micro lot.
Otherwise if the signal equals buy and we have no open positions we use “trade.Buy” to buy 10 micro lot.
The last thing is to create a chart output by using the “Comment” function to output the text: “The current signal is:” and the calculated “signal” directly on our chart.
Okay, if you’re done you can click on the “Compile” button here or press F7, that should work without any errors and in that case you can click on the little button here or press F4 to go back to Metatrader and in Metatrader we click on: “View/ Strategy Tester” or press CTRL and R, please select the new file: “SimpleAwesomeStandaloneEA”, let’s also mark the visualization option here and start a test.
…and here we are, our Expert Advisor is working, actually we have opened the first automated trade and now you know how to code the Awesome Oscillator Standalone Expert Advisor and you have coded it yourself with a few lines of MQL5 code.
The post MQL5 TUTORIAL – SIMPLE AWESOME STANDALONE EXPERT ADVISOR appeared first on MQL5 Tutorial.
27 Episoden
All episodes
×Willkommen auf Player FM!
Player FM scannt gerade das Web nach Podcasts mit hoher Qualität, die du genießen kannst. Es ist die beste Podcast-App und funktioniert auf Android, iPhone und im Web. Melde dich an, um Abos geräteübergreifend zu synchronisieren.