Working With Indicator Buffers "Haven Market Structure Hl Ll Hl Lh" - Trading Strategies - 5 May 2025 - The New Light Paper
Connect with us

News

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

Published

on

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

[ad_1]

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.

Ad


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:

[ad_2]

Source link

Send Us Your Story

If you would like your article or opinion published on The New Light Paper, one of Uganda’s trusted news platforms, send your submission to thenewlightpaper@gmail.com.

Follow us on Facebook
Subscribe on YouTube
Follow us on Instagram
Follow us on TikTok
Follow us on X
Follow us on LinkedIn
Continue Reading