Connect with us

News

Working with indicator buffers “Haven Market Structure Hl Ll Hl Lh” – Trading Strategies – 5 May 2025

Avatar photo

Published

on

Working with indicator buffers “Haven Market Structure Hl Ll Hl Lh” – Trading Strategies – 5 May 2025


Introduction

To use indicator buffers in your Expert Advisors or simply to read data from indicator buffers, you need to perform several steps:

1. Defining Input Parameters

You need to determine which input parameters the indicator has and which ones you want to modify or use when loading the indicator into your Expert Advisor. In our case, here is my list of input parameters that I use in the indicator Haven Market Structure Hl Ll Hl Lh.

We see these values in the Inputs window when loading the indicator onto the chart.



input group "===== Structure Analysis =====";
input int   SwingPeriod = 2;
input int   HistoryBars = 500;
input bool  ShowCHoCH    = true;

input group "===== BOS Settings =====";
input bool  UseBodyForBreakout = false;
input int   LabelSize_Line     = 8;
input color BOSUpColor         = clrRoyalBlue;
input color BOSDownColor       = clrRed;
input int   BOSLineWidth       = 2;
input ENUM_LINE_STYLE bosStyle = STYLE_SOLID;

input group "===== CHoCH Settings =====";
input color CHoCHUpColor       = clrDodgerBlue;
input color CHoCHDownColor     = clrFireBrick;
input int   CHoCHLineWidth     = 2;
input ENUM_LINE_STYLE chchStyle = STYLE_DASH;

input group "===== Label Settings =====";
input int   LabelSize          = 10;
input color HHColor            = clrGreen;
input color HLColor            = clrBlue;
input color LHColor            = clrOrange;
input color LLColor            = clrRed;

input group "===== Notification Settings =====";
input bool EnablePushNotifications = false;
input bool EnableAlerts            = false;

2. Creating the Indicator Handle

Next, you need to create an indicator HANDLE and specify the desired indicator parameters for it (this is how we load into our program a version of the indicator with the correct settings), and then we can use it in our code. In this example, we load all available parameters via ICustom. However, you can omit them, and the indicator will load with its default settings defined in its code. The most important parameters here are “SwingPeriod“, “ShowCHoCH” and “UseBodyForBreakout“; all others only affect the graphical representation of the indicator.
Note that in MQL5 you must pass parameters to ICustom exactly as they appear in the indicator code, preserving their order. You cannot specify only UseBodyForBreakout—ICustom will pass our parameter to the first listed parameter in the indicator code (which, oddly enough, is “===== Structure Analysis =====”, because “input group” counts as a parameter even though it should only separate the inputs).

int marketStructureHandle = iCustom(
                               _Symbol, PERIOD_CURRENT,
                               "\Indicators\Market\Haven Market Structure Hl Ll Hl Lh.ex5", 
                               "===== Structure Analysis =====", 
                               SwingPeriod,
                               HistoryBars,
                               ShowCHoCH,
                               "===== BOS Settings =====",
                               UseBodyForBreakout,
                               LabelSize_Line,
                               BOSUpColor,
                               BOSDownColor,
                               BOSLineWidth,
                               bosStyle,
                               "===== CHoCH Settings =====",
                               CHoCHUpColor,
                               CHoCHDownColor,
                               CHoCHLineWidth,
                               chchStyle,
                               "===== Label Settings =====",
                               LabelSize,
                               HHColor,
                               HLColor,
                               LHColor,
                               LLColor,
                               "===== Notification Settings =====",
                               EnablePushNotifications,
                               EnableAlerts);

3. Using the CopyBuffer Function

Next, we use CopyBuffer to copy data from the buffers for use in our program. Example:

int bars_to_copy = 100;

CopyBuffer(marketStructureHandle, 0, 0, bars_to_copy, HH_Buffer);
CopyBuffer(marketStructureHandle, 1, 0, bars_to_copy, LL_Buffer);
CopyBuffer(marketStructureHandle, 2, 0, bars_to_copy, HL_Buffer);
CopyBuffer(marketStructureHandle, 3, 0, bars_to_copy, LH_Buffer);
CopyBuffer(marketStructureHandle, 4, 0, bars_to_copy, BOS_UP_Buffer);
CopyBuffer(marketStructureHandle, 5, 0, bars_to_copy, BOS_DOWN_Buffer);
CopyBuffer(marketStructureHandle, 6, 0, bars_to_copy, CHoCH_UP_Buffer);
CopyBuffer(marketStructureHandle, 7, 0, bars_to_copy, CHoCH_DOWN_Buffer);

Now, our arrays (HH_Buffer[], LL_Buffer[], HL_Buffer[], LH_Buffer[], BOS_UP_Buffer[], BOS_DOWN_Buffer[], CHoCH_UP_Buffer[], CHoCH_DOWN_Buffer[]) contain the indicator buffer values for the last bars_to_copy candles on the chart (including empty values when no buffer value exists for a given candle). This is necessary to accurately know which candle and when a specific indicator signal occurred.

5. Printing Data or Further Use in Your Logic

Now, simply print the values of our arrays along with the corresponding date and time.


for (int i = 0; i string time_str = TimeToString(times[i], TIME_DATE | TIME_MINUTES);

   if (HH_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | HH = ", DoubleToString(HH_Buffer[i], _Digits));
   if (LL_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | LL = ", DoubleToString(LL_Buffer[i], _Digits));
   if (HL_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | HL = ", DoubleToString(HL_Buffer[i], _Digits));
   if (LH_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | LH = ", DoubleToString(LH_Buffer[i], _Digits));
   if (BOS_UP_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | BOS UP = ", DoubleToString(BOS_UP_Buffer[i], _Digits));
   if (BOS_DOWN_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | BOS DOWN = ", DoubleToString(BOS_DOWN_Buffer[i], _Digits));
   if (CHoCH_UP_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | CHoCH UP = ", DoubleToString(CHoCH_UP_Buffer[i], _Digits));
   if (CHoCH_DOWN_Buffer[i] != EMPTY_VALUE)
      Print(time_str, " | CHoCH DOWN = ", DoubleToString(CHoCH_DOWN_Buffer[i], _Digits));
}


Conclusion

After obtaining the indicator buffer values in your Expert Advisor, you can use them in your advisor’s trading logic.

For a more detailed article on how to use indicator buffers in your Expert Advisors: MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors

🔵 My other products: https://www.mql5.com/en/users/maks19900/seller

🔵Telegram Channel: https://t.me/maks_haven

The script file from the example:



Source link

Continue Reading

Copyright © 2023 The New Light Paper, Uganda. A Subsidiary of KOOM Media Group Ltd.