smart trend follower
Info
The smart trend follower is a Expert Advisor for MetaTrader 5 that 1. enum types (enumjnssignal, enumordertype)- enumjnssignalthis enum defines the type of signal used in the ea.
Usage
This tool is typically used for trend following strategies across multiple currency pairs.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use smart trend follower
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
1.
Typical Use Case
This Expert Advisor excels in trend following on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: Steep MA Trend EA - another powerful expert for MetaTrader 5 traders.
1.enum types (enumjnssignal, enumordertype)
-
enumjnssignal
this enum defines the type of signal used in the ea. there are two signal options: - `etypecrossma`: uses the signal of
Also recommended: Super Trend Trading EA - similar expert with strong performance on MetaTrader 5.
cross 2 ma(the crossing of two moving averages). - `etypetrend`: follows the
trend
using moving averages and stochastic. -
enumordertype
this enum defines the type of order: - `ebuy`: a
buy
order. - `esell`: a
sell
order. - `enone`: no order executed. 2.
input parameters
-
inmagicnumber
a unique magic number used to distinguish orders from this ea. -
inlotsize
the initial lot size for each order. -
inmultiply
the multiplier factor used in the lot size strategy. -
injaraklayer
the pip distance between trading positions in the grid/layer strategy. -
inmaperiodfast & inmaperiodslow
the periods for fast and slow moving averages. -
instokperiod, instodperiod, instoslowing
parameters for the stochastic oscillator. -
intakeprofit & instoploss
the settings for take profit and stop loss. 3.
struct datatrades
- this struct is used to store data related to open trading positions, such as the total number of positions (`ttlpos`), the average price of positions (`hargata`, `hargatb`), and the total volume (`ttllot`). 4.
oninit() function
- this function handles the initialization of the ea, including validating input parameters (e.g., ensuring that the fast ma period is smaller than the slow ma period) and creating handles for the ma and stochastic indicators. 5.
ontick() function
- the main function executed every time the price moves (tick). - it calls the function to check for a new signal with
getsignal()
, and if a signal is found,
managetrading()
is used to execute trades. - it also calls
settpsl()
to ensure that take profit and stop loss are always updated. 6.
isnewcandle() function
- this function detects whether a new candle has formed. this is important because the ea checks for signals only on new candle formations. 7.
getsignal() function
- this function determines if a valid trading signal exists based on the selected strategy: - for
etypecrossma
, the signal is determined by the crossing of the fast and slow moving averages. - for
etypetrend
, the signal uses confirmation from ma and stochastic. 8.
managetrading() function
- this function manages the execution of trades. - if a valid signal is detected, the ea opens a position with the lot size determined using the
getlotsize()
function. - a grid/layer strategy is also applied to open additional positions based on the price distance (`injaraklayer`). 9.
updatedatatrades() function
- this function updates the data related to ongoing trading positions, such as calculating the average price and total volume of open positions. 10.
opentrade() function
- this function opens a new trading position based on the generated signal and calculated lot size. it uses
ordersend()
to execute the order. 11.
settpsl() function
- this function sets or updates the
take profit
and
stop loss
for each open position. 12.
modiftpsl() function
- this function modifies the
take profit
and
stop loss
of existing positions if the values differ from what has been previously set. 13.
validatelot() function
- this function ensures that the lot size used is within the allowed minimum and maximum range, as well as in line with the minimum lot step (`glotstep`). 14.
getlotsize() function
- this function calculates the lot size to be used based on the initial lot size and the number of positions already opened, taking into account the multiplier factor (`inmultiply`). this code is designed to capture market trends and manage trading positions automatically using technical signals from moving averages and stochastic.
You may also like: adx trend pullback ea: trend strength and volatility-based trading - excellent alternative for expert users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property description "Educational code - RobotFX www.robotfx.org"
#property description "Educational code - RobotFX www.robotfx.org"
#property description "Educational code - RobotFX www.robotfx.org"
enum enumJnsSignal{
eTypeCrossMA, //Cross 2 MA
eTypeTrend, //Follow Trend
};
.......
⚠ 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.