413 lines
8.1 KiB
Plaintext
413 lines
8.1 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 "../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;
|
|
XSCXCTHelper *mCTHelper;
|
|
XSCXCCHelper *mCCHelper;
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
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();
|
|
}
|
|
}
|
|
|
|
//
|
|
// 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;
|
|
}
|
|
|
|
//
|
|
XSCXTestSetup *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;
|
|
}
|
|
|
|
// |