Skip to content

Pine2Trade Syntax Guide

Welcome to the official Pine2Trade Syntax Guide. This document provides a comprehensive reference for all the rules and commands needed to send trading alerts from any platform to your Pine2Trade Expert Advisor (EA) on MetaTrader 5.

Correctly formatting your alert messages is crucial for ensuring your trading signals are interpreted and executed accurately.

Quick Sample Alert Messages

Here are a few examples of Pine2Trade-compliant alert messages:

  • 123456789,buy,EURUSD,risk=0.01,sl=50
  • 123456789,sell,GBPJPY,sl=100,tp=300,money=250
  • 123456789,buylimit,USDCAD,entry=50,risk=0.02,sl=25
  • 123456789,closelong,BTCUSD,pct=50

Core Alert Message Principles

Alert Message Guidelines

To create Pine2Trade-compliant alert messages, please pay close attention to the following guidelines. Failure to adhere to the syntax may result in your signal being ignored or rejected by the EA.

Test Drive Before Going Live!

Before connecting your live strategy, we strongly recommend sending manual or test alerts. This helps ensure: 1. The alert message you've configured is valid as per this Syntax Guide. 2. Your selected EA Settings on MT5 result in the intended trading behavior (e.g., correct lot sizing).

Components of an Alert Message

Alert messages are made up of distinct components. Here’s what each part means:

Component Remarks
License ID • Your unique identifier, found in the Pine2Trade members' portal.
• Example: 123456789.
Command • The specific action you want the EA to take (e.g., buy, sell, closelong).
• Commands do not use an equals sign (=).
Symbol • The asset or instrument to be traded (e.g., EURUSD, GBPJPY, XAUUSD).
Others • Additional parameters that modify the command, often including values (e.g., risk=0.01, sl=50, comment=MyStrategy1).
• These parameters generally use an equals sign (=).

Structure of an Alert Message

The components in your alert message must follow this specific order:

LicenseID,Command,Symbol,Others

Key Structural Rules:

  • Order: The sequence (License ID, then Command, then Symbol, then any Other parameters) is mandatory.
  • Commas: Components must be separated by commas (,). Spaces are not recommended.
  • Uniqueness: Each alert message can only contain one License ID, one Command, and one Symbol.

EA Input Parameters (MT5 Settings)

Before sending alerts, it's crucial to configure the Pine2Trade EA's settings in your MetaTrader 5 terminal. These inputs define the default behavior and risk controls.

Parameter Description
license Your unique Pine2Trade license key. The EA will not work without a valid license.
RiskPercent The default risk as a percentage of your account balance (e.g., 0.01 for 1%). This is used if AllowRiskOverwrite is false, or if no risk/vol/money parameter is sent with an alert. A stop-loss is required for this calculation.
MaxLots The absolute maximum lot size the EA is allowed to open for a single trade, regardless of other calculations. Acts as a safety cap.
EAMagicNumber A unique number that helps the EA identify and manage its own trades. Do not use the same number for different EAs on your account.
AllowRiskOverwrite true: Allows alert messages to specify the trade size using risk=, vol=, or money=, overriding the default RiskPercent.
false: Ignores risk=, vol=, and money= from alerts and always uses the EA's RiskPercent setting for lot calculation.
OneSideTrading true: Enforces that only one direction (long or short) can be open for a specific symbol at a time. If you send a buy signal while a sell position is open, the EA will automatically close all sell positions on that symbol before opening the new buy.
false: Allows you to have both long and short positions open on the same symbol simultaneously (hedging).

Command & Parameter Reference

1. Common Order Parameters

These parameters define the sizing and key levels of your trade. They are used with all entry commands.

risk=

Specifies the position size as a percentage of your account balance. This parameter is only active if AllowRiskOverwrite is true in the EA settings. * A stop-loss (sl=) is required in the alert message to calculate the lot size. * The value should be in decimal format (e.g., risk=0.01 for 1%, risk=0.005 for 0.5%).

LicenseID,buy,EURUSD,risk=0.01,sl=50

money=

Specifies the amount of account currency to risk on the trade. This parameter is only active if AllowRiskOverwrite is true. * A stop-loss (sl=) is required in the alert message to calculate the lot size. * The EA calculates a lot size such that if the stop-loss is hit, the loss will be approximately this amount.

LicenseID,sell,AUDJPY,money=100,sl=40

vol=

Specifies the position size directly in lots. This parameter is only active if AllowRiskOverwrite is true.

LicenseID,buy,US30,vol=0.5,sl=200

Risk Parameter Priority: When AllowRiskOverwrite is true, the EA uses the first valid risk parameter it finds in this order of priority: 1. risk= (percentage of balance) 2. vol= (fixed lot size) 3. money= (fixed cash amount) If none are found, it falls back to the EA's default RiskPercent setting.

sl=

Sets the stop-loss for an order in pips from the entry price.

LicenseID,buy,EURUSD,risk=0.01,sl=25.5

tp=

Sets the take-profit for an order in pips from the entry price.

LicenseID,sell,GBPUSD,risk=0.01,sl=30,tp=90

comment=

Adds a custom text comment to the order in MetaTrader. This can be used to filter which trades a close command affects.

LicenseID,buy,EURUSD,vol=1,comment=MyStrategy1

2. Market Order Commands

For placing orders that execute immediately at the current market price.

buy

Places a buy (long) order at the current market price. Valid Alternatives (case-insensitive): long, bull

LicenseID,buy,EURUSD,vol=0.1 LicenseID,long,US30,money=500,sl=350,tp=700,comment=NasdaqBreakout

sell

Places a sell (short) order at the current market price. Valid Alternatives (case-insensitive): short, bear

LicenseID,sell,EURUSD,risk=0.01,sl=20 LicenseID,short,XAUUSD,vol=0.05,sl=150,tp=400

3. Pending Order Commands

For placing orders that execute when the price reaches a specified level.

entry=

Specifies the entry price offset in pips for a pending order. This is a required parameter for all pending order commands. * For buylimit and sellstop, this is the number of pips below the current price. * For buystop and selllimit, this is the number of pips above the current price.

LicenseID,buylimit,EURUSD,entry=50,risk=0.01,sl=25

buylimit

Places a buy limit order, below the current market price. entry= is required.

LicenseID,buylimit,USDCHF,entry=30,vol=1,sl=20,tp=100

buystop

Places a buy stop order, above the current market price. entry= is required.

LicenseID,buystop,GBPJPY,entry=20,risk=0.02,sl=40

selllimit

Places a sell limit order, above the current market price. entry= is required.

LicenseID,selllimit,AUDCAD,entry=25,money=150,sl=30,tp=80

sellstop

Places a sell stop order, below the current market price. entry= is required.

LicenseID,sellstop,NZDUSD,entry=15,vol=0.5,sl=20,tp=50

4. Position and Order Management Commands

Commands for closing open positions or cancelling pending orders.

closelong

Closes all open buy positions for the specified symbol. If a comment= is included, it will only close positions with that exact comment.

LicenseID,closelong,EURUSD LicenseID,closelong,US30,comment=MyStrategy1

closeshort

Closes all open sell positions for the specified symbol. Can be filtered by comment=.

LicenseID,closeshort,GBPJPY LicenseID,closeshort,BTCUSD,comment=ScalperV2

closeallof

Closes all open buy and sell positions for the specified symbol. Can be filtered by comment=.

LicenseID,closeallof,EURUSD

forcecloseall

Closes all positions managed by this EA across all symbols. This is a global command and does not use the symbol parameter in the same way.

LicenseID,forcecloseall,any_symbol

pct=

Used with a close command to close a percentage of the position's volume.

LicenseID,closelong,EURUSD,pct=50 // Closes 50% of all long EURUSD positions

vol=

Used with a close command to close a specific volume (in lots) of a position.

LicenseID,closeshort,XAUUSD,vol=0.02 // Closes 0.02 lots of short XAUUSD positions

cancellong

Cancels all pending buy orders (buystop, buylimit) for the specified symbol. Can be filtered by comment=.

LicenseID,cancellong,EURUSD

cancelshort

Cancels all pending sell orders (sellstop, selllimit) for the specified symbol. Can be filtered by comment=.

LicenseID,cancelshort,EURUSD

forcecancelall

Cancels all pending orders managed by this EA across all symbols.

LicenseID,forcecancelall,any_symbol


5. Advanced Stop-Loss Management

These optional parameters are added to entry commands (buy, sell, buylimit, etc.) to enable dynamic stop-loss behaviors. These tasks are managed by the Pine2Trade_Helper.mq5 EA.

Breakeven Parameters (betrigger=, beoffset=)

Automatically moves the stop-loss to breakeven (or a slight profit) once a certain profit is achieved. Both parameters must be included to activate this feature.

  • betrigger=: The number of pips a position must be in profit before the breakeven is triggered.
  • beoffset=: The offset in pips from the entry price where the new stop-loss will be placed. (beoffset=0 for pure breakeven, beoffset=2 to lock in 2 pips of profit).

LicenseID,buy,EURUSD,vol=1,sl=20,betrigger=15,beoffset=2

Interpretation: When the trade is 15 pips in profit, the SL will be moved to 2 pips above the entry price.

Pip Trailing Parameters (trailtrig=, traildist=, trailstep=)

Automatically trails the stop-loss behind the current price to lock in profits as a trade moves in your favor. All three parameters must be included to activate this feature.

  • trailtrig=: The number of pips a trade must gain before the trailing stop is first activated.
  • traildist=: The distance in pips from the current price at which the trailing stop will be maintained.
  • trailstep=: The number of pips the price must move further in a favorable direction before the stop-loss is adjusted again.

LicenseID,sell,GBPJPY,risk=0.01,sl=50,trailtrig=30,traildist=20,trailstep=5

Interpretation: When the trade is 30 pips in profit, the SL is first moved to 20 pips away from the current price. After that, for every 5 pips the trade moves further into profit, the SL is updated to remain 20 pips from the new current price.


6. Sample Combined Syntax

Syntax Interpretation
123456789,buy,AUDUSD,risk=0.01,sl=30 • Enters a long AUDUSD trade.
• Position size is calculated to risk 1% of the account balance.
• Stop-loss is placed 30 pips from entry.
123456789,sell,GBPJPY,sl=50,tp=150,money=250 • Enters a short GBPJPY trade.
• Lot size is calculated to risk approximately $250 (if account currency is USD).
• SL and TP are placed 50 and 150 pips from entry, respectively.
123456789,buylimit,USDCAD,entry=40,vol=0.5,sl=25,tp=80 • Places a buy limit order on USDCAD, 40 pips below the current price.
• Uses a fixed lot size of 0.5.
• Sets a 25-pip SL and 80-pip TP from the pending entry price.
123456789,closelong,ETHUSD,pct=25 • Closes 25% of the total volume of all open long positions on ETHUSD.
123456789,buy,EURUSD,vol=1,sl=20,betrigger=15,beoffset=1 • Opens a long EURUSD position of 1.0 lots with an initial 20-pip SL.
• When the trade is 15 pips in profit, the SL will be moved to 1 pip above the entry price.
123456789,sell,XAUUSD,risk=0.005,sl=100,trailtrig=80,traildist=50,trailstep=10 • Opens a short Gold trade, risking 0.5% of the account balance, with a 100-pip SL.
• When the trade is 80 pips in profit, the trailing stop activates, maintaining a 50-pip distance from the current price and updating every 10 pips of further profit.