//--- Arrow code for consolidation signals (Wingdings font)
#define ARROW_CODE 234 // Wingdings code for downward arrow
//--- Input parameters
input int InpPeriodADX = 14; // Period for ADX
input int InpPeriodATR = 14; // Period for ATR
input int InpPeriodBB = 20; // Period for Bollinger Bands
input double InpBBDeviation = 2.0; // Deviation for Bollinger Bands
input int InpPeriodRSI = 14; // Period for RSI
input int InpThresholdRSI = 10; // RSI Threshold range around 50 for consolidation
input ENUM_TIMEFRAMES InpTimeframe = PERIOD_CURRENT; // Timeframe
'consolidation.mq5' 1
'SetIndexArrow' - undeclared identifier consolidation.mq5 83 4
',' - unexpected token consolidation.mq5 83 19
'3' - some operator expected consolidation.mq5 83 18
')' - unexpected token consolidation.mq5 83 31
'ADXBuffer' - invalid array access consolidation.mq5 190 55
'&' - illegal operation use consolidation.mq5 190 54
'ADXBuffer' - class type expected consolidation.mq5 190 55
'CopyBuffer' - no one of the overloads can be applied to the function call consolidation.mq5 190 7
could be one of 3 function(s) consolidation.mq5 190 7
built-in: int CopyBuffer(int,int,int,int,double&[]) consolidation.mq5 190 7
built-in: int CopyBuffer(int,int,datetime,int,double&[]) consolidation.mq5 190 7
built-in: int CopyBuffer(int,int,datetime,datetime,double&[]) consolidation.mq5 190 7
'ATRBuffer' - invalid array access consolidation.mq5 206 55
'&' - illegal operation use consolidation.mq5 206 54
'ATRBuffer' - class type expected consolidation.mq5 206 55
'CopyBuffer' - no one of the overloads can be applied to the function call consolidation.mq5 206 7
could be one of 3 function(s) consolidation.mq5 206 7
built-in: int CopyBuffer(int,int,int,int,double&[]) consolidation.mq5 206 7
built-in: int CopyBuffer(int,int,datetime,int,double&[]) consolidation.mq5 206 7
built-in: int CopyBuffer(int,int,datetime,datetime,double&[]) consolidation.mq5 206 7
12 errors, 0 warnings 13 1
fix the errors and make it that it will make a rectangle n the chart where there is a consolidation
I have reviewed your code, fixed the compilation errors, and modified it to draw rectangles on the chart where consolidation is detected. Below is the corrected and updated code:
SetIndexArrow Error: Replaced SetIndexArrow(3, ARROW_CODE); and the subsequent PlotIndexSetInteger call with the correct property setting in MQL5. Since we're no longer drawing arrows in the indicator window, these lines were removed.
CopyBuffer Calls: Removed the & symbol before array names in CopyBuffer calls. In MQL5, arrays are already passed by reference, so using & causes an error.
Changed Indicator to Draw on Chart Window:
Updated #property indicator_separate_window to #property indicator_chart_window so the indicator draws on the main chart window.
Removed Unnecessary Indicator Buffers:
Since we're drawing rectangles on the chart, the ConsolidationBuffer and arrow plotting are no longer needed. Adjusted the number of indicator buffers and plots accordingly.
Consolidation Detection and Rectangle Drawing:
Added logic to detect when consolidation starts and ends. When consolidation is detected, the code keeps track of the highest high and lowest low during the period.
When consolidation ends, it creates a rectangle (OBJ_RECTANGLE) on the chart covering the consolidation period's time range and price range.
Set properties for the rectangle (color, style, transparency, etc.) to visually represent consolidation areas on the chart.
Cleanup of Rectangle Objects:
In the OnDeinit function, added code to delete all rectangle objects created by the indicator when it's removed from the chart.
Boundary Checks and Index Handling:
Ensured that array indices are within bounds to prevent runtime errors.
Efficient Looping:
Adjusted the starting point of the loop to start = 0; to ensure all bars are processed, which is necessary for accurate rectangle drawing.
Notes:
Object Naming: Each rectangle is named uniquely using the start time of the consolidation period. This prevents conflicts and ensures that each rectangle represents a specific consolidation period.
Transparency: Adjusted the rectangle's transparency for better visual clarity on the chart.
Indicator Buffers: Although we continue to calculate MPOBuffer, BBUpperBuffer, and BBLowerBuffer, you can remove or modify these if they are no longer needed for your purposes.
Error Handling: Added checks and error messages for potential failures in creating handles and objects.
Please compile and test the above code in MetaEditor to ensure it works as expected on your platform.