271 lines
5.5 KiB
Plaintext
271 lines
5.5 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center XTESTXXX MQL5 Expert Advisor
|
|
// -------------------------------------------------
|
|
// Name: XTESTXXX
|
|
// Description: an Exper Advisor which used RSI and MA
|
|
// 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 XTESTXXX"
|
|
#property strict
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
|
#include "../Classes/x-saherelm.xalert.class.mq5"
|
|
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
|
#include "../Classes/x-saherelm.x121.setup.class.mq5"
|
|
|
|
//
|
|
#define ShortName "XTESTXXX"
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
long eaMagicNumber = 78692110; // Magic Number
|
|
int eaSlippage = 10; // Slippgae
|
|
|
|
//
|
|
string eaSymbols = "EURUSDb"; // Symbols
|
|
|
|
//
|
|
bool eaAllowLong = true; // Allow Long Trades
|
|
bool eaAllowShort = true; // Allow Short Trades
|
|
double eaVolume = 0.05; // Static Volume
|
|
int eaReuiredVerifications = 1; // Required Verifications for Signals
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// Local Variables ...
|
|
|
|
//
|
|
XSCAlert *mAlert;
|
|
XSCTrade *mTrader;
|
|
|
|
//
|
|
XSCX121Setup *mSetup;
|
|
X121SignalGenerator mSignalGenerator;
|
|
|
|
//
|
|
XBarTracker xBarTracker;
|
|
|
|
//
|
|
// Event Handlers ...
|
|
|
|
//
|
|
// Initialization ...
|
|
int OnInit()
|
|
{
|
|
//
|
|
drawPrefix = ShortName;
|
|
|
|
//
|
|
if (!InitialEA())
|
|
{
|
|
return INIT_PARAMETERS_INCORRECT;
|
|
}
|
|
|
|
//
|
|
// 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 mSetup;
|
|
|
|
//
|
|
delete mAlert;
|
|
delete mTrader;
|
|
}
|
|
|
|
//
|
|
// On Tick Handler ...
|
|
void OnTick()
|
|
{
|
|
//
|
|
if (!xBarTracker.CanProcessBar())
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Get Consitions and Validate it ...
|
|
X121SetupConditions conditions;
|
|
bool hasConditions = mSetup.GetConditions(
|
|
conditions //
|
|
);
|
|
if (!hasConditions)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
string separator = "\n";
|
|
|
|
//
|
|
// Retrieve Scores ...
|
|
double bullishScore = 0;
|
|
double bearishScore = 0;
|
|
conditions.GenerateScore(
|
|
bullishScore,
|
|
bearishScore //
|
|
);
|
|
|
|
//
|
|
// Create Score Summary for Commenting on Chart ...
|
|
string scoreSummary =
|
|
//
|
|
"Scores:" + separator +
|
|
"----------" + separator +
|
|
"Bullish: " + ToString(bullishScore) + separator +
|
|
"Bearish: " + ToString(bearishScore) + separator +
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
Comment(scoreSummary);
|
|
|
|
//
|
|
// Check Conditions has Signal or not ...
|
|
int pusher = 0;
|
|
XSignal signal;
|
|
bool hasSignal = mSignalGenerator
|
|
.HasSignal(
|
|
conditions,
|
|
signal,
|
|
pusher,
|
|
eaAllowLong,
|
|
eaAllowShort,
|
|
eaVolume,
|
|
0, // SL Point ...
|
|
30 // TP Point ...
|
|
);
|
|
if (!hasSignal)
|
|
{
|
|
return;
|
|
}
|
|
|
|
//
|
|
// Since we have a Signal in current Bar, ignore other ticks and
|
|
// waits for Next Bar ...
|
|
xBarTracker.Waits();
|
|
|
|
//
|
|
// Generate Condition Summary for Logging ...
|
|
string summary = conditions.GenerateSummary(false, true, false);
|
|
|
|
//
|
|
Print(summary);
|
|
|
|
//
|
|
ENUM_X_SIGNAL_EXECUTION_RESULT state;
|
|
int isExecuted = mTrader.ExecuteSignal(
|
|
signal,
|
|
state //
|
|
);
|
|
if (isExecuted)
|
|
{
|
|
//
|
|
string message = "Signal Executed Successfully ...";
|
|
|
|
//
|
|
mAlert.Alert(message);
|
|
}
|
|
}
|
|
|
|
//
|
|
// Custom Functions ...
|
|
|
|
//
|
|
bool InitialEA()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
TesterHideIndicators(true);
|
|
|
|
//
|
|
mAlert = new XSCAlert();
|
|
mAlert.SetLogAlerts(true);
|
|
mAlert.SetPrefix(ShortName);
|
|
mAlert.SetEnableAlerts(true);
|
|
mAlert.SetPushAlerts(false);
|
|
mAlert.SetMailAlerts(false);
|
|
mAlert.SetTerminalAlerts(false);
|
|
|
|
//
|
|
mTrader = new XSCTrade(
|
|
eaSlippage,
|
|
eaMagicNumber,
|
|
0,
|
|
0,
|
|
0 //
|
|
);
|
|
|
|
//
|
|
result = xBarTracker.Init(
|
|
_Symbol,
|
|
_Period //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
X121SetupInputs x121Inputs;
|
|
x121Inputs.symbol = _Symbol;
|
|
x121Inputs.period = _Period;
|
|
result = x121Inputs.Init();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
mSetup = new XSCX121Setup();
|
|
result = mSetup.Init(
|
|
x121Inputs //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|