Files
MQL5Data/Experts/x-saherelm.xpoi.test.ea.mq5
T
2025-03-17 23:02:12 +03:30

378 lines
8.3 KiB
Plaintext

//+------------------------------------------------------------------+
//| x-saherelm.xpoi.test.ea.mq5 |
//| SaherElm IT Center |
//| https://www.saherelm.ir |
//+------------------------------------------------------------------+
#property copyright "SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
//
#include "../Classes/x-saherelm.x-poi.class.mq5"
#include "../Classes/x-saherelm.x-poi.drawer.class.mq5"
#include "../Libraries/x-saherelm.x-poi.extensions.lib.mq5"
#include "../Libraries/x-saherelm.x-poi.state.lib.mq5"
//
#include "../Classes/x-saherelm.x-bar.analyser.class.mq5"
//
// Global Variables ...
//
XCPOIDrawer *mPOIDrawer;
//
XCPOIDetector *mPOIDetector;
XBarTracker mBarTracker;
XCBarAnalyser *mBarAnalyser;
//
bool useDetector = true;
bool useBarAnalyser = false;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//
mPOIDetector = new XCPOIDetector(
_Symbol,
_Period //
);
//
mPOIDrawer = new XCPOIDrawer();
//
mBarAnalyser = new XCBarAnalyser();
//
mBarTracker.Init(
_Symbol,
_Period //
);
//
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//
// ZeroMemory(mPOIDrawer);
// ZeroMemory(mPOIDetector);
ZeroMemory(mBarAnalyser);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//
DetectBarAnalyser();
//
DetectPOIState();
}
//+------------------------------------------------------------------+
//| Custom Functions |
//+------------------------------------------------------------------+
/**
* Detect POI(s) Using Bar Analyser Class ...
*/
void DetectBarAnalyser()
{
//
if (!useBarAnalyser)
{
return;
}
//
if (!mBarTracker.IsNewBar())
{
return;
}
//
XOHCL zBar;
bool isInited = zBar.Init(
_Symbol,
_Period,
0 //
);
if (!isInited)
{
//
zBar.Clean();
return;
}
//
XOHCL cBar;
isInited = zBar.GetPreviousBar(cBar);
if (!isInited)
{
//
zBar.Clean();
cBar.Clean();
return;
}
//
int rootIDX = -1;
XOHCL selectedBar;
ENUM_X_DIRECTION dir;
//
// Check Big Change in Price ...
bool isBigChange = mBarAnalyser.IsSharp(
zBar, // Bar ...
dir, // Change Direction ...
rootIDX, // Change Root IDX ...
X_PRICE_CLOSE, // Price Change Type ...
true, // Force Use Body for Range Calculation ...
1.0 // Range Extend Multiplier ...
);
if (isBigChange)
{
Print("Big Price Change Detected: ", ToString(dir));
}
//
// Check Big Change in Price ...
bool isSpike = mBarAnalyser.IsSpike(
zBar, // Bar ...
dir, // Change Direction ...
rootIDX, // Root Index ...
X_PRICE_CLOSE, // Price Change Type ...
true, // Force Use Body for Range Calculation ...
1.0, // Range Extend Multiplier ...
3 // Same Bars ...
);
if (isSpike)
{
Print("Spike Detected: ", ToString(dir));
}
//
// Check Doji Pattern ...
bool isDoji = mBarAnalyser.IsDoji(
cBar,
dir //
);
if (isDoji)
{
Print(ToString(dir), " Doji Detected ...");
}
//
// Check Hammer Pattern ...
bool isHammer = mBarAnalyser.IsHammer(
cBar,
dir //
);
if (isHammer)
{
Print(ToString(dir), " Hammer Detected ...");
}
//
// Check Engulf Pattern ...
bool isEngulfed = mBarAnalyser.IsEngulfed(
cBar,
dir //
);
if (isEngulfed)
{
Print(ToString(dir), " Engulfed Detected ...");
}
//
// Check Momentum Pattern ...
bool isMomentum = mBarAnalyser.IsMomentum(
cBar,
dir //
);
if (isMomentum)
{
Print(ToString(dir), " Momentum Detected ...");
}
//
// Check Pullback Pattern ...
bool isPullback = mBarAnalyser.IsPullback(
cBar,
dir //
);
if (isMomentum)
{
Print(ToString(dir), " Pullback Detected ...");
}
//
// Check Swing Pattern ...
bool isSwing = mBarAnalyser.IsSwing(
cBar,
dir //
);
if (isSwing)
{
Print(ToString(dir), " Swing Detected ...");
}
//
// Check Swing Pattern ...
bool isRejected = mBarAnalyser.IsRejected(
cBar,
dir //
);
if (isRejected)
{
Print(ToString(dir), " Rejected Detected ...");
}
//
// Check Support ...
bool isSupport = mBarAnalyser.HasSupport(
cBar,
selectedBar //
);
if (isSupport)
{
Print(ToString(dir), " Support Detected ...");
}
//
// Check Resistance ...
bool isResistance = mBarAnalyser.HasResistance(
cBar,
selectedBar //
);
if (isResistance)
{
Print(ToString(dir), " Resistance Detected ...");
}
//
// Check Fair Value Gap ...
XOHCL toBar;
XOHCL fromBar;
bool hasFVG = mBarAnalyser.HasFairValueGap(
zBar,
fromBar,
toBar,
dir,
3 //
);
if (hasFVG)
{
Print(ToString(dir), " FairValueGap Detected ...");
}
//
// Check Order Block ...
bool hasOB = mBarAnalyser.HasOrderBlock(
zBar,
selectedBar,
dir,
true,
true,
true //
);
if (hasOB)
{
Print(ToString(dir), " OrderBlock Detected ...");
}
//
// Cleanup Resources ...
//
zBar.Clean();
cBar.Clean();
}
/**
* Detect POI(s) Using POIDetector Class ...
*/
void DetectPOIState()
{
//
if (!useDetector)
{
return;
}
//
if (!mBarTracker.IsNewBar())
{
return;
}
//
ENUM_XPOI_EVENTS poiEvents[];
XPOIStateEvents poiEventNotifier;
mPOIDetector.Update(
poiEvents,
0 //
);
poiEventNotifier.Init(poiEvents);
//
XPOIState state;
mPOIDetector.GetState(state);
//
bool showBullishPOIs = true;
bool showBearishPOIs = true;
//
XCBaseObject *stateObjects[];
mPOIDrawer.DrawState(
state,
stateObjects,
//
// Bullish ...
showBullishPOIs && true, // SwingLows
showBullishPOIs && true, // DemandZones
showBullishPOIs && true, // SupportZones
showBullishPOIs && true, // BullishSharps
showBullishPOIs && true, // BullishSpikes
showBullishPOIs && true, // BullishPullbacks
showBullishPOIs && true, // BullishMomentums
showBullishPOIs && true, // BullishRejections
showBullishPOIs && false, // BullishOrderBlocks
showBullishPOIs && true, // BullishFairValueGaps
showBullishPOIs && true, // BullishConsolidationZones
//
// Bearish ...
showBearishPOIs && true, // SwingHighs
showBearishPOIs && true, // SupplyZones
showBearishPOIs && true, // ResistanceZones
showBearishPOIs && true, // BearishSharps
showBearishPOIs && true, // BearishSpikes
showBearishPOIs && true, // BearishPullbacks
showBearishPOIs && true, // BearishMomentums
showBearishPOIs && true, // BearishRejections
showBearishPOIs && false, // BearishOrderBlocks
showBearishPOIs && true, // BearishFairValueGaps
showBearishPOIs && true // BearishConsolidationZones
);
//
Clean(poiEvents);
poiEventNotifier.Clean();
}
//
//+------------------------------------------------------------------+