Files
MQL5Data/Experts/x-test.ea.mq5
T

634 lines
13 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center XTest MQL5 Expert Advisor
// -------------------------------------------------
// Name: XTestEA
// Description: an Exper Advisor which used XTestSetup
// to Analyse Market ...
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////x
//
// Global Properties ...
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm XTestEA"
#property strict
//
#define ShortName "XTestEA"
//
// Imports ...
#include "../Test/x-saherelm.test.xea.mq5"
#include "../Libraries/x-saherelm.tools.mq5"
#include "../Helpers/x-saherelm.xct.helper.mq5"
#include "../Helpers/x-saherelm.xcc.helper.mq5"
//
// Inputs ...
long mMagicNumber = 78692110; // Magic Number
int mSlippage = 10; // Slippgae
//
double eaVolume = 0.01;
double eaAllowLong = true;
double eaAllowShort = true;
//
// Variables ...
XBarTracker eaBarTracker;
//
XSCXTestSetupEA *mSetupEA;
XSCXTestSetup *iSetup;
XSCXCTHelper *mCTHelper;
XSCXCCHelper *mCCHelper;
//
// For Pivot Checking ...
XPivot lastSupportPivot;
XPivot lastResistancePivot;
//
// For Zone Checking ...
XZone lastSupportZone;
XZone lastResistanceZone;
//
// Event Handlers ...
//
// Initialization ...
int OnInit()
{
//
if (!ValidateInputs())
{
return INIT_PARAMETERS_INCORRECT;
}
//
if (!InitialEA())
{
return INIT_FAILED;
}
//
bool isInited = eaBarTracker.Init(
_Symbol,
_Period //
);
if (!isInited)
{
return INIT_FAILED;
}
//
// Init Succeed ...
return INIT_SUCCEEDED;
}
//
// DeInitialization ...
void OnDeinit(const int reason)
{
//
// REASON_PROGRAM 0 The EA has stopped working calling the ExpertRemove() function
// REASON_REMOVE 1 Program removed from a chart
// REASON_RECOMPILE 2 Program recompiled
// REASON_CHARTCHANGE 3 A symbol or a chart period is changed
// REASON_CHARTCLOSE 4 Chart closed
// REASON_PARAMETERS 5 Inputs changed by a user
// REASON_ACCOUNT 6 Another account has been activated or reconnection to the trade server has occurred due to changes in the account settings
// REASON_TEMPLATE 7 Another chart template applied
// REASON_INITFAILED 8 The OnInit() handler returned a non-zero value
// REASON_CLOSE 9 Terminal closed
//
// De Initialize XSampleEA Providers ...
delete mSetupEA;
delete mCTHelper;
delete mCCHelper;
}
//
// On Tick Handler ...
void OnTick()
{
//
// mSetupEA.OnTick();
//
if (!eaBarTracker.CanProcessBar())
{
return;
}
//
// Check Pivots ...
HandleCheckPivots();
//
// Check Zones ...
// HandleCheckZones();
}
//
// Custom Functions ...
//
bool ValidateInputs()
{
//
bool result = false;
//
result = true;
//
return result;
}
//
bool InitialEA()
{
//
bool result = false;
//
//
// Bar Timer ...
XCTInputs ctInputs;
ctInputs.Default();
mCTHelper = new XSCXCTHelper();
result = mCTHelper.Init(
_Symbol,
_Period,
ctInputs //
);
if (!result)
{
return result;
}
//
// Bar Styles ...
XCCInputs ccInputs;
ccInputs.Default();
mCCHelper = new XSCXCCHelper();
result = mCCHelper.Init(
_Symbol,
_Period,
ccInputs //
);
if (!result)
{
return result;
}
//
// Preparing EA Class ...
mSetupEA = new XSCXTestSetupEA(
mSlippage,
mMagicNumber //
);
//
// Configuring EA Class ...
mSetupEA.Volume(eaVolume);
mSetupEA.AllowLong(eaAllowLong);
mSetupEA.AllowShort(eaAllowShort);
//
// Configure Indicators ...
XTestInputs setupInputsDefault;
setupInputsDefault.Default();
PreConfigureStyles(setupInputsDefault);
//
// Instantiate Per Symbol ...
//
string iSymbol = _Symbol;
ENUM_TIMEFRAMES iPeriod = _Period;
//
XTestInputs iInputs;
iInputs = setupInputsDefault;
iInputs.tpPoint = 60;
iInputs.slPoint = 60;
iInputs.symbol = iSymbol;
iInputs.period = iPeriod;
iInputs.volume = eaVolume;
result = iInputs.IsValid();
if (!result)
{
return result;
}
//
iSetup = new XSCXTestSetup();
result = iSetup.Init(iInputs);
if (!result)
{
return result;
}
//
result = mSetupEA.AddSetup(iSetup);
//
return result;
}
//
void PreConfigureStyles(XTestInputs &inputs)
{
//
// XRL ...
inputs.rlInputs.showFast = false;
inputs.rlInputs.showSlow = false;
inputs.rlInputs.showVerifier = false;
//
// XHTD ...
inputs.htdInputs.show = false;
//
// XATSL ...
inputs.atslInputs.show = false;
//
// XSLN ...
inputs.slnInputs.show = false;
//
// XDMNT ...
inputs.dmntInputs.showBull = false;
inputs.dmntInputs.showBear = false;
//
// XSTR ...
inputs.strInputs.showTrends = false;
inputs.strInputs.fillTrends = false;
//
// XPV ...
inputs.pvInputs.showPeaksAndVales = false;
inputs.pvInputs.showLevels = false;
inputs.pvInputs.showConsolidations = false;
inputs.pvInputs.showFibo1Levels = false;
inputs.pvInputs.showFibo2Levels = false;
inputs.pvInputs.showFibo3Levels = false;
inputs.pvInputs.showFibo4Levels = false;
inputs.pvInputs.showFibo5Levels = false;
//
// XMC ...
inputs.mcInputs.showSar = false;
inputs.mcInputs.showFastMa = false;
inputs.mcInputs.showSlowMa = false;
inputs.mcInputs.showVerifierMa = false;
//
// XHK ...
inputs.hkInputs.drawHikenAshi = false;
inputs.hkInputs.drawSmoothedHikenAshi = false;
//
// XCHE ...
inputs.cheInputs.showLongExit1Line = false;
inputs.cheInputs.showShortExit1Line = false;
inputs.cheInputs.showLongExit2Line = false;
inputs.cheInputs.showShortExit2Line = false;
//
// XICH ...
inputs.ichInputs.showTenkanSen = false;
inputs.ichInputs.showKijunSen = false;
inputs.ichInputs.showKijunSenPlus = false;
inputs.ichInputs.showKijunSenNegative = false;
inputs.ichInputs.showChikouSpan = false;
inputs.ichInputs.showSenkouSpanA = false;
inputs.ichInputs.showSenkouSpanB = false;
inputs.ichInputs.showKumo = false;
//
// XMRB ...
inputs.mrbInputs.showFastMa = false;
inputs.mrbInputs.showSlowMa = false;
inputs.mrbInputs.showRibbon = false;
//
// XASCT ...
inputs.asctInputs.showLongs = false;
inputs.asctInputs.showShorts = false;
//
// XSSLC ...
inputs.sslcInputs.showUp = false;
inputs.sslcInputs.showDown = false;
//
// XHULL ...
inputs.hullInputs.showUpZone = false;
inputs.hullInputs.showDownZone = false;
//
// XCHMA ...
inputs.chmaInputs.showFast = false;
inputs.chmaInputs.showSlow = false;
inputs.chmaInputs.showCCFast = false;
inputs.chmaInputs.showCCSlow = false;
inputs.chmaInputs.showSCFast = false;
inputs.chmaInputs.showSCSlow = false;
inputs.chmaInputs.showMCFast = false;
inputs.chmaInputs.showMCSlow = false;
inputs.chmaInputs.showLCFast = false;
inputs.chmaInputs.showLCSlow = false;
inputs.chmaInputs.showHCFast = false;
inputs.chmaInputs.showHCSlow = false;
}
//
// Custom Testing Functions ...
//
void HandleCheckPivots()
{
//
XOHCL cBar;
bool isInited = cBar.Init(
_Symbol,
_Period,
1 //
);
if (!isInited)
{
return;
}
//
// Check Resistance ...
if (!lastResistancePivot.isResistance)
{
//
isInited = lastResistancePivot.FindLastResistance(
_Symbol,
_Period //
);
if (!isInited)
{
//
lastResistancePivot.Clean();
return;
}
//
bool isDrawn = lastResistancePivot.Draw(ChartID());
if (isDrawn)
{
Print("Valid Resistance ...");
}
}
//
// Check Support ...
if (!lastSupportPivot.isSupport)
{
//
isInited = lastSupportPivot.FindLastSupport(
_Symbol,
_Period //
);
if (!isInited)
{
//
lastSupportPivot.Clean();
return;
}
//
bool isDrawn = lastSupportPivot.Draw(ChartID());
if (isDrawn)
{
Print("Valid Support ...");
}
}
else
{
//
bool isBreaked = lastSupportPivot.IsBreaked();
bool isRejected = lastSupportPivot.IsRejected();
//
if (isBreaked)
{
//
lastSupportPivot.Clean();
Print("Support Breaked ...");
}
//
if (isRejected)
{
//
lastSupportPivot.Clean();
Print("Support Rejected ...");
}
}
}
//
void HandleCheckZones() {
//
bool result = false;
//
// Find Last Support Zone ...
if (!lastSupportZone.IsValid()) {
//
result = lastSupportZone.FindLastSupportZone(
_Symbol,
_Period //
);
if (!result) {
return;
}
//
result = lastSupportZone.Draw(ChartID());
if (result) {
Print("Valid Support Zone ...");
}
} else {
}
//
// Find Last Resistance Zone ...
if (!lastResistanceZone.IsValid()) {
//
result = lastResistanceZone.FindLastResistanceZone(
_Symbol,
_Period //
);
if (!result) {
return;
}
//
result = lastResistanceZone.Draw(ChartID());
if (result) {
Print("Valid Resistance Zone ...");
}
} else {
}
}
//
void OldTests()
{
// //
// XTestConditions conditions;
// bool hasConditions = iSetup.GetConditions(
// conditions,
// 0,
// 5 //
// );
// if (hasConditions)
// {
// //
// bool isCHMAOverUnder1 =
// //
// (conditions.chmaConditions.isFastOverMin &&
// conditions.chmaConditions.isFastUnderMin)
// //
// ;
// //
// bool isCHMAOverUnder2 =
// //
// (conditions.chmaConditions.isSlowOverMin &&
// conditions.chmaConditions.isSlowUnderMin)
// //
// ;
// //
// bool isCHMAOverUnder3 =
// //
// (conditions.chmaConditions.isFastOverMax &&
// conditions.chmaConditions.isFastUnderMax)
// //
// ;
// //
// bool isCHMAOverUnder4 =
// //
// (conditions.chmaConditions.isSlowOverMax &&
// conditions.chmaConditions.isSlowUnderMax)
// //
// ;
// //
// if (isCHMAOverUnder1 || isCHMAOverUnder2 || isCHMAOverUnder3 || isCHMAOverUnder4)
// {
// Print("isCHMAOverUnder");
// }
// }
// //
// XOHCL cBar;
// bool isInit = cBar.Init(
// _Symbol,
// _Period,
// 1 //
// );
// if (!isInit)
// {
// return;
// }
// //
// datetime time1 = iTime(
// _Symbol,
// _Period,
// 2 //
// );
// //
// double fib382 = 0;
// //
// bool isHammer = cBar.IsHammer();
// if (isHammer)
// {
// //
// fib382 = GetFibonacciLevel(
// cBar.high,
// cBar.low,
// 0.382,
// -1 //
// );
// DrawTrendLine(
// ChartID(),
// "HMR_TR",
// 0,
// time1,
// fib382,
// cBar.time,
// fib382,
// clrYellow //
// );
// Print("Hammer ...");
// eaBarTracker.Waits();
// }
// //
// bool isShootingStar = cBar.IsShootingStar();
// if (isShootingStar)
// {
// //
// fib382 = GetFibonacciLevel(
// cBar.high,
// cBar.low,
// 0.382,
// 1 //
// );
// DrawTrendLine(
// ChartID(),
// "HMR_TR",
// 0,
// time1,
// fib382,
// cBar.time,
// fib382,
// clrYellow //
// );
// Print("ShootingStar ...");
// eaBarTracker.Waits();
// }
// //
// bool isBullishEngulf = cBar.IsBullishEngulf();
// if (isBullishEngulf)
// {
// //
// Print("Bullish Engulf ...");
// eaBarTracker.Waits();
// }
// //
// bool isBearishEngulf = cBar.IsBearishEngulf();
// if (isBearishEngulf)
// {
// //
// Print("Bearish Engulf ...");
// eaBarTracker.Waits();
// }
}
//