update workspace ...
This commit is contained in:
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,262 +0,0 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Expert Advisor
|
||||
// ----------------------------------------
|
||||
// Name: X121EA
|
||||
// Description: this is an expert controller
|
||||
// advisors which provides a mechanism for use them ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property description "SaherElm X121EA"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Common Library ...
|
||||
#include "../Classes/x-saherelm.x121.xea.class.mq5"
|
||||
|
||||
//
|
||||
#define ShortName "X121EA"
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// EA ...
|
||||
input group "Common";
|
||||
input bool xEAEnable = true; // Enable EA
|
||||
input int xEASlippage = 10; // Slippgae
|
||||
input ulong xEAMagicNumber = 1604056; // Magic Number
|
||||
|
||||
//
|
||||
// Signals ...
|
||||
input group "Signals";
|
||||
input bool xEAEnableLongs = true; // Enable Long Trades
|
||||
input bool xEAEnableShorts = true; // Enable Short Trades
|
||||
|
||||
//
|
||||
// Risk Management ...
|
||||
input group "Risk Management";
|
||||
input int xEAMaxOpenPositions = 15; // Max Allowed Open Positions
|
||||
input double xEAMaxAllowedDrawDownFactor = 0.15; // Max Allowed Drawdown Factor
|
||||
|
||||
//
|
||||
// Alerts ...
|
||||
input group "Alerts";
|
||||
input bool xEAEnableAlerts = true; // Enable Events Alert
|
||||
input bool xEAEnableHourlyAlerts = false; // Send Alert on each new Hour
|
||||
input bool xEAEnableDailyAlerts = false; // Send Alert on each new Day
|
||||
input bool xEAEnableWeeklyAlerts = false; // Send Alert on each new Week
|
||||
input bool xEAEnableMonthlyAlerts = false; // Send Alert on each new Month
|
||||
|
||||
//
|
||||
// END Inputs ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Logger Library ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
|
||||
//
|
||||
// END Including Providers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
XSCX121EA *mX121EA;
|
||||
|
||||
//
|
||||
// END Global Definitions: Variables, Properties and etc ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = logTag;
|
||||
alertPrefix = logTag;
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!ValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
InitEAInstance();
|
||||
|
||||
//
|
||||
// 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 XEA Providers ...
|
||||
delete mX121EA;
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// Prevent Going Forward if user Disable it ...
|
||||
if (xEAEnable)
|
||||
{
|
||||
mX121EA.OnTick();
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade Events ...
|
||||
void OnTrade()
|
||||
{
|
||||
mX121EA.OnTrade();
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Signal Event ...
|
||||
void OnSignalConditionsRecieved(X121MarketConditions &info)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle StopLoss Event ...
|
||||
void OnStopLossTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle TakeProfit Event ...
|
||||
void OnTakeProfitTriggered(const XDeal &deal)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Deals Changed Event ...
|
||||
void OnDealsChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Order Changed Event ...
|
||||
void OnOrdersChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Position Changed Event ...
|
||||
void OnPositionsChangedHandler(int count)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Trade State Changed ...
|
||||
void OnTradeStateChangedHandler(const XOnTradeHandlerState &state)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// END Event Handlers ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Validate Input Args for Initialization ...
|
||||
bool ValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = true;
|
||||
|
||||
//
|
||||
// Validate Args ...
|
||||
result =
|
||||
//
|
||||
xEASlippage > 0 &&
|
||||
xEAMagicNumber > 0
|
||||
//
|
||||
// TODO: add new validations here ...
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
// Logging State ...
|
||||
string message = "Validation of (" + logTag + ") Inputs " + (result ? "Succeeded" : "Failed") + " ...";
|
||||
LogMessage(message);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize X121EA Class Instances ...
|
||||
void InitEAInstance()
|
||||
{
|
||||
//
|
||||
mX121EA = new XSCX121EA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
xEAMagicNumber,
|
||||
xEASlippage,
|
||||
OnStopLossTriggered,
|
||||
OnTakeProfitTriggered,
|
||||
OnDealsChangedHandler,
|
||||
OnOrdersChangedHandler,
|
||||
OnPositionsChangedHandler,
|
||||
OnTradeStateChangedHandler,
|
||||
OnSignalConditionsRecieved);
|
||||
}
|
||||
//
|
||||
// END Functions ...
|
||||
//
|
||||
Binary file not shown.
@@ -0,0 +1,398 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center XSAMPLE MQL5 Expert Advisor
|
||||
// -------------------------------------------------
|
||||
// Name: XSAMPLE
|
||||
// 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 XSAMPLE"
|
||||
#property strict
|
||||
|
||||
//
|
||||
#define ShortName "XSAMPLE"
|
||||
|
||||
//
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
#include "../Helpers/x-saherelm.x121.xmc.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xstr.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xche.helper.mq5"
|
||||
#include "../Helpers/x-saherelm.x121.xosc.helper.mq5"
|
||||
|
||||
//
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Classes/x-saherelm.x121.xmcycle.class.mq5"
|
||||
|
||||
//
|
||||
// Inputs ...
|
||||
long xSampleEAMagicNumber = 78692110; // Magic Number
|
||||
int xSampleEASlippage = 10; // Slippgae
|
||||
|
||||
//
|
||||
double xSampleEAVolume = 0.01;
|
||||
|
||||
//
|
||||
// Vars ...
|
||||
string xSampleEASymbol;
|
||||
ENUM_TIMEFRAMES xSampleEAPeriod;
|
||||
|
||||
//
|
||||
int maxBuys = 1;
|
||||
int maxSells = 1;
|
||||
int buyCount = 0;
|
||||
int sellCount = 0;
|
||||
|
||||
//
|
||||
double _tp = 0;
|
||||
double _sl = 0;
|
||||
double _entry = 0;
|
||||
ENUM_POSITION_TYPE _type = NULL;
|
||||
|
||||
//
|
||||
MqlTick xSampleEATick;
|
||||
|
||||
//
|
||||
XBarTracker xSamplEABarTracker;
|
||||
|
||||
//
|
||||
// X121MCycle ...
|
||||
X121MCycleInputs xSampleEA121MCInputs;
|
||||
XSC121Market xSampleEA121MC;
|
||||
|
||||
//
|
||||
XSCSignalCollector signalCollector;
|
||||
|
||||
//
|
||||
// Event Handlers ...
|
||||
//
|
||||
// Initialization ...
|
||||
int OnInit()
|
||||
{
|
||||
//
|
||||
if (xSampleEASymbol == NULL || StringLen(xSampleEASymbol) <= 0)
|
||||
{
|
||||
xSampleEASymbol = _Symbol;
|
||||
}
|
||||
|
||||
//
|
||||
if (xSampleEAPeriod == NULL)
|
||||
{
|
||||
xSampleEAPeriod = _Period;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
if (!XSampleEAValidateInputs())
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
logTag = ShortName;
|
||||
drawPrefix = ShortName;
|
||||
|
||||
//
|
||||
bool result = xSamplEABarTracker.Init(
|
||||
xSampleEASymbol,
|
||||
xSampleEAPeriod);
|
||||
if (!result)
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// X121Market Cycle ...
|
||||
result = xSampleEA121MCInputs.Init(
|
||||
xSampleEASymbol,
|
||||
xSampleEAPeriod,
|
||||
X_MARKET_CYCLE_SHORT,
|
||||
PERIOD_H1,
|
||||
X_PERIOD_MANUALLY //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return INIT_PARAMETERS_INCORRECT;
|
||||
}
|
||||
|
||||
//
|
||||
// after Inputs Initialize Successfully we must prepare Styling for Draw ...
|
||||
ApplyMCDrawStyles();
|
||||
|
||||
//
|
||||
result = xSampleEA121MC.Init(
|
||||
xSampleEA121MCInputs
|
||||
//
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
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 ...
|
||||
}
|
||||
|
||||
//
|
||||
// On Tick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
if (!xSamplEABarTracker.IsNewBar())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Reading Tick ...
|
||||
if (!SymbolInfoTick(xSampleEASymbol, xSampleEATick))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Draw Market Cycle Bars On Chart ...
|
||||
int offset = 0;
|
||||
xSampleEA121MC.Draw(
|
||||
ChartID(),
|
||||
0,
|
||||
offset
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// TestXSignalCollector();
|
||||
}
|
||||
|
||||
//
|
||||
// Custom Functions ...
|
||||
|
||||
//
|
||||
// Validate Variables nd Inputs ...
|
||||
bool XSampleEAValidateInputs()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
xSampleEASlippage > 0 &&
|
||||
xSampleEAMagicNumber > 0
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
void TestXSignalCollector()
|
||||
{
|
||||
//
|
||||
XSignal signal;
|
||||
bool isPrepared = signal.Prepare(
|
||||
xSampleEASymbol,
|
||||
"XTest",
|
||||
xSampleEAPeriod,
|
||||
POSITION_TYPE_BUY,
|
||||
X_ORDER_MODE_MARKET,
|
||||
GetEntry(
|
||||
xSampleEASymbol,
|
||||
POSITION_TYPE_BUY),
|
||||
0.01,
|
||||
0,
|
||||
0
|
||||
//
|
||||
);
|
||||
if (isPrepared)
|
||||
{
|
||||
//
|
||||
bool isAdded = signalCollector
|
||||
.Add(signal);
|
||||
|
||||
//
|
||||
if (isAdded)
|
||||
{
|
||||
LogMessage("Signal Added Successfully ...");
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Try to Reading Collection ...
|
||||
XSignal collectedSignals[];
|
||||
int collectedSignalsCount = signalCollector.Collect(collectedSignals);
|
||||
if (collectedSignalsCount > 0)
|
||||
{
|
||||
LogMessage("Number of Loaded Signals: " + ToString(collectedSignalsCount));
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
void ApplyMCDrawStyles()
|
||||
{
|
||||
//
|
||||
// Here we Apply All Draw Styles on Input of Market Cycle ...
|
||||
xSampleEA121MCInputs.drawCBar = true;
|
||||
xSampleEA121MCInputs.drawPBar = true;
|
||||
xSampleEA121MCInputs.drawLabels = true;
|
||||
xSampleEA121MCInputs.drawCBarMid = true;
|
||||
xSampleEA121MCInputs.drawPBarMid = true;
|
||||
|
||||
//
|
||||
// Current ...
|
||||
|
||||
//
|
||||
// MidLine ...
|
||||
xSampleEA121MCInputs.cBarMidDrawSpecs.width = 1;
|
||||
xSampleEA121MCInputs.cBarMidDrawSpecs.style = STYLE_DOT;
|
||||
xSampleEA121MCInputs.cBarMidDrawSpecs.clr = clrSpringGreen;
|
||||
xSampleEA121MCInputs.cBarMidDrawSpecs.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_C MID",
|
||||
xSampleEA121MCInputs.cBarMidDrawSpecs.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// XOHCL ...
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.Default();
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.Width(1);
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.Style(STYLE_DOT);
|
||||
//
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.openStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_C O",
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.openStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.highStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_C H",
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.highStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_C C",
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.closeStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_C L",
|
||||
xSampleEA121MCInputs.cBarDrawSpecs.lowStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// Prev ...
|
||||
|
||||
//
|
||||
// MidLine ...
|
||||
xSampleEA121MCInputs.pBarMidDrawSpecs.width = 2;
|
||||
xSampleEA121MCInputs.pBarMidDrawSpecs.style = STYLE_SOLID;
|
||||
xSampleEA121MCInputs.pBarMidDrawSpecs.clr = clrLimeGreen;
|
||||
xSampleEA121MCInputs.pBarMidDrawSpecs.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_P MID",
|
||||
xSampleEA121MCInputs.pBarMidDrawSpecs.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
|
||||
//
|
||||
// XOHCL ...
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.Default();
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.Width(2);
|
||||
//
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.openStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_P O",
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.openStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.highStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_P H",
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.highStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_P C",
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.closeStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.Label(
|
||||
xSampleEA121MCInputs.cycle.prefix + "_P L",
|
||||
xSampleEA121MCInputs.pBarDrawSpecs.lowStyle.clr,
|
||||
"Arial",
|
||||
8,
|
||||
ANCHOR_LEFT_UPPER,
|
||||
90
|
||||
//
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user