322 lines
7.0 KiB
Plaintext
322 lines
7.0 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XTest MQL5 Expert Advisor
|
|
// -------------------------------------------------
|
|
// Name: XTestPivotsEA
|
|
// 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 XTestPivotsEA"
|
|
#property strict
|
|
|
|
//
|
|
#define ShortName "XTestPivotsEA"
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Helpers/x-saherelm.xct.helper.mq5"
|
|
#include "../Helpers/x-saherelm.xcc.helper.mq5"
|
|
#include "../Strategies/x-saherelm.xsrbr.strategy.mq5"
|
|
|
|
//
|
|
// Inputs ...
|
|
long mMagicNumber = 78692110; // Magic Number
|
|
int mSlippage = 10; // Slippgae
|
|
|
|
//
|
|
double eaVolume = 0.01;
|
|
double eaAllowLong = true;
|
|
double eaAllowShort = true;
|
|
|
|
//
|
|
// Variables ...
|
|
XSCXCTHelper *mCTHelper;
|
|
XSCXCCHelper *mCCHelper;
|
|
|
|
//
|
|
XSCBaseStrategy *strategies[];
|
|
|
|
//
|
|
// Event Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
if (!ValidateInputs())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
if (!InitialEA())
|
|
{
|
|
return INIT_FAILED;
|
|
}
|
|
|
|
//
|
|
// EventSetTimer(1);
|
|
// EventSetMillisecondTimer(100);
|
|
|
|
//
|
|
// 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 mCTHelper;
|
|
delete mCCHelper;
|
|
|
|
//
|
|
// EventKillTimer();
|
|
|
|
//
|
|
Clean(strategies);
|
|
}
|
|
|
|
//
|
|
// On Tick Handler ...
|
|
void OnTick()
|
|
{
|
|
HandleStrategiesOnTick();
|
|
}
|
|
|
|
//
|
|
// On Timer ...
|
|
void OnTimer()
|
|
{
|
|
//
|
|
// HandleStrategiesOnTick();
|
|
}
|
|
|
|
//
|
|
// Custom Functions ...
|
|
|
|
//
|
|
// Validate Inputs ...
|
|
bool ValidateInputs()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result = true;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Initialize all Requirements ...
|
|
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;
|
|
}
|
|
|
|
//
|
|
XSymbolParser symbolParser;
|
|
|
|
//
|
|
bool drawAreas = false;
|
|
|
|
//
|
|
// EURUSD ...
|
|
string eurusdSymbol = "EURUSDb"; // symbolParser.GetEURUSDSymbol();
|
|
if (IsValid(eurusdSymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = mMagicNumber + 1;
|
|
|
|
//
|
|
// Register XSRBR on EURUSD in M5 ...
|
|
XSCXSRBRStrategy *eurusdM5SRBRStrategy;
|
|
eurusdM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
eurusdSymbol,
|
|
PERIOD_M5,
|
|
PERIOD_H1,
|
|
eaVolume,
|
|
1.5, // R2R ...
|
|
mSlippage,
|
|
magicNumber,
|
|
true, // Use TP SL Point
|
|
false, // Use Max
|
|
200, // TP
|
|
100, // SL
|
|
eaAllowLong,
|
|
eaAllowShort,
|
|
0, // Max Longs
|
|
0, // Max Shorts
|
|
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
);
|
|
eurusdM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
eurusdM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
RegisterStrategy(eurusdM5SRBRStrategy);
|
|
|
|
//
|
|
// Register XSRBR on EURUSD in M5 ...
|
|
XSCXSRBRStrategy *eurusdM15SRBRStrategy;
|
|
eurusdM15SRBRStrategy = new XSCXSRBRStrategy(
|
|
eurusdSymbol,
|
|
PERIOD_M15,
|
|
PERIOD_M30,
|
|
eaVolume,
|
|
1.5, // R2R ...
|
|
mSlippage,
|
|
magicNumber,
|
|
true, // Use TP SL Point
|
|
false, // Use Max
|
|
200, // TP
|
|
100, // SL
|
|
eaAllowLong,
|
|
eaAllowShort,
|
|
0, // Max Longs
|
|
0, // Max Shorts
|
|
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
);
|
|
eurusdM15SRBRStrategy.SetAlertLogAlerts(true);
|
|
eurusdM15SRBRStrategy.SetAlertEnableAlerts(true);
|
|
RegisterStrategy(eurusdM15SRBRStrategy);
|
|
}
|
|
|
|
//
|
|
// USDCHF ...
|
|
string usdchfSymbol = "USDCHFb";
|
|
if (IsValid(usdchfSymbol))
|
|
{
|
|
//
|
|
// MAGIC NUMBER ...
|
|
long magicNumber = mMagicNumber + 2;
|
|
|
|
//
|
|
// Register XSRBR on EURUSD in M5 ...
|
|
XSCXSRBRStrategy *usdchfM5SRBRStrategy;
|
|
usdchfM5SRBRStrategy = new XSCXSRBRStrategy(
|
|
usdchfSymbol,
|
|
PERIOD_M5,
|
|
PERIOD_H1,
|
|
eaVolume,
|
|
1.5, // R2R ...
|
|
mSlippage,
|
|
magicNumber,
|
|
true, // Use TP SL Point
|
|
false, // Use Max
|
|
200, // TP
|
|
100, // SL
|
|
eaAllowLong,
|
|
eaAllowShort,
|
|
0, // Max Longs
|
|
0, // Max Shorts
|
|
X_SIGNALLING_BOTH_DIRECTIONS // X_SIGNALIING_TREND_REVERSAL_DIRECTION // X_SIGNALLING_BOTH_DIRECTIONS //
|
|
);
|
|
usdchfM5SRBRStrategy.SetAlertLogAlerts(true);
|
|
usdchfM5SRBRStrategy.SetAlertEnableAlerts(true);
|
|
RegisterStrategy(usdchfM5SRBRStrategy);
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Register Strategy ...
|
|
void RegisterStrategy(XSCBaseStrategy *strategy)
|
|
{
|
|
//
|
|
if (strategy == NULL)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
ArrayResize(
|
|
strategies,
|
|
ArraySize(strategies) + 1 //
|
|
);
|
|
|
|
//
|
|
strategies[ArraySize(strategies) - 1] = strategy;
|
|
}
|
|
|
|
//
|
|
// Call All Registered Strategis Tick Handler Functions ...
|
|
void HandleStrategiesOnTick()
|
|
{
|
|
//
|
|
int count = ArraySize(strategies);
|
|
if (!IsValidSize(count))
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
//
|
|
// Call Tick Handler Function ...
|
|
strategies[i].HandleTick();
|
|
}
|
|
}
|
|
|
|
//
|
|
// Custom Testing Functions ...
|
|
|
|
// |