Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Simple Continuous Trend Following Strategy Based on Predefined Conditions - MetaTrader 4 Expert - MT4/MT5 Resource

author EAcpu | 6 reads | 0 comments |

Simple continuous trend-following strategy for buying and selling based on predefined conditions - expert for MetaTrader 4

Simple continuous trend-following strategy for buying and selling based on predefined conditions - expert for MetaTrader 4

Simple continuous trend-following strategy for buying and selling based on predefined conditions - expert for MetaTrader 4

Simple continuous trend-following strategy for buying and selling based on predefined conditions - expert for MetaTrader 4

This MetaTrader 4 (MT4) script implements a simple continuous trend following strategy for buying and selling based on predefined conditions. Here is a detailed description of the script:

Initialization : The script initializes and prints a message if initialization is successful.

Deinitialize : The script deinitializes and prints a message when deinitialized.

Tick ​​function : This function is executed every time there is a new price movement (price change) in the market.

one. Reset Position Tracking Variables : The script resets variables tracking open buy and sell positions.

b. Check open orders : It loops through all open orders to determine if there are any existing buy or sell positions.

c. Open a buy position : If there is no open buy position and the "OpenBuyPosition" flag is set to true, it will try to open a position based on the current market buy price. It sets stop loss and take profit for buy orders.

d. Open a sell position : If there is no open sell position and the "OpenSellPosition" flag is set to true, it will try to open a position based on the current market ask price. It sets stop loss and take profit for sell orders.

e. Check for closed orders : It checks if there are any closed orders. If a buy or sell order is closed with a profit, the corresponding position flag is reset.

Input parameters : The script provides input parameters for lot size, stop loss, take profit and flags to control whether to open a buy or sell position.

Disclaimer : This script contains a warning advising users to use it at their own risk and exonerating the creator from any liability for potential damage or loss.

Overall, the script is designed to automate the process of executing buy and sell orders based on a continuous trend following strategy, allowing users to customize parameters such as lot size and trade direction. However, users should exercise caution and conduct thorough testing before deploying it into a live trading environment.


Attachment download

📎 open_a_buy_position_if_therejs_no_open_position.mq4 (5.74 KB)

Source: MQL5 #41679

Verification code Refresh