How to attach the Price Range indicator to your trading robot

How to attach the Price Range indicator to your trading robot

12 February 2026, 22:01
Vladimir Toropov
0
110

My client asked how to attach the Price Range indicator to his trading robot. Indeed, this allows the use of different Stop Loss and Take Profit values, as well as a variety of trading logic.

If you're new to this powerful indicator, you can read more about it here: Price Range Indicator - Stay up to date with price movements.

You can also read all about using this indicator effectively here: Trading strategies for the "Price Range MT5" indicator.

Let's get back to attaching this indicator to your trading robot.

The indicator is designed to be developer-friendly and fully supports automation. It outputs signals directly to indicator buffers (INDICATOR_DATA), so you can easily retrieve them using the iCustom() and CopyBuffer() functions in MQL5.

How to attach the Price Range indicator to your trading robot: the buffer mapping for a developer

  • Buffer 0: UP signal (New uptrend). Contains the Low price of the corresponding bar when a signal appears, otherwise EMPTY_VALUE.
  • Buffer 1: DOWN signal (New downtrend). Contains the High price of the corresponding bar when a signal appears, otherwise EMPTY_VALUE.

Additional buffers available for advanced logic:

  • Buffer 2: Resistance Level
  • Buffer 3: Support Level
  • Buffer 4: Stop-Loss for Short
  • Buffer 5: Stop-Loss for Long

All empty values are returned as EMPTY_VALUE.

Here is a brief guide on how to attach the Price Range indicator to your trading robot

1. After purchasing on MQL5 Market, the Price Range indicator is located in the "Market" folder. We'll take this into account when calling the iCustom() function.

2. When receiving the indicator handle via the iCustom() function, specify the exact name of the indicator file (without “.ex5“):

int Handle = iCustom(
	_Symbol,           // Trading symbol
       	_Period,           // Timeframe
      	"Market\\Price Range MT5", // The exact path to the indicator
       	"Market layout:",
      	IN_MinRangeWeight, // Min price range, pivot points (int)
     	IN_MinStrongLevel, // Min price level, price touches (int)
     	"Chart appearance:",
      	IN_DrawRanges,     // Draw price ranges (bool)
       	IN_DrawStrongs,    // Draw price levels (bool)
      	IN_DrawSLs,        // Draw SL levels.   (bool)
      	IN_DrawTrends,     // Show when a new trend begins (bool)
      	"Send notifications when:",
       	IN_NewRange,       // Price range detected   (bool)
      	IN_NewLevel,       // Price level built      (bool)
      	IN_NewTrend,       // New trend started      (bool)
       	IN_AlwaysReport,   // Always report problems (bool)
      	"Preferences:",
      	IN_Lang,           // Notification language  (int)(0 - 11)
     	IN_NewRangeLag,    // Range notification lag (int)
       	IN_NewLevelLag,    // Level notification lag (int)
      	IN_NewTrendLag     // Trend notification lag (int)
       	);

⚠️ IMPORTANT: You should pass ALL parameters. They MUST be listed in the exact order they appear in the indicator's input list.

3. In the case of a buy signal, the buffer contains the current bar's low price. Similarly, in the case of a sell signal, the buffer contains the current bar's high price. Therefore, we need to check whether the number in the buffer is equal to these prices. Since these are double numbers, they cannot be compared exactly; we need to use epsilon.

4. Get prices from the chart. We need the Low and High prices of the same bar from which we took the signal (the first bar):

double barLow  = iLow(_Symbol, _Period, 1);
double barHigh = iHigh(_Symbol, _Period, 1);

5. Set accuracy (epsilon). Let’s use _Point - the size of one point (e.g., 0.00001). We consider numbers equal if the difference between them is less than half a point.

double epsilon = _Point * 0.5;

6. Get data from the first bar (previous closed):

if (CopyBuffer(Handle, 0, 1, 1, bufferBuy) < 0 || CopyBuffer(Handle, 1, 1, 1, bufferSell) < 0) return;

7. Prepare values for checking the signal:

double buyValue  = bufferBuy[0];
double sellValue = bufferSell[0];

8. Check buy (UpTrend). The indicator writes Low[i] to the buffer. Checking:

  • The value is not empty (less than DBL_MAX),
  • The value in the buffer is almost equal to the Low price.
bool isBuySignal = (buyValue < DBL_MAX) && (MathAbs(buyValue - barLow) < epsilon);

9. Check sell (DownTrend). The indicator writes High[i] to the buffer. Checking:

  • The value is not empty (less than DBL_MAX),
  • The value in the buffer is almost equal to the High price.
bool isSellSignal = (sellValue < DBL_MAX) && (MathAbs(sellValue - barHigh) < epsilon);

That’s it!

You can use the Price Range indicator without attaching it to your trading robot

Don't forget that the Price Range indicator has a very convenient, customizable notification system for new trends, support and resistance levels, and price ranges on any trading symbol and timeframe.

The indicator is available here: https://www.mql5.com/en/market/product/133246

Good luck with your trading!

Vladimir Toropov