2 ma crossing
Info
The 2 ma crossing is a Expert Advisor for MetaTrader 4 that we will start creating this ea by defining the input variables. followed by defining global variables.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 4 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL4/Experts folder via File ? Open Data Folder in MetaTrader 4.
How to Install and Use 2 ma crossing
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
we will start creating this ea by defining the input variables.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 4.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 4. Place the file in the MQL4/Experts folder and restart the terminal.
Description & Settings
Related: lock system 2+1 - another powerful expert for MetaTrader 4 traders.
we will start creating this ea by defining the input variables.
followed by defining global variables. variables with this global scope will be known or accessible to all functions.
Also recommended: read news from forex factory website by web request - similar expert with strong performance on MetaTrader 4.
when ea is executed, the first function that is executed is oninit (). so that we often use this function to validate and initialize global variables that will be used.when the market price moves (tick), the ontick () function will be called and execute all instructions / functions contained in this ontick () function block.
inside the ontick () function will call various other functions.
starting to call the checkminequity () function to control the adequacy of trading equity. if the equity funds are sufficient (exceeding the minimum equity), it will be followed by a signal variable declaration and followed by a call to the newcandle () function which functions to inform when a new candle is formed.
the getsignal () function will read the values on both moving average indicators and return signal information whether an upward or downward cross occurs as a signal for a buy / sell signal.
based on this signal information, it will be forwarded to the transaction () function to set open buy or sell positions.
and it will be continued by calling the settpsl () function which functions to set the take profit and stop loss prices.if equity does not meet the minimum equity requirement, an alert will be displayed and this ea will be terminated.
function to settpsl()
if you are looking for an app to support your trading, please download our signalforex app in the play store
You may also like: explosion - excellent alternative for expert users on MetaTrader 4.
Source Code
#property copyright "robotfx"
#property link "https://robotfx.org"
#property version "1.00"
#property strict
input int period_ma_fast = 8; //period fast ma
input int period_ma_slow = 20; //period slow ma
input double takeprofit = 20.0; //take profit (pips)
input double stoploss = 20.0; //stop loss (pips)
input double lotsize = 1.00; //lot size
input double minequity = 100.0; //min. equity ($)
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.