187 lines
6.6 KiB
Plaintext
187 lines
6.6 KiB
Plaintext
//+------------------------------------------------------------------+
|
|
//| SMC_Indicator.mq5 |
|
|
//| Smart Money Concepts Indicator for MT5 |
|
|
//+------------------------------------------------------------------+
|
|
|
|
#include "../Libraries/x-saherelm.common.lib.mq5";
|
|
|
|
#property indicator_chart_window
|
|
#property indicator_buffers 8
|
|
#property indicator_color1 clrGreen // BOS Up
|
|
#property indicator_color2 clrRed // BOS Down
|
|
#property indicator_color3 clrBlue // Order Block
|
|
#property indicator_color4 clrOrange // FVG
|
|
#property indicator_color5 clrPurple // Liquidity Zones
|
|
#property indicator_color6 clrMagenta // Premium/Discount Levels
|
|
#property indicator_color7 clrYellow // Equal Highs
|
|
#property indicator_color8 clrCyan // Equal Lows
|
|
|
|
// Indicator buffers
|
|
double BosUpBuffer[];
|
|
double BosDownBuffer[];
|
|
double OrderBlockBuffer[];
|
|
double FvgBuffer[];
|
|
double LiquidityBuffer[];
|
|
double PremiumBuffer[];
|
|
double EqualHighBuffer[];
|
|
double EqualLowBuffer[];
|
|
|
|
// Input parameters for customization
|
|
input int swingRange = 2; // Range to detect swing highs/lows
|
|
input int orderBlockLookback = 20; // Bars to look back for order blocks
|
|
input int fvgDepth = 3; // Depth for fair value gaps
|
|
input bool enableAlerts = true; // Enable alerts for SMC signals
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Initialization |
|
|
//+------------------------------------------------------------------+
|
|
int OnInit()
|
|
{
|
|
SetIndexBuffer(0, BosUpBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(1, BosDownBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(2, OrderBlockBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(3, FvgBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(4, LiquidityBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(5, PremiumBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(6, EqualHighBuffer, INDICATOR_DATA);
|
|
SetIndexBuffer(7, EqualLowBuffer, INDICATOR_DATA);
|
|
|
|
IndicatorSetString(INDICATOR_SHORTNAME, "Smart Money Concepts Indicator");
|
|
|
|
return INIT_SUCCEEDED;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Swing High and Low Detection |
|
|
//+------------------------------------------------------------------+
|
|
bool isSwingHigh(int index)
|
|
{
|
|
double high = iHigh(_Symbol, _Period, index);
|
|
for (int i = 1; i <= swingRange; i++)
|
|
{
|
|
if (iHigh(_Symbol, _Period, index + i) >= high || iHigh(_Symbol, _Period, index - i) >= high)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| |
|
|
//+------------------------------------------------------------------+
|
|
bool isSwingLow(int index)
|
|
{
|
|
double low = iLow(_Symbol, _Period, index);
|
|
for (int i = 1; i <= swingRange; i++)
|
|
{
|
|
if (iLow(_Symbol, _Period, index + i) <= low || iLow(_Symbol, _Period, index - i) <= low)
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Detect Order Blocks |
|
|
//+------------------------------------------------------------------+
|
|
void detectOrderBlocks(int rates_total)
|
|
{
|
|
ArrayInitialize(OrderBlockBuffer, 0);
|
|
|
|
for (int i = rates_total - orderBlockLookback - 1; i >= swingRange; i--)
|
|
{
|
|
if (isSwingHigh(i))
|
|
{
|
|
OrderBlockBuffer[i] = iHigh(_Symbol, _Period, i); // Bullish Order Block
|
|
}
|
|
else if (isSwingLow(i))
|
|
{
|
|
OrderBlockBuffer[i] = iLow(_Symbol, _Period, i); // Bearish Order Block
|
|
}
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Detect Fair Value Gaps |
|
|
//+------------------------------------------------------------------+
|
|
void detectFairValueGaps(int rates_total)
|
|
{
|
|
ArrayInitialize(FvgBuffer, 0);
|
|
|
|
for (int i = rates_total - fvgDepth - 1; i >= swingRange; i--)
|
|
{
|
|
if (iHigh(_Symbol, _Period, i) < iLow(_Symbol, _Period, i - fvgDepth))
|
|
{
|
|
FvgBuffer[i] = (iHigh(_Symbol, _Period, i) + iLow(_Symbol, _Period, i - fvgDepth)) / 2.0; // FVG midpoint
|
|
}
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Detect Liquidity Zones |
|
|
//+------------------------------------------------------------------+
|
|
void detectLiquidityZones(int rates_total)
|
|
{
|
|
//
|
|
ArrayInitialize(LiquidityBuffer, 0);
|
|
|
|
//
|
|
double points = GetPoints(_Symbol);
|
|
|
|
//
|
|
for (int i = rates_total - swingRange - 1; i >= swingRange; i--)
|
|
{
|
|
if (isSwingHigh(i))
|
|
{
|
|
LiquidityBuffer[i] = iHigh(_Symbol, _Period, i) + (points * 10); // Above swing high for liquidity pool
|
|
}
|
|
else if (isSwingLow(i))
|
|
{
|
|
LiquidityBuffer[i] = iLow(_Symbol, _Period, i) - (points * 10); // Below swing low for liquidity pool
|
|
}
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Detect Equal Highs and Lows |
|
|
//+------------------------------------------------------------------+
|
|
void detectEqualHighsLows(int rates_total)
|
|
{
|
|
ArrayInitialize(EqualHighBuffer, 0);
|
|
ArrayInitialize(EqualLowBuffer, 0);
|
|
|
|
for (int i = rates_total - swingRange - 1; i >= swingRange; i--)
|
|
{
|
|
if (isSwingHigh(i) && iHigh(_Symbol, _Period, i) == iHigh(_Symbol, _Period, i + swingRange))
|
|
{
|
|
EqualHighBuffer[i] = iHigh(_Symbol, _Period, i);
|
|
}
|
|
else if (isSwingLow(i) && iLow(_Symbol, _Period, i) == iLow(_Symbol, _Period, i + swingRange))
|
|
{
|
|
EqualLowBuffer[i] = iLow(_Symbol, _Period, i);
|
|
}
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Main Calculation Loop |
|
|
//+------------------------------------------------------------------+
|
|
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[])
|
|
{
|
|
|
|
detectOrderBlocks(rates_total);
|
|
detectFairValueGaps(rates_total);
|
|
detectLiquidityZones(rates_total);
|
|
detectEqualHighsLows(rates_total);
|
|
|
|
return rates_total;
|
|
}
|
|
//+------------------------------------------------------------------+
|