Files
MQL5Data/Experts/test.mq5
T
2025-05-20 21:48:12 +03:30

202 lines
4.3 KiB
Plaintext

//+------------------------------------------------------------------+
//| X121_Strategy_EA.mq5 |
//| Copyright 2023, SaherElm IT |
//| https://saherelm.ir/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "EA based on X121 XCA and X3MA indicators"
#property strict
//
// Include Common Library ...
#include "../Libraries/x-saherelm.common.lib.mq5"
#include "../XCAEA/Helpers/xcaea.helper.mq5"
#include "../XCAEA/Libraries/xcaea.trigger.block.lib.mq5"
//
// Variables ...
XCAEAInputs eaInputs;
XCXCAEAHelper *eaHelper;
XBarTracker eaBarTraker;
//
CArrayObj eaObjects;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//
// Initial Bar Tracker ...
eaBarTraker.Init(
_Symbol,
_Period //
);
//
// Configure XCA ...
eaInputs.Default();
//
// Hide all Visible Buffers ...
eaInputs.Hide();
//
// we Can make Show all requirements here ...
eaInputs.caInputs.showSar = true;
//
eaHelper = new XCXCAEAHelper();
bool isInited = eaHelper.Init(
_Symbol,
_Period,
eaInputs //
);
if (!isInited)
{
return (INIT_FAILED);
}
//
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//
// eaObjects.Clear();
//
eaBarTraker.Clean();
//
delete eaHelper;
ZeroMemory(eaHelper);
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//
// Check Bar Processing ...
if (!eaBarTraker.CanProcessBar())
{
return;
}
//
bool has = false;
//
// Required Chart Identification ...
ulong chartId = eaHelper.poiDrawer.ChartIdentification();
int subWindow = eaHelper.poiDrawer.SubWindowIdentification();
//
// Retrieve Bars ...
XOHCL zBar;
XOHCL cBar;
has = zBar.Init(
_Symbol,
_Period,
0 //
);
has =
has &&
zBar.GetPreviousBar(cBar);
if (!has)
{
//
zBar.Clean();
cBar.Clean();
//
return;
}
//
// Define Trigger Block ...
XTriggerBlock tb;
XCAEATriggerBlockConfiguration tbConfig;
//
// Configure Detector ...
//
// Validation ...
tbConfig.maxAllowedRange = 0.0;
tbConfig.minAllowedBlockEdgeLength = 7;
//
// Validation ...
tbConfig.forceFVGBarType = true;
tbConfig.forceHasSwingBar = true;
tbConfig.forceOBOppositBar = true;
tbConfig.forceHasLiquidity = false;
tbConfig.forceGapBarBreakout = true;
tbConfig.forceHasReversalLiquidity = true;
//
// Filters ...
tbConfig.filterBasedOnSar = true;
tbConfig.filterBasedOnADX = true;
tbConfig.filterBasedOnRSI = true;
tbConfig.filterBasedOnTrend = true;
tbConfig.filterBasedOnScores = true;
tbConfig.filterBasedOnVolumes = true;
//
// Do Detection ...
has = DetectTriggerBlock(
tb,
eaHelper,
tbConfig,
zBar.Index(),
10 //
);
if (has)
{
//
CArrayObj *tObjects;
tObjects = new CArrayObj();
//
has = DrawTriggerBlock(
tb,
tObjects,
eaHelper,
zBar.time //
);
if (has)
{
AddObjects(tObjects, eaObjects);
}
//
Print("Trigger Block Detected ...");
}
tb.Clean();
//
// Do What we Want ...
// When we Need Waits Until Next Bar ...
eaBarTraker.Waits();
//
// Cleanup Resources ...
//
tb.Clean();
zBar.Clean();
cBar.Clean();
tbConfig.Clean();
}