Skip to content

Commands

Signals are sent to the EA via a webhook using a JSON structure similar to the following:

{
  "license": "123456789",
  "type": "signal",
  "signal": "123456789,buy,EURUSD,tp=100,sl=100,comment=123456"
}

When this JSON is received, the EA extracts the signal string and splits it by commas. The first elements correspond to:

  • license: License ID used to validate the request.
  • operation: Trading action such as buy, sell, closelong, closeshort, closeallof, or forcecloseall.
  • symbol: The trading pair or instrument (e.g., EURUSD).
  • tp (optional): Take Profit in pips.
  • sl (required for buy/sell): Stop Loss in pips. It is mandatory to calculate risk and determine the lot size.
  • comment (optional): A note attached to the position. Useful for tracking or grouping trades.

Important Notes

  • sl is required when sending buy or sell commands because it is used to calculate the lot size based on your risk percentage.

  • The comment field is optional, but plays a crucial role when closing trades.
    If you send a close command (like closelong, closeshort, or closeallof) with a comment, the EA will try to close only the position(s) that match both the symbol and the comment.
    If no comment is provided, it will attempt to close all positions opened by the EA for that symbol.

  • Use forcecloseall to immediately close all positions handled by this EA (regardless of symbol or comment).


Understanding sl and tp in Pips

When sending buy or sell commands, both sl (stop loss) and tp (take profit) are defined in pips, not raw price values. Pine2Trade will automatically calculate the correct price level based on the current market price and pip size for the symbol, regardless of the number of decimals.

What is a Pip?

A pip is the 4th digit after the decimal for most forex pairs (e.g., EURUSD = 1.1050 → 1 pip = 0.0001), and the 2nd digit after the decimal for JPY or lower-precision assets (e.g., USDJPY = 110.50 → 1 pip = 0.01).

We handle this automatically using the pip size of the symbol:

pip_size = SymbolInfoDouble(symbol, SYMBOL_POINT) * 10

Example 1: High-precision symbol (e.g., 10.00001)

Let’s say the current Ask price (for a buy) is 10.00001.

  • You send: "sl": 10 and "tp": 10
  • Pip size is 0.0001, so:

Stop Loss (10 pips) = 10.00001 − (10 × 0.0001) = 9.99901
Take Profit (10 pips) = 10.00001 + (10 × 0.0001) = 10.00101

For a short (sell) from the current Bid price 10.00001:

  • SL = 10.00101
  • TP = 9.99901

Example 2: Low-precision symbol (e.g., 1000.01)

Let’s say the current Ask price is 1000.01.

  • You send: "sl": 10 and "tp": 10
  • Pip size is 0.1, so:

Stop Loss (10 pips) = 1000.01 − (10 × 0.1) = 999.01
Take Profit (10 pips) = 1000.01 + (10 × 0.1) = 1001.01

For a short (sell):

  • SL = 1001.01
  • TP = 999.01

No matter what symbol or instrument you are trading, you always provide SL and TP in pips, and the EA handles price conversion internally using the correct pip size.


Using comment to Manage Multiple Strategies

The comment field can be used to tag trades with a strategy name, identifier, or any custom label. This is especially useful when running multiple strategies on the same symbol.

Example Use Case

Let’s say you are running two strategies on EURUSD:

  • A short-term strategy using a 20-period moving average
  • A longer-term strategy using a 90-period moving average

You can send two separate buy signals like this:

{
   ...
  "signal": "123456789,buy,EURUSD,tp=50,sl=30,comment=SMA20"
}
{
    ...
  "signal": "123456789,buy,EURUSD,tp=120,sl=60,comment=SMA90"
}

This will result in two open positions on the same symbol, each tagged with its corresponding strategy name.

Now, if you want to close only the short-term strategy position, you can send:

{
    ...
  "signal": "123456789,closelong,EURUSD,comment=SMA20"
}

This tells the EA to find and close the BUY position on EURUSD that matches the comment SMA20. The position with comment SMA90 remains open.

This allows you to manage multiple strategies independently, even if they trade the same instrument.


Market Execution & Slippage Considerations

All trades opened or closed by the EA are executed at market price, meaning they are not pending or limit orders.

We are currently working on adding support for:

  • Limit and stop order execution
  • Advanced position management during market closures
  • Real-time trade notifications via Telegram
  • And more...

Stay tuned for upcoming updates and feature announcements!

Please keep in mind:

  • Due to market volatility, slippage can occur, especially in fast-moving conditions.
  • Avoid placing SL or TP levels too close to the entry price, as some brokers enforce minimum distance requirements between the current price and stop/limit levels.
  • The EA uses a default deviation of 100 points (equivalent to 10 pips in most pairs) to improve the chances of successful execution.

closeallof: Close All Positions for a Symbol

Use the command closeallof to close all positions on a specific symbol opened by the EA.

Example:

{
    ...
  "signal": "123456789,closeallof,EURUSD"
}

You can optionally include a comment to close only positions that match both the symbol and the comment:

{
    ...
  "signal": "123456789,closeallof,EURUSD,comment=SMA90"
}

Important: - Only positions opened by the EA (matching the magic number) will be considered. - If no matching positions are found, no action will be taken.


forcecloseall: Emergency Close All

Use forcecloseall to close all positions opened by the EA, across all symbols, regardless of comment or instrument.

Example:

{
    ...
  "signal": "123456789,forcecloseall,ANY"
}

Important: - This is an emergency command designed to quickly liquidate all EA-controlled positions. - It does not close positions opened manually or by other EAs (since it filters by magic number).