Introduction
To make use of indicator buffers in your Professional Advisors or just to learn knowledge from indicator buffers, you want to carry out a number of steps:
1. Defining Enter Parameters
You have to decide which enter parameters the indicator has and which of them you wish to modify or use when loading the indicator into your Professional Advisor. In our case, right here is my listing of enter parameters that I exploit within the indicator Haven Market Construction Hl Ll Hl Lh.
We see these values within the Inputs window when loading the indicator onto the chart.
enter group "===== Construction Evaluation ====="; enter int SwingPeriod = 2; enter int HistoryBars = 500; enter bool ShowCHoCH = true; enter group "===== BOS Settings ====="; enter bool UseBodyForBreakout = false; enter int LabelSize_Line = 8; enter shade BOSUpColor = clrRoyalBlue; enter shade BOSDownColor = clrRed; enter int BOSLineWidth = 2; enter ENUM_LINE_STYLE bosStyle = STYLE_SOLID; enter group "===== CHoCH Settings ====="; enter shade CHoCHUpColor = clrDodgerBlue; enter shade CHoCHDownColor = clrFireBrick; enter int CHoCHLineWidth = 2; enter ENUM_LINE_STYLE chchStyle = STYLE_DASH; enter group "===== Label Settings ====="; enter int LabelSize = 10; enter shade HHColor = clrGreen; enter shade HLColor = clrBlue; enter shade LHColor = clrOrange; enter shade LLColor = clrRed; enter group "===== Notification Settings ====="; enter bool EnablePushNotifications = false; enter bool EnableAlerts = false;
2. Creating the Indicator Deal with
Subsequent, you want to create an indicator HANDLE and specify the specified indicator parameters for it (that is how we load into our program a model of the indicator with the right settings), after which we will use it in our code. On this instance, we load all obtainable parameters by way of ICustom. Nonetheless, you may omit them, and the indicator will load with its default settings outlined in its code. Crucial parameters listed here are “SwingPeriod“, “ShowCHoCH” and “UseBodyForBreakout“; all others solely have an effect on the graphical illustration of the indicator.
Observe that in MQL5 it’s essential to go parameters to ICustom precisely as they seem within the indicator code, preserving their order. You can not specify solely UseBodyForBreakout—ICustom will go our parameter to the primary listed parameter within the indicator code (which, oddly sufficient, is “===== Construction Evaluation =====”, as a result of “enter group” counts as a parameter regardless that it ought to solely separate the inputs).
int marketStructureHandle = iCustom( _Symbol, PERIOD_CURRENT, "IndicatorsMarketHaven Market Construction Hl Ll Hl Lh.ex5", "===== Construction Evaluation =====", 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. Utilizing the CopyBuffer Operate
Subsequent, we use CopyBuffer to repeat knowledge from the buffers to be used in our program. Instance:
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[]) comprise the indicator buffer values for the final bars_to_copy candles on the chart (together with empty values when no buffer worth exists for a given candle). That is essential to precisely know which candle and when a particular indicator sign occurred.
5. Printing Knowledge or Additional Use in Your Logic
Now, merely print the values of our arrays together with the corresponding date and time.
for (int i = 0; i < bars_to_copy; i++) BOS UP = ", DoubleToString(BOS_UP_Buffer[i], _Digits)); if (BOS_DOWN_Buffer[i] != EMPTY_VALUE) Print(time_str, "
Conclusion
After acquiring the indicator buffer values in your Professional Advisor, you should utilize them in your advisor’s buying and selling logic.
For a extra detailed article on methods to use indicator buffers in your Professional Advisors: MQL5 for Newbies: Information to Utilizing Technical Indicators in Professional Advisors
🔵 My different merchandise: https://www.mql5.com/en/customers/maks19900/vendor
🔵Telegram Channel: https://t.me/maks_haven
The script file from the instance: