The JagzFX Trailing Stop PIN (TSP) is a powerful tool for pinTrader and other expert advisors that support signal PINs. TSP monitors the open trades of each symbol and calculates where the trailing stop level will be for a chosen indicator method. When the price reverses and crosses the calculated trailing stop level, TSP will generate a PIN signal that an EA can use to close the trades.

The JagzFX Trailing Stop Visualizer (TSV) indicator is a companion tool for the TSP. Attaching the TSV to a chart will display horizontal lines at the trailing stop levels for that symbol.

Getting to know the TSP and TSV

The image below illustrates a TSP 100 point trailing stop where the price has peaked and reversed. The blue horizontal lines are drawn by the TSV. The average-open price of the trades is shown by the short-dashed line. The average-trail price is shown by the long-dashed line (refer to the technical notes for an explanation of average prices). This trade is in an exit condition since the price has reversed and broken the trail level. The exit signal from the TSP is on PIN 9 as can be seen displayed on the MUX PIN.

A 100 point trailing stop in the exit condition.
100 point trailing stop – example settings
Trailing Stop Visualizer – set to pin 9 (same as the TSP)

Here is another example using a moving average trail. For illustration purposes, a 10-period simple moving average has been drawn on the M30 chart and the TSP settings have been configured to match. When using the indicator-based trailing modes the parameters can be customised (as shown below for the Moving Average (MA) mode).

Trailing Stop PIN – trailing at the 10-period moving average on a 30-minute timeframe
M30 10MA trailing stop – example settings

Technical Notes

The TSP Exit Signal PIN # must be set to the same number as the PIN input on the EA used to close trades. Alternatively, a MUX PIN can be used to aggregate multiple exit signals and, in this case, the TSP must be set to the same number as the input channel on the MUX PIN. Keep in mind that an exit signal is the opposite direction to the open trades, e.g. a sell signal is sent to close buy trades. The EA must be configured to close trades when the exit signal is received. Consult the relevant EA documentation.

The Dashboard Magic # must be set to the magic number used by the EA to open the trades. Since there may be more than one EA trading on the account, the TSP needs the magic number in order to know which trades to work on.

A PIN signal can only be Buy, Sell, or None. Since there is no value for ‘close all’, opposite direction signals signify a close: i.e. a Buy signal instructs the EA to close Sell signals and vice versa. Therefore, TSP processes buy and sell trailing stops separately.

When more than one trade is open, TSP will calculate the trailing stop from the average profit of the trades. This behaviour is by design. E.g. when an EA (such as pinTrader) receives a PIN signal to close buy trades for a symbol with multiple open trades, it will close all the buy trades. Therefore, it makes sense for TSP to treat all buy trades collectively and all sell trades collectively.

TSP stores the trailing stop levels in Metatrader Global Variables based on the symbol’s name, signal PIN and direction of the trade. For example, EURAUDpin9_Buy_TLock stores the trailing price for EURAUD buy trades for signal PIN 9.

Note: As soon as the EA has closed the trades the exit signal and trail levels will disappear. To experiment and study how to trailing stop modes and signals work, turn auto-close turned off in your EA or set TSP to magic number 0 and it will trail trades that you open manually.

Download “JagzFX Trailing Stop PIN”

JagzFX_Trailing_Stop_PIN_v1_18.ex4 – Downloaded 434 times – 30.01 KB

Download “JagzFX Trailing Stop Visualizer”

JagzFX_EAX_Trailing_Stop_Visualizer_v1_02.ex4 – Downloaded 187 times – 9.88 KB

JagzFX Trailing Stop PIN User Guide

This documentation is for version 1.16 of the JagzFX Trailing Stop PIN

Terminal Integration

Terminal integration settings
  • Exit Signal PIN #. Signal PIN channel number used to send the exit signals to the EA, must match the exit signal PIN set on the EA (or MUX PIN if using).
  • Expert Advisor Magic #. Determines which trades to trail based on their magic number. E.g. set this to the magic number used by the EA to open the trades.
  • Keep TSL values on change/unload. TSP uses Metatrader Global Variables to keep track of trailing stop levels. When set to true, the trailing stop levels with be saved and will be reloaded when TSP restarts or is reattached to a chart. When false, the trailing stop levels will be cleared when the TSP removed from the chart or reconfigured and locked values will be lost. The recommended setting is true.

Trailing Stop

Trailing-stop settings
  • Timeframe. Sets the timeframe used for ATR and other indicator calculations.
  • Trailing Stop Calculation Mode. Sets the method used to calculate the price of the trailing stop. There are nine choices.
    • ATR. Trailing stop distance is a ratio of the Average True Range of the specified Timeframe. See Indicator Parameters: ATR Mode.
    • Fractals. Trailing stop distance is based on recent fractals in the specifed Timeframe. There are no other parameters.
    • High/Low of candles. Trailing stop distance is based on recent highs and lows in the Timeframe, highest for sell trades and lowest for buy trades. The number of history candles checked is set in Indicator Parameters: H/L Candle Mode.
    • Moving Average. The trailing stop distance is based on a moving average of the Timeframe. See Indicator Parameters: MA Mode.
    • Parabolic SAR. The trailing stop distance is based on a Parabolic Stop And Reverse of the Timeframe. See Indicator Parameters: PSAR Mode.
    • Points (fixed). The trailing stop distance is set manually in points. The number of points is set in Indicator Parameters: Points Mode.
    • Profit %. The trailing stop distance is calculated from a percentage of the peak profit. The trailing percentage is set in Indicator Parameters: Profit Mode.
    • Ichimoku: Tenkan-Sen. The trailing stop distance is based on the Tenkan-Sen level for the Timeframe. The Tenkan-Sen period is set in Indicator Parameters: Ichimoku Mode.
    • Ichimoku: Kijun-Sen. The trailing stop distance is based on the Kijun-Sen level for the Timeframe. The Kijun-Sen period is set in Indicator Parameters: Ichimoku Mode.
  • Set Initial Stop. When true, a the trail level is set immediately a trade opens and at negative level (similar to a real stoploss). When false, no trail is set until the price has moved sufficiently to lock in a profit.
  • Trail Initial Stop. When true and Set Initial Stop is also true, the trailing stop will commence trailing from the negative level, When false, the trailing stop will remain at the initial level until the price has moved sufficiently to lock in a profit.
  • Offset from calculated price (x.ATR). Adds additional distance to the trail based on a ratio of the ATR of the Timeframe. This can be used to add an additional volatility buffer to the calcutated distance. e.g. if using High/Low of Candles, an Offset of 0.25 would add an extra 0.25 of distance above the high price and below the low price, helping to protect against the trail being taken out by a false reversal.

Breakeven

Breakeven settings
  • Set Breakeven. When true, the trail price will be moved to the Set Stop to level as soon as the price has moved to the At level. When false, the breakeven settings are ingnored.
  • At level (x.ATR). This the the breakeven trigger level and is set as a ratio of the ATR. For example, a setting of 1.0 meand that the price must move 1.0 ATR (100% ATR) into profit before breakeven will be set.
  • Set Stop to (x.ATR). This is the breakeven level that is set when the above level is reached. For example, a setting of 0.05 will set the stop 0.05 ATR (5% ATR) above the open price of the trades (i.e. locking in a small about of profit).

Indicator Parameters

Unless specified, these values are only relevant when the associated mode is selected.

  • Mode Points: Points. Set the trail distance in points. For example, a value of 100 will trail by 100 points.
  • ATR Mode: Period. Sets the ATR period used for ATR mode and also for the Breakeven and Offset ATRs.
  • ATR Mode: Ratio, Sets the trail as a ratio of the ATR. For example, a value of 1.0 will trail the price by 1.0 ATR (100% ATR).
  • H/L Candle Mode: Number of candles. Sets the number of history candles checked to find the high and low prices.
  • PSAR Mode: Step. Sets the step value of the PSAR indicator.
  • PSAR Mode: Maximum. Sets the maximum value of the PSAR indicator.
  • MA Mode: Period. Sets the Period of the Moving Average indicator.
  • MA Mode: Averaging: Sets the Averaging method of thr Moving Average indicator.
  • MA Mode: Applied Price. Sets the price used by the Moving Average indicator.
  • Profit Mode: %. Set the percentage of profit to trail.
  • Ichimoku Mode: Tenkan-sen. Sets the Tenkan-sen period of the Ichimoku indicator.
  • Ichimoku Mode: Kijun-sen. Sets the Kijun-sen period of the Ichimoku indicator.