video

In this video nosotros are going to create an skilful counselor that is able to modify the groundwork color based on purchase and sell signals, and then permit's find out how to do that with mql5.
To get started please click on the footling icon here or press F4 on your keyboard, at present you should see the Metaeditor window and here you want to click on file, new file, practiced advisor from template, go along, I will call this file simple background color, click on continue, continue and finish.
At present y'all can delete everything above the ontick function and the two comment lines here, first we need to get the ask price, this is washed past using symbol info double, for the current symbol on the nautical chart we utilise symbol underscore ask and with normalize double and underscore digits we brand sure that the number of digits behind the dot is automatically calculated that could be either three or five digits depending on the currency pair.
At present we repeat the process using symbol underscore bid this time to calculate the bid price and we also need to create a cord, this will be called indicate and we don't assign a value here because we are going to calculate that at present.
Our good counselor is going to use a moving average, so the first affair to do is to create a moving average array, this is going to concur our values and nosotros utilise the included ima role that comes with mql5 to create a moving average for the current symbol on the nautical chart and the currently selected menstruum.
Our moving average is going to calculate the values based on the last twenty candles, we commencement with the current candle, the method should be manner underscore sma for simple moving average and we calculate the values based on the close price.
Afterwards, nosotros utilise assortment gear up equally series to sort the array from the current candle downwards and with copy buffer we fill our moving average assortment according to the definition that we have created hither, for one line, we start with candle zero that's the electric current candle and nosotros copy the values for three candles and later on, nosotros can get the moving boilerplate value by just looking into candle zero of our moving average array.
And if that value is below the bid price nosotros consider that to be a buy signal so we assign the word buy to our bespeak and for a buy betoken nosotros are going to call a role chosen, gear up chart color groundwork and set the color to green.
In the other case if the value for the moving average is to a higher place the ask price we consider that to be a sell point so now we assign the discussion sell to our signal and we call the groundwork color function and set up the groundwork color to red.
Let's add a third condition, if the value for m a moving boilerplate is below the ask price and in a higher place the bid cost that would hateful that we accept no betoken then we fix the value for our signal to none and in that case we would like to call the custom function and ready the background to black.
Well, if you mark that and printing F1 you will see that there are lots of other colors that you could choose but this function doesn't exist so far and then nosotros need to create it in a few seconds, allow'due south add a chart output by using the comment statement and that will show united states the text, the current signal is and the calculated bespeak directly on our chart.
Now let's create the custom function, it doesn't return a value so we utilize void here, the name of the function is set chart color background and it takes a parameter, this ane is of the type color, I have called it groundwork color but you tin can call it whatever yous like and inside that function, we are going to use chart gear up integer for the current symbol on the chart, we want to gear up the color so nosotros use nautical chart underscore color underscore background – all in capital messages – and the last parameter here is the background color that nosotros take passed here.
And that'southward about it.
Well, if this was likewise fast for you or if you don't sympathise what all the code here does maybe you want to sentry one of the other bones videos offset or maybe the premium form on our website might be interesting for you. This again was an idea of a premium course fellow member, and if yous are a premium course member and have an idea for such a video please send me an email. For at present, we click on the compile button or press F7, you shouldn't get any errors hither and if this is the case y'all can click on a fiddling button here or press F4 to become back to Metatrader.
And inside of Metatrader, we click on view, strategy tester or press control and r, please pick the new file, simple background colour dot ex5, enable the visual mode here and start a test.
This is how it looks similar. Currently, nosotros have a sell signal and when information technology changes to buy we encounter that the background color too changes and in this piffling video you have learned how to create an expert counselor that is able to change the groundwork color based on buy and sell signals and you have coded it yourself with a few lines of mql5 code.