Skip to content
All library documents

MT5 Script for Market Orders with Stop-Loss and Take-Profit

Article MQL5 code base

Summary

This document describes a MetaTrader 5 script that opens a buy or sell position at the current market price and attaches a stop-loss and take-profit when placing the order. The stop-loss and take-profit distances are specified in pips, and the script also uses a lot size setting.

On its first run, the script takes its lot size, stop-loss, and take-profit values from values defined in the script. Those settings can subsequently be changed through the platform’s global variable settings. The description does not explain how the user chooses between buying and selling, how the pip distances are converted for different instruments, or how order failures are handled. It also provides no performance results or risk analysis, so it describes order-entry functionality rather than a tested trading strategy.

Key ideas

  • The script places a buy or sell market order at the current price in MT5.
  • It sets stop-loss and take-profit levels using distances measured in pips.
  • The initial lot size and exit distances come from values specified in the script.
  • Those values can later be changed through MT5 global variable settings.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.