passed the control or flow over to this second while loop. The type bool comes from Boole, the last name of the inventor of the logical calculus. More about the Moving Average EA You can install the Moving Average EA on limitless demo and live accounts. There are many advanced forms of directives, such as the #import and #include, but we are just using the simplest of them all, the #property copyright preprocessor directive that identifies the code as ours. A handy quick reference to MA parameters (as well as the parameters to all 20 native indicators) can be found here: m/indicators/iMA For our immediate purposes, we will be working with the default parameter values, and the most important parameter for our purposes is the. Increasing the number of moving averages, as seen in the triple crossover method, is one of the best ways to gauge the strength of a trend and the likelihood that the trend will continue. We are going to indicate the buy crossover condition by watching if previous bar's fast moving average was previously below the slow moving average and now the current bar bar's moving average is above the slow moving average. It is the MAPeriod that drives the bus, because it differentiates the fast from the slow moving average. If set to true, and I am currently in a long position, and a short entry order is triggered, the short entry order closes out my current long before putting on a short trade.
Within the beginning of this start function I have included the following lines: if(Bars 100) Print Bars less than 100 return(0 Translation : If Bars are less than 100, do not trade, and print on the screen that bars are less than 100. Open prices are less accurate but faster than the others. The strategytester has three types of backtest modes in its drop down menu: everytick, control points, and open prices only. Other than that, it is not that important and does nothing fancy.
Moving, average, expert, advisor with 3rd Generation MA!
As you can see in Figure 1, a cross below a moving average can signal the beginning of a downtrend and would likely be used by traders as a signal to close out any existing long positions. Remember, any time you come across specific indentifiers and it is hard to see what part of the code they refer to, there is a fast way to find their matching counterparts. Note While it is easy to type in the double ampersand ( ) for "and it is hard to type the double vertical lines for "or" so a quick short cut for this is just to copy and paste. Vice versa for short. Supplementary moving averages may be added to the chart to increase the strength of a signal. If I had chosen false, that is, decativated the oppositeclose, the short entry signal would not close out my prior long trade, and my long trade would remain open until it was closed by hitting the stoploss or takeprofit. MAPrice The price array to use when calculating the moving average, either close, open, high, low or some type of average. Please read the article about optimization first. Source: MetaStock, now that you have a good grip on basic strategies for moving averages, let's kick it up a notch! It is a simple method of looping in MQL4, similar to the for loop discussed above, but more appropriate if you are unsure of the number of iterations. Here are the buy and sell conditions that I intend to code: Buy Condition1: if 3 period moving average crosses above 30 period moving average, buy at market (also close open sell position Sell Condition1: if 3 period moving average crosses under 30 period moving. Since this checking for openbar is a simple but crucial component for any new system, I have discusses it a bit more in length in its own article.