last ...
This commit is contained in:
@@ -0,0 +1,196 @@
|
||||
//+------------------------------------------------------------------+
|
||||
//| HH_LH_LL_HL.mq5 |
|
||||
//| Indicator for detecting HH, LH, LL, HL |
|
||||
//| Created by [Your Name] |
|
||||
//+------------------------------------------------------------------+
|
||||
|
||||
#property copyright "Your Name"
|
||||
#property link "yourwebsite.com"
|
||||
#property version "1.00"
|
||||
#property indicator_chart_window
|
||||
#property indicator_buffers 4
|
||||
#property indicator_plots 4
|
||||
|
||||
//--- Input parameters
|
||||
input int LookbackPeriod = 20; // Number of bars to look back for pattern detection
|
||||
|
||||
//--- Buffer declarations
|
||||
double HH_Buffer[]; // Buffer for Higher Highs
|
||||
double HL_Buffer[]; // Buffer for Higher Lows
|
||||
double LH_Buffer[]; // Buffer for Lower Highs
|
||||
double LL_Buffer[]; // Buffer for Lower Lows
|
||||
|
||||
//--- Plot settings
|
||||
#property indicator_label1 "Higher Highs"
|
||||
#property indicator_type1 DRAW_ARROW
|
||||
#property indicator_color1 clrGreen
|
||||
#property indicator_style1 STYLE_SOLID
|
||||
#property indicator_width1 1
|
||||
|
||||
#property indicator_label2 "Higher Lows"
|
||||
#property indicator_type2 DRAW_ARROW
|
||||
#property indicator_color2 clrBlue
|
||||
#property indicator_style2 STYLE_SOLID
|
||||
#property indicator_width2 1
|
||||
|
||||
#property indicator_label3 "Lower Highs"
|
||||
#property indicator_type3 DRAW_ARROW
|
||||
#property indicator_color3 clrRed
|
||||
#property indicator_style3 STYLE_SOLID
|
||||
#property indicator_width3 1
|
||||
|
||||
#property indicator_label4 "Lower Lows"
|
||||
#property indicator_type4 DRAW_ARROW
|
||||
#property indicator_color4 clrYellow
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
#property indicator_width4 1
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Initialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnInit()
|
||||
{
|
||||
// Set buffer properties
|
||||
SetIndexBuffer(0, HH_Buffer);
|
||||
SetIndexBuffer(1, HL_Buffer);
|
||||
SetIndexBuffer(2, LH_Buffer);
|
||||
SetIndexBuffer(3, LL_Buffer);
|
||||
|
||||
// Clear buffers at each bar
|
||||
ArrayInitialize(HH_Buffer, 0.0);
|
||||
ArrayInitialize(HL_Buffer, 0.0);
|
||||
ArrayInitialize(LH_Buffer, 0.0);
|
||||
ArrayInitialize(LL_Buffer, 0.0);
|
||||
|
||||
return(INIT_SUCCEEDED);
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Deinitialization function |
|
||||
//+------------------------------------------------------------------+
|
||||
void OnDeinit(const int reason)
|
||||
{
|
||||
// Cleanup if necessary
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Calculate function |
|
||||
//+------------------------------------------------------------------+
|
||||
int OnCalculate(const int rates_total,
|
||||
const int prev_calculated,
|
||||
const datetime &time[],
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &low[],
|
||||
const double &close[],
|
||||
const long &tick_volume[],
|
||||
const long &volume[],
|
||||
const int &spread[])
|
||||
{
|
||||
// Start from the last calculated bar
|
||||
int start_bar = MathMax(prev_calculated - 1, 0);
|
||||
|
||||
// Loop through bars
|
||||
for (int i = start_bar; i < rates_total; i++)
|
||||
{
|
||||
// Get current high and low
|
||||
double current_high = high[i];
|
||||
double current_low = low[i];
|
||||
|
||||
// Check for Higher High (HH)
|
||||
if (IsHigherHigh(i, high, LookbackPeriod))
|
||||
{
|
||||
HH_Buffer[i] = current_high;
|
||||
HL_Buffer[i] = 0.0; // Reset other buffers
|
||||
LH_Buffer[i] = 0.0;
|
||||
LL_Buffer[i] = 0.0;
|
||||
}
|
||||
// Check for Higher Low (HL)
|
||||
else if (IsHigherLow(i, low, LookbackPeriod))
|
||||
{
|
||||
HL_Buffer[i] = current_low;
|
||||
HH_Buffer[i] = 0.0;
|
||||
LH_Buffer[i] = 0.0;
|
||||
LL_Buffer[i] = 0.0;
|
||||
}
|
||||
// Check for Lower High (LH)
|
||||
else if (IsLowerHigh(i, high, LookbackPeriod))
|
||||
{
|
||||
LH_Buffer[i] = current_high;
|
||||
HH_Buffer[i] = 0.0;
|
||||
HL_Buffer[i] = 0.0;
|
||||
LL_Buffer[i] = 0.0;
|
||||
}
|
||||
// Check for Lower Low (LL)
|
||||
else if (IsLowerLow(i, low, LookbackPeriod))
|
||||
{
|
||||
LL_Buffer[i] = current_low;
|
||||
HH_Buffer[i] = 0.0;
|
||||
HL_Buffer[i] = 0.0;
|
||||
LH_Buffer[i] = 0.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Reset all buffers if no pattern is detected
|
||||
HH_Buffer[i] = 0.0;
|
||||
HL_Buffer[i] = 0.0;
|
||||
LH_Buffer[i] = 0.0;
|
||||
LL_Buffer[i] = 0.0;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return rates_total;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function to detect Higher High |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsHigherHigh(int index, const double &high[], int lookback)
|
||||
{
|
||||
for (int i = 1; i <= lookback; i++)
|
||||
{
|
||||
if (index - i < 0) continue; // Ensure we don't go out of bounds
|
||||
if (high[index] <= high[index - i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function to detect Higher Low |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsHigherLow(int index, const double &low[], int lookback)
|
||||
{
|
||||
for (int i = 1; i <= lookback; i++)
|
||||
{
|
||||
if (index - i < 0) continue; // Ensure we don't go out of bounds
|
||||
if (low[index] <= low[index - i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function to detect Lower High |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsLowerHigh(int index, const double &high[], int lookback)
|
||||
{
|
||||
for (int i = 1; i <= lookback; i++)
|
||||
{
|
||||
if (index - i < 0) continue; // Ensure we don't go out of bounds
|
||||
if (high[index] >= high[index - i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//+------------------------------------------------------------------+
|
||||
//| Function to detect Lower Low |
|
||||
//+------------------------------------------------------------------+
|
||||
bool IsLowerLow(int index, const double &low[], int lookback)
|
||||
{
|
||||
for (int i = 1; i <= lookback; i++)
|
||||
{
|
||||
if (index - i < 0) continue; // Ensure we don't go out of bounds
|
||||
if (low[index] >= low[index - i]) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user