add MQL5Test Workspace Content as BKP Solution ...
This commit is contained in:
@@ -0,0 +1,385 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCHttp
|
||||
// Description: provides all HTTP requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
enum X_HTTP_METHOD
|
||||
{
|
||||
X_HTTP_GET,
|
||||
X_HTTP_POST
|
||||
};
|
||||
|
||||
//
|
||||
// Convert enum to String ...
|
||||
string ToString(X_HTTP_METHOD method)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
switch (method)
|
||||
{
|
||||
//
|
||||
case X_HTTP_GET:
|
||||
result = "GET";
|
||||
break;
|
||||
|
||||
//
|
||||
case X_HTTP_POST:
|
||||
result = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCHttp
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCHttp()
|
||||
{
|
||||
XSCHttp("", 10000);
|
||||
}
|
||||
void XSCHttp(
|
||||
string path, // Base Folder to Store Data
|
||||
int timeout // base timeout for Requests
|
||||
)
|
||||
{
|
||||
//
|
||||
Path(path);
|
||||
Timeout(timeout);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCHttp()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Getter(s)/Setter(s) ...
|
||||
//
|
||||
|
||||
//
|
||||
// Path ...
|
||||
void Path(string value)
|
||||
{
|
||||
mPath = value;
|
||||
}
|
||||
|
||||
string Path()
|
||||
{
|
||||
return mPath;
|
||||
}
|
||||
|
||||
//
|
||||
// Timeout ...
|
||||
void Timeout(int value)
|
||||
{
|
||||
mTimeout = value;
|
||||
}
|
||||
|
||||
//
|
||||
int Timeout()
|
||||
{
|
||||
return mTimeout;
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
int Error()
|
||||
{
|
||||
return mError;
|
||||
}
|
||||
|
||||
//
|
||||
// Response ...
|
||||
string Response()
|
||||
{
|
||||
return mResponse;
|
||||
}
|
||||
|
||||
//
|
||||
// END Getter(s)/Setter(s) ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Send Global Request ...
|
||||
int SendRequest(
|
||||
X_HTTP_METHOD method, // Httm Request Method
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
string strMethod = ToString(method);
|
||||
if (StringLen(strMethod) == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Reset State ...
|
||||
ResetState();
|
||||
|
||||
//
|
||||
result = WebRequest(
|
||||
strMethod,
|
||||
url,
|
||||
headers,
|
||||
timeout,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders);
|
||||
|
||||
//
|
||||
if (result < 0)
|
||||
{
|
||||
mError = GetLastError();
|
||||
}
|
||||
else
|
||||
{
|
||||
mResponse = CharArrayToString(response);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Request ...
|
||||
int GetRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_GET,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Post Request ...
|
||||
int PostRequest(
|
||||
const string url, // Server Address
|
||||
const string headers, // Headers providing
|
||||
const char &payload[], // the Data which needs to Send
|
||||
char &response[], // Response of request
|
||||
string responseHeaders, // Response Headers
|
||||
int timeout = 500 // Timeout for response default is 500
|
||||
)
|
||||
{
|
||||
//
|
||||
int result = SendRequest(
|
||||
X_HTTP_POST,
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Download Specific URL Content to Specific Path and File Name ...
|
||||
bool Download(
|
||||
string url, // the URL address which going to download
|
||||
string fileName // Specify Destination file name to Store Response
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
string filePath = GetFilePath(fileName);
|
||||
string cookie = NULL;
|
||||
string referer = NULL;
|
||||
int timeout = Timeout();
|
||||
|
||||
//
|
||||
char payload[];
|
||||
string headers;
|
||||
char response[];
|
||||
string responseHeaders;
|
||||
|
||||
//
|
||||
// Send Request ...
|
||||
int requestResult = GetRequest(
|
||||
url,
|
||||
headers,
|
||||
payload,
|
||||
response,
|
||||
responseHeaders,
|
||||
timeout);
|
||||
|
||||
//
|
||||
// Define File Handler ...
|
||||
int mFileHandler = FileOpen(
|
||||
filePath,
|
||||
FILE_WRITE | FILE_BIN);
|
||||
if (mFileHandler == INVALID_HANDLE)
|
||||
{
|
||||
//
|
||||
mError = GetLastError();
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Write Response to File ...
|
||||
uint writed = FileWriteArray(
|
||||
mFileHandler,
|
||||
response,
|
||||
0,
|
||||
ArraySize(response));
|
||||
FileFlush(mFileHandler);
|
||||
FileClose(mFileHandler);
|
||||
|
||||
//
|
||||
result = writed > 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Destintion Folder Path ...
|
||||
string mPath;
|
||||
|
||||
//
|
||||
// WEB Request Timeout Value ...
|
||||
int mTimeout;
|
||||
|
||||
//
|
||||
// WEB Request's Response ...
|
||||
string mResponse;
|
||||
|
||||
//
|
||||
// Error Value ...
|
||||
int mError;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Reset Errors State ...
|
||||
void ResetState()
|
||||
{
|
||||
//
|
||||
// Reset Errors ...
|
||||
mError = -1;
|
||||
mResponse = "";
|
||||
ResetLastError();
|
||||
}
|
||||
|
||||
//
|
||||
// Generate Full File Path ...
|
||||
string GetFilePath(string fileName)
|
||||
{
|
||||
//
|
||||
string result = "";
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
Path() + "\\" + fileName
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,443 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCX121EA
|
||||
// Description: an Expert Class which
|
||||
// used X121 Setup ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Classes/x-saherelm.xea.class.mq5"
|
||||
#include "../Libraries/x-saherelm.x121.draw.lib.mq5"
|
||||
#include "../Classes/x-saherelm.x121.provider.class.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// an Expert Advisor Class by X121Provider ...
|
||||
class XSCX121EA : public XSCBaseEA
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XSCX121Provider *mProvider;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCX121EA(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Time Frame
|
||||
ulong magic, // Magic Number
|
||||
int slippage, // Slippgae
|
||||
OnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
|
||||
OnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
|
||||
OnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
|
||||
OnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
|
||||
OnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
|
||||
OnTradeStateChanged onTradeStateChangedHandler = NULL, // On Trade State Changed Event Handler
|
||||
TOnSignalConditions onSignalConditions = NULL // On SignalConditions Event Handler
|
||||
) : XSCBaseEA(symbol,
|
||||
period,
|
||||
magic,
|
||||
slippage,
|
||||
onStopLossTriggered,
|
||||
onTakeProfitTriggered,
|
||||
onDealsChangedHandler,
|
||||
onOrdersChangedHandler,
|
||||
onPositionsChangedHandler,
|
||||
onTradeStateChangedHandler)
|
||||
{
|
||||
//
|
||||
mOnSignalConditions = onSignalConditions;
|
||||
|
||||
//
|
||||
InitProvider();
|
||||
}
|
||||
|
||||
//
|
||||
// DeConstructor ...
|
||||
void ~XSCX121EA()
|
||||
{
|
||||
delete mProvider;
|
||||
}
|
||||
|
||||
//
|
||||
// START Inheritance Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
void PrepareTag()
|
||||
{
|
||||
mTag = "X121EA:" + mSymbol + "," + ToString(mPeriod) + (string)mMagic;
|
||||
}
|
||||
|
||||
//
|
||||
bool CheckGuard(XGuard &guards[])
|
||||
{
|
||||
return mProvider.GuardCheck(guards);
|
||||
}
|
||||
|
||||
//
|
||||
bool SignalCheck(XSignal &signals[])
|
||||
{
|
||||
//
|
||||
// Detect Pivot Points ...
|
||||
int foundedPivots = mProvider.CountPivots();
|
||||
int reuiredPivots = mProvider.GetMinPivots();
|
||||
if (foundedPivots < reuiredPivots)
|
||||
{
|
||||
//
|
||||
mProvider.ProccessPivotPoints();
|
||||
|
||||
//
|
||||
LogMessage("Founding Pivots: " + ToString(foundedPivots) + "/" + ToString(reuiredPivots));
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
X121MarketConditions conditions;
|
||||
bool result = mProvider.ProcessTick(conditions);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
// TODO: Here we Do all Signal Preparations such as TP/SL Calculations
|
||||
// or Support and Resistance usage or Volume Calculations ...
|
||||
// then pass prepared Signal to Execution ...
|
||||
|
||||
//
|
||||
ulong mTicket = MathRand() * 100000;
|
||||
|
||||
//
|
||||
DrawSignal(
|
||||
mTicket,
|
||||
conditions.signal);
|
||||
|
||||
//
|
||||
DrawSupportResistance(
|
||||
0,
|
||||
conditions.supportResistances,
|
||||
conditions.signal.providers[0]);
|
||||
|
||||
//
|
||||
// IGNORE SIGNAL EXECUTTION ...
|
||||
return false;
|
||||
|
||||
//
|
||||
Add(
|
||||
conditions.signal,
|
||||
signals);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Inheritance Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Actions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Provided Actions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
X121ProviderInputs mProviderConfig;
|
||||
TOnSignalConditions mOnSignalConditions;
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
//
|
||||
// Prepare Default Configurations for X121Provider Setup ...
|
||||
void PrepareProviderConfig()
|
||||
{
|
||||
//
|
||||
// XCT ...
|
||||
// Candle Timing ...
|
||||
mProviderConfig.xctConfig.clr = clrBlueViolet;
|
||||
mProviderConfig.xctConfig.corner = CORNER_RIGHT_UPPER;
|
||||
mProviderConfig.xctConfig.showCandleTime = true;
|
||||
|
||||
//
|
||||
// XCC ...
|
||||
// Candle Styling ...
|
||||
mProviderConfig.xccConfig.upColor = clrLime;
|
||||
mProviderConfig.xccConfig.downColor = clrRed;
|
||||
mProviderConfig.xccConfig.lineColor = clrLime;
|
||||
mProviderConfig.xccConfig.bearishColor = clrRed;
|
||||
mProviderConfig.xccConfig.bullishColor = clrLime;
|
||||
mProviderConfig.xccConfig.volumesColor = clrGreen;
|
||||
mProviderConfig.xccConfig.showCandles = true;
|
||||
|
||||
//
|
||||
// XHK ...
|
||||
// HikenAshi Candle Representing ...
|
||||
mProviderConfig.xhkConfig.drawCandleLines = false;
|
||||
|
||||
//
|
||||
// XTM ...
|
||||
// Trend Magic ...
|
||||
mProviderConfig.xtmConfig.length = 35;
|
||||
mProviderConfig.xtmConfig.shift = 0;
|
||||
mProviderConfig.xtmConfig.method = MODE_SMA;
|
||||
mProviderConfig.xtmConfig.appliedTo = PRICE_LOW;
|
||||
mProviderConfig.xtmConfig.showLine = false;
|
||||
|
||||
//
|
||||
// XPV ...
|
||||
// Peaks And Vales ...
|
||||
mProviderConfig.xpvConfig.shortLength = 9;
|
||||
mProviderConfig.xpvConfig.mediumLength = 17;
|
||||
mProviderConfig.xpvConfig.longLength = 26;
|
||||
mProviderConfig.xpvConfig.hindLength = 35;
|
||||
mProviderConfig.xpvConfig.fiboLevel1 = 0.382;
|
||||
mProviderConfig.xpvConfig.fiboLevel2 = 0.5;
|
||||
mProviderConfig.xpvConfig.fiboLevel3 = 0.618;
|
||||
mProviderConfig.xpvConfig.hhMode = MODE_HIGH;
|
||||
mProviderConfig.xpvConfig.llMode = MODE_LOW;
|
||||
mProviderConfig.xpvConfig.showPeaksAndVales = false;
|
||||
mProviderConfig.xpvConfig.showLevels = false;
|
||||
mProviderConfig.xpvConfig.showFibo1Levels = false;
|
||||
mProviderConfig.xpvConfig.showFibo2Levels = false;
|
||||
mProviderConfig.xpvConfig.showFibo3Levels = false;
|
||||
|
||||
//
|
||||
// XAMA ...
|
||||
// Adaptive Moving Average ...
|
||||
mProviderConfig.xamaConfig.length = 52;
|
||||
mProviderConfig.xamaConfig.fastEMA = 2;
|
||||
mProviderConfig.xamaConfig.slowEMA = 30;
|
||||
mProviderConfig.xamaConfig.maShift = 0;
|
||||
mProviderConfig.xamaConfig.appliedTo = PRICE_LOW;
|
||||
mProviderConfig.xamaConfig.showLine = false;
|
||||
|
||||
//
|
||||
// XMRB ...
|
||||
// Moving Average Ribbon ...
|
||||
mProviderConfig.xmrbConfig.fast1Length = 3;
|
||||
mProviderConfig.xmrbConfig.slow1Length = 5;
|
||||
mProviderConfig.xmrbConfig.fast2Length = 8;
|
||||
mProviderConfig.xmrbConfig.slow2Length = 13;
|
||||
mProviderConfig.xmrbConfig.fast3Length = 21;
|
||||
mProviderConfig.xmrbConfig.slow3Length = 34;
|
||||
mProviderConfig.xmrbConfig.fast4Length = 55;
|
||||
mProviderConfig.xmrbConfig.slow4Length = 89;
|
||||
mProviderConfig.xmrbConfig.fast5Length = 144;
|
||||
mProviderConfig.xmrbConfig.slow5Length = 233;
|
||||
mProviderConfig.xmrbConfig.ribbonMode = MODE_EMA;
|
||||
mProviderConfig.xmrbConfig.ribbonAppliedTo = PRICE_CLOSE;
|
||||
mProviderConfig.xmrbConfig.showFastMa = false;
|
||||
mProviderConfig.xmrbConfig.showSlowMa = false;
|
||||
mProviderConfig.xmrbConfig.showRibbon = false;
|
||||
|
||||
//
|
||||
// XCHE ...
|
||||
// Chandelier Exit Points ...
|
||||
mProviderConfig.xcheConfig.length = 35;
|
||||
mProviderConfig.xcheConfig.loopback = 26;
|
||||
mProviderConfig.xcheConfig.multiplier1 = 3;
|
||||
mProviderConfig.xcheConfig.multiplier2 = 3.5;
|
||||
mProviderConfig.xcheConfig.upAppliedTo = PRICE_HIGH;
|
||||
mProviderConfig.xcheConfig.downAppliedTo = PRICE_LOW;
|
||||
mProviderConfig.xcheConfig.showLongExit1Line = false;
|
||||
mProviderConfig.xcheConfig.showShortExit1Line = false;
|
||||
mProviderConfig.xcheConfig.showLongExit2Line = false;
|
||||
mProviderConfig.xcheConfig.showShortExit2Line = false;
|
||||
|
||||
//
|
||||
// XICH ...
|
||||
// Ichimopku Kinko Hyo ...
|
||||
mProviderConfig.xichConfig.tenkanSenLength = 9;
|
||||
mProviderConfig.xichConfig.tenkanSenMode = X_XICH_HH_LL_MODE;
|
||||
mProviderConfig.xichConfig.kijunSenLength = 26;
|
||||
mProviderConfig.xichConfig.kijunSenMode = X_XICH_HH_LL_MODE;
|
||||
mProviderConfig.xichConfig.senkouSpanBLength = 52;
|
||||
mProviderConfig.xichConfig.senkouSpanBMode = X_XICH_HH_LL_MODE;
|
||||
mProviderConfig.xichConfig.chikuoSpanAppliedTo = PRICE_CLOSE;
|
||||
mProviderConfig.xichConfig.showTenkanSen = false;
|
||||
mProviderConfig.xichConfig.showKijunSen = false;
|
||||
mProviderConfig.xichConfig.showKijunSenPlus = false;
|
||||
mProviderConfig.xichConfig.showKijunSenNegative = false;
|
||||
mProviderConfig.xichConfig.showChikouSpan = false;
|
||||
mProviderConfig.xichConfig.showSenkouSpanA = false;
|
||||
mProviderConfig.xichConfig.showSenkouSpanB = false;
|
||||
mProviderConfig.xichConfig.showKumo = false;
|
||||
mProviderConfig.xichConfig.shiftKumo = true;
|
||||
|
||||
//
|
||||
// XTRND ...
|
||||
// Trend Detector ...
|
||||
mProviderConfig.xtrndConfig.cycleLength = 2;
|
||||
mProviderConfig.xtrndConfig.numberOfVerifications = 2;
|
||||
mProviderConfig.xtrndConfig.hhMode = MODE_HIGH;
|
||||
mProviderConfig.xtrndConfig.llMode = MODE_LOW;
|
||||
mProviderConfig.xtrndConfig.l1Method = X_PERIOD_AUTO;
|
||||
mProviderConfig.xtrndConfig.l1Period = NULL;
|
||||
mProviderConfig.xtrndConfig.l2Method = X_PERIOD_AUTO;
|
||||
mProviderConfig.xtrndConfig.l2Period = NULL;
|
||||
mProviderConfig.xtrndConfig.l3Method = X_PERIOD_AUTO;
|
||||
mProviderConfig.xtrndConfig.l3Period = NULL;
|
||||
mProviderConfig.xtrndConfig.showConsolidations = false;
|
||||
mProviderConfig.xtrndConfig.showTrend = false;
|
||||
mProviderConfig.xtrndConfig.showL1Trend = false;
|
||||
mProviderConfig.xtrndConfig.showL2Trend = false;
|
||||
mProviderConfig.xtrndConfig.showL3Trend = false;
|
||||
|
||||
//
|
||||
// XSSLC ...
|
||||
// SSL Channel ...
|
||||
mProviderConfig.xsslcConfig.length = 36;
|
||||
mProviderConfig.xsslcConfig.method = MODE_SMA;
|
||||
mProviderConfig.xsslcConfig.upAppliedTo = PRICE_HIGH;
|
||||
mProviderConfig.xsslcConfig.downAppliedTo = PRICE_LOW;
|
||||
mProviderConfig.xsslcConfig.showUp = false;
|
||||
mProviderConfig.xsslcConfig.showDown = false;
|
||||
|
||||
//
|
||||
// XHULL ...
|
||||
// Hull Trend Detection Channel ...
|
||||
mProviderConfig.xhullConfig.length = 72;
|
||||
mProviderConfig.xhullConfig.divisor = 2;
|
||||
mProviderConfig.xhullConfig.upAppliedTo = PRICE_HIGH;
|
||||
mProviderConfig.xhullConfig.downAppliedTo = PRICE_LOW;
|
||||
mProviderConfig.xhullConfig.showUpZone = false;
|
||||
mProviderConfig.xhullConfig.showDownZone = false;
|
||||
|
||||
//
|
||||
// Default Configs For Different States ...
|
||||
bool showPV = true;
|
||||
bool showHK = true;
|
||||
bool showCHE = true;
|
||||
bool showTRND = true;
|
||||
bool simpleIchi = true;
|
||||
|
||||
//
|
||||
if (showHK)
|
||||
{
|
||||
//
|
||||
// Hiken Ashi ...
|
||||
mProviderConfig.xccConfig.showCandles = false;
|
||||
mProviderConfig.xhkConfig.drawCandles = true;
|
||||
}
|
||||
if (showPV)
|
||||
{
|
||||
//
|
||||
// Peaks and Vales ...
|
||||
mProviderConfig.xpvConfig.showFibo1Levels = true;
|
||||
mProviderConfig.xpvConfig.showFibo2Levels = true;
|
||||
mProviderConfig.xpvConfig.showFibo3Levels = true;
|
||||
mProviderConfig.xpvConfig.showPeaksAndVales = true;
|
||||
}
|
||||
if (simpleIchi)
|
||||
{
|
||||
//
|
||||
// Simple Ichimoku Kinko Hyo ...
|
||||
mProviderConfig.xichConfig.showKijunSen = true;
|
||||
mProviderConfig.xichConfig.showTenkanSen = true;
|
||||
mProviderConfig.xichConfig.showSenkouSpanA = true;
|
||||
mProviderConfig.xichConfig.showSenkouSpanB = true;
|
||||
}
|
||||
if (showCHE)
|
||||
{
|
||||
//
|
||||
// Chandelier Exit ...
|
||||
mProviderConfig.xcheConfig.showLongExit1Line = true;
|
||||
mProviderConfig.xcheConfig.showLongExit2Line = true;
|
||||
mProviderConfig.xcheConfig.showShortExit1Line = true;
|
||||
mProviderConfig.xcheConfig.showShortExit2Line = true;
|
||||
}
|
||||
if (showTRND)
|
||||
{
|
||||
//
|
||||
// Show Trend ...
|
||||
mProviderConfig.xtrndConfig.showL1Trend = true;
|
||||
mProviderConfig.xtrndConfig.showL2Trend = true;
|
||||
mProviderConfig.xtrndConfig.showL3Trend = true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize X121Provider ...
|
||||
void InitProvider()
|
||||
{
|
||||
//
|
||||
PrepareProviderConfig();
|
||||
|
||||
//
|
||||
mProvider = new XSCX121Provider(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
|
||||
//
|
||||
if (mOnSignalConditions != NULL)
|
||||
{
|
||||
//
|
||||
// Attach Event Handlers ...
|
||||
mProvider.AddOnSignalConditionEventHandler(mOnSignalConditions);
|
||||
}
|
||||
|
||||
//
|
||||
// Initialize Provider ...
|
||||
mProvider.SetConfig(mProviderConfig);
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,398 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCAccount
|
||||
// Description: provides all Account requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include <Trade/AccountInfo.mqh>
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Manage Account ...
|
||||
class XSCAccount
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCAccount()
|
||||
{
|
||||
//
|
||||
mAccountInfo = new CAccountInfo();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCAccount()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// User Account ...
|
||||
long GetUserAccount()
|
||||
{
|
||||
return mAccountInfo.Login();
|
||||
}
|
||||
|
||||
//
|
||||
// Account Leverage ...
|
||||
long GetLeverage()
|
||||
{
|
||||
return mAccountInfo.Leverage();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Trade Expert State ...
|
||||
bool CanExpertTrade()
|
||||
{
|
||||
return mAccountInfo.TradeExpert();
|
||||
}
|
||||
|
||||
//
|
||||
// User Account Trade Mopde (ENUM_ACCOUNT_TRADE_MODE) ...
|
||||
// --------------------------
|
||||
// ACCOUNT_TRADE_MODE_DEMO
|
||||
// ACCOUNT_TRADE_MODE_CONTEST
|
||||
// ACCOUNT_TRADE_MODE_REAL
|
||||
ENUM_ACCOUNT_TRADE_MODE GetTradeMode()
|
||||
{
|
||||
return mAccountInfo.TradeMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Get Account Balance ...
|
||||
double GetBalance()
|
||||
{
|
||||
return mAccountInfo.Balance();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of give Credit ...
|
||||
double GetCredit()
|
||||
{
|
||||
return mAccountInfo.Credit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Profit on account ...
|
||||
double GetProfit()
|
||||
{
|
||||
return mAccountInfo.Profit();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of current Equity on account ...
|
||||
double GetEquity()
|
||||
{
|
||||
return mAccountInfo.Equity();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of reserved Margin ...
|
||||
double GetMargin()
|
||||
{
|
||||
return mAccountInfo.Margin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the amount of free Margin ...
|
||||
double GetFreeMargin()
|
||||
{
|
||||
return mAccountInfo.FreeMargin();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin ...
|
||||
double GetMarginLevel()
|
||||
{
|
||||
return mAccountInfo.MarginLevel();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level Of Margin for a Deposit ...
|
||||
double GetMarginCall()
|
||||
{
|
||||
return mAccountInfo.MarginCall();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Level of Margin for Stop out ...
|
||||
double GetMarginStopOut()
|
||||
{
|
||||
return mAccountInfo.MarginStopOut();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Client Name ...
|
||||
string GetName()
|
||||
{
|
||||
return mAccountInfo.Name();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Trade Server Name ...
|
||||
string GetServerName()
|
||||
{
|
||||
return mAccountInfo.Server();
|
||||
}
|
||||
|
||||
//
|
||||
// Get deposit Currency Name ...
|
||||
string GetCurrency()
|
||||
{
|
||||
return mAccountInfo.Currency();
|
||||
}
|
||||
|
||||
//
|
||||
// Get the Company Name that serves an Account ...
|
||||
string GetCompany()
|
||||
{
|
||||
return mAccountInfo.Company();
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Profits for the current account based on passed parameters ...
|
||||
double CalculateTradeProfit(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry, // open price
|
||||
double exit // close price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.OrderProfitCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry,
|
||||
exit);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of margin which required for trade operation ...
|
||||
double CalculateMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate amount of free margin left after trade operation ...
|
||||
double CalculateFreeMarging(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double volume, // volume
|
||||
double entry // open price
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.FreeMarginCheck(
|
||||
symbol,
|
||||
type,
|
||||
volume,
|
||||
entry);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate the Maximum possible volume of trade operation ...
|
||||
double CalculateMaxVolume(
|
||||
const string symbol, // trading symbol
|
||||
ENUM_ORDER_TYPE type, // order type
|
||||
double entry, // open price
|
||||
double percent = 100 // percent of available margin
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = mAccountInfo.MaxLotCheck(
|
||||
symbol,
|
||||
type,
|
||||
entry,
|
||||
percent);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Point Value for Given Symbol based on Account ...
|
||||
double GetPointValue(
|
||||
string symbol // trading symbol
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double tickSize = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_SIZE);
|
||||
double tickValue = SymbolInfoDouble(symbol, SYMBOL_TRADE_TICK_VALUE);
|
||||
double point = SymbolInfoDouble(symbol, SYMBOL_POINT);
|
||||
|
||||
//
|
||||
double ticksPerPoint = tickSize / point;
|
||||
|
||||
//
|
||||
result = tickValue / ticksPerPoint;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Amount based on account Currency by Providing:
|
||||
// Points and Volume ...
|
||||
double CalculateRiskAmount(
|
||||
string symbol, // trading symbol
|
||||
double points, // amount of Risk Points
|
||||
double volume // position Volume
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = pointValue * volume * points;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Risk Points based on account Currency by Providing:
|
||||
// Volume and Amount ...
|
||||
double CalculateRiskPoints(
|
||||
string symbol, // trading symbol
|
||||
double volume, // position Volume
|
||||
double amount // amount of Risk based on Account Currency
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * volume);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate Volume based on account Currency by Providing:
|
||||
// Amount and Risk Points ...
|
||||
double CalculateVolume(
|
||||
string symbol, // trading symbol
|
||||
double amount, // amount of Risk based on Account Currency
|
||||
double points // amount of Risk Points
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = 0;
|
||||
|
||||
//
|
||||
points =
|
||||
points <= 0
|
||||
? 10
|
||||
: points;
|
||||
|
||||
//
|
||||
double pointValue = GetPointValue(symbol);
|
||||
|
||||
//
|
||||
result = amount / (pointValue * points);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Account Info ...
|
||||
CAccountInfo mAccountInfo;
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -0,0 +1,814 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseEA
|
||||
// Description: provides all Base EA requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.alert.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
#include "../Classes/x-saherelm.xtrade.class.mq5"
|
||||
#include "../Classes/x-saherelm.xaccount.class.mq5"
|
||||
#include "../Classes/x-saherelm.xprovider.class.mq5"
|
||||
#include "../Libraries/x-saherelm.seriallizer.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCBaseEA
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
XSCTrade *mTrader;
|
||||
XSCAccount *mAccount;
|
||||
|
||||
//
|
||||
bool isNewHour;
|
||||
bool isNewDay;
|
||||
bool isNewWeek;
|
||||
bool isNewMonth;
|
||||
bool isNewCandle;
|
||||
|
||||
//
|
||||
bool isInTestMode;
|
||||
|
||||
//
|
||||
bool mWaitsUntilNewCandle;
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCBaseEA(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period, // Trading Time Frame
|
||||
ulong magic, // Magic Number
|
||||
int slippage, // Slippgae
|
||||
OnStopLoss onStopLossTriggered = NULL, // On StopLoass Triggered Event Handler
|
||||
OnTakeProfit onTakeProfitTriggered = NULL, // On TakeProfit Triggered Event Handler
|
||||
OnDealsChanged onDealsChangedHandler = NULL, // On Deals Changed Event Handler
|
||||
OnOrdersChanged onOrdersChangedHandler = NULL, // On Orders Changed Event Handler
|
||||
OnPositionsChanged onPositionsChangedHandler = NULL, // On Positions Changed Event Handler
|
||||
OnTradeStateChanged onTradeStateChangedHandler = NULL // On Trade State Changed Event Handler
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mMagic = magic;
|
||||
mSlippage = slippage;
|
||||
|
||||
//
|
||||
mOnStopLossTriggered = onStopLossTriggered;
|
||||
mOnTakeProfitTriggered = onTakeProfitTriggered;
|
||||
mOnDealsChangedHandler = onDealsChangedHandler;
|
||||
mOnOrdersChangedHandler = onOrdersChangedHandler;
|
||||
mOnPositionsChangedHandler = onPositionsChangedHandler;
|
||||
mOnTradeStateChangedHandler = onTradeStateChangedHandler;
|
||||
|
||||
//
|
||||
// Reset Timings ...
|
||||
ResetTiming();
|
||||
|
||||
//
|
||||
InitRequirements();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCBaseEA()
|
||||
{
|
||||
//
|
||||
delete mTrader;
|
||||
delete mAccount;
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Tag ...
|
||||
string GetTag()
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
|
||||
//
|
||||
ulong GetMagic()
|
||||
{
|
||||
return mMagic;
|
||||
}
|
||||
|
||||
//
|
||||
int GetSlippage()
|
||||
{
|
||||
return mSlippage;
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag()
|
||||
{
|
||||
mTag = "XEA" + mSymbol + "," + ToString(mPeriod) + (string)mMagic;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle Chart Events ...
|
||||
virtual void OnChartEvent(
|
||||
const int id, // event ID
|
||||
const long &lparam, // long type event parameter
|
||||
const double &dparam, // double type event parameter
|
||||
const string &sparam // string type event parameter
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Check any Registered Providers Signalling ...
|
||||
virtual bool SignalCheck(XSignal &signals[]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for any Custom Guard Actions Guard Actions ...
|
||||
virtual bool CheckGuard(XGuard &guards[]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// NOTE: you have to call these Functions on Static Classes to Handle Works ...
|
||||
|
||||
//
|
||||
// Handle StopLoss Event ...
|
||||
virtual void OnStopLossTriggered(const XDeal &deal) {}
|
||||
|
||||
//
|
||||
// Handle TakeProfit Event ...
|
||||
virtual void OnTakeProfitTriggered(const XDeal &deal) {}
|
||||
|
||||
//
|
||||
// Handle Deals Changed Event ...
|
||||
virtual void OnDealsChangedHandler(int count) {}
|
||||
|
||||
//
|
||||
// Handle Order Changed Event ...
|
||||
virtual void OnOrdersChangedHandler(int count) {}
|
||||
|
||||
//
|
||||
// Handle Position Changed Event ...
|
||||
virtual void OnPositionsChangedHandler(int count) {}
|
||||
|
||||
//
|
||||
// Handle Trade State Changed ...
|
||||
virtual void OnTradeStateChangedHandler(const XOnTradeHandlerState &state) {}
|
||||
|
||||
//
|
||||
// Implemented Actions ...
|
||||
|
||||
//
|
||||
// OnTick Handler ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
// First Check Guards ....
|
||||
XGuard guards[];
|
||||
bool hasGuard = CheckGuard(guards);
|
||||
if (hasGuard) {
|
||||
DoGuards(guards);
|
||||
}
|
||||
|
||||
//
|
||||
XSignal signals[];
|
||||
bool hasSignal = SignalCheck(signals);
|
||||
if (hasSignal) {
|
||||
mTrader.ExecuteSignals(signals);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Trade ...
|
||||
void OnTrade()
|
||||
{
|
||||
//
|
||||
XOnTradeHandlerState state = mTrader.HandleOnTrade();
|
||||
|
||||
//
|
||||
if (
|
||||
!state.hasNewDeal &&
|
||||
!state.hasNewOrder &&
|
||||
!state.hasNewPosition &&
|
||||
!state.hasNewHistoryOrder)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// STATE ...
|
||||
|
||||
//
|
||||
// Notfy Trade State Changed Event ...
|
||||
OnTradeStateChangedHandler(state);
|
||||
|
||||
//
|
||||
// DEALS ...
|
||||
if (state.hasNewDeal)
|
||||
{
|
||||
//
|
||||
// Notfy Deals Changed Event ...
|
||||
OnDealsChangedHandler(state.newDeals);
|
||||
|
||||
//
|
||||
// Retrieve Last Deal ...
|
||||
XDeal deals[];
|
||||
mTrader.GetDeals(deals);
|
||||
int dealsCount = ArraySize(deals);
|
||||
if (dealsCount > 0)
|
||||
{
|
||||
//
|
||||
XDeal lastDeal = deals[0];
|
||||
|
||||
//
|
||||
if (lastDeal.reason == DEAL_REASON_TP)
|
||||
{
|
||||
OnTakeProfitTriggered(lastDeal);
|
||||
}
|
||||
else if (lastDeal.reason == DEAL_REASON_SL)
|
||||
{
|
||||
OnStopLossTriggered(lastDeal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// ORDERS ...
|
||||
if (state.hasNewOrder || state.hasNewHistoryOrder)
|
||||
{
|
||||
//
|
||||
// Notfy Orders Changed Event ...
|
||||
OnOrdersChangedHandler(state.newOrders + state.newHistoryOrders);
|
||||
}
|
||||
|
||||
//
|
||||
// POSITIONS ...
|
||||
if (state.hasNewPosition)
|
||||
{
|
||||
//
|
||||
// Notfy Positions Changed Event ...
|
||||
OnPositionsChangedHandler(state.newPositions);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Dept Of Market ...
|
||||
void OnBookEvent(const string &symbol)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// TOOLS ...
|
||||
//
|
||||
void GetPositions(
|
||||
XPosition &result[], // Hold Result ...
|
||||
string symbol = NULL, // Trading Symbol ...
|
||||
ENUM_POSITION_TYPE type = NULL, // Trading Type ...
|
||||
ENUM_TIMEFRAMES period = NULL // Trading Period ...
|
||||
)
|
||||
{
|
||||
//
|
||||
Clean(result);
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.PositionsCount();
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
mTrader.GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
period);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (type == NULL)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
result,
|
||||
ArraySize(positions));
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
positions[i],
|
||||
result);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
if (type == NULL || iPosition.type == type)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iPosition,
|
||||
result);
|
||||
}
|
||||
}
|
||||
}
|
||||
void GetPositions(
|
||||
XPosition &result[], // Hold Result ...
|
||||
string symbol = NULL, // Trading Symbol ...
|
||||
ENUM_POSITION_TYPE type = NULL, // Trading Type ...
|
||||
ENUM_TIMEFRAMES period = NULL, // Trading Period ...
|
||||
string provider = NULL // Signal Provider ...
|
||||
)
|
||||
{
|
||||
//
|
||||
Clean(result);
|
||||
|
||||
//
|
||||
bool hasSymbol = !(symbol == NULL || StringLen(symbol) == 0);
|
||||
bool hasProvider = !(provider == NULL || StringLen(provider) == 0);
|
||||
|
||||
//
|
||||
int positionsCount = mTrader.PositionsCount();
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
XPosition positions[];
|
||||
mTrader.GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
period);
|
||||
positionsCount = ArraySize(positions);
|
||||
if (positionsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (!hasProvider && type == NULL)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
result,
|
||||
ArraySize(positions));
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
positions[i],
|
||||
result);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
if (type == NULL)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
result,
|
||||
ArraySize(positions));
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
positions[i],
|
||||
result);
|
||||
}
|
||||
|
||||
//
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < positionsCount; i++)
|
||||
{
|
||||
//
|
||||
XPosition iPosition = positions[i];
|
||||
|
||||
//
|
||||
string iProvider = ExtractProvider(iPosition.comment);
|
||||
if (hasProvider && iProvider != provider)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
//
|
||||
if (type == NULL || iPosition.type == type)
|
||||
{
|
||||
//
|
||||
Add(
|
||||
iPosition,
|
||||
result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// GUARD Handlers ...
|
||||
|
||||
//
|
||||
// Parse Recievd Guards and Do them ...
|
||||
void DoGuards(XGuard &guards[])
|
||||
{
|
||||
int guardsCount = ArraySize(guards);
|
||||
if (guardsCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < guardsCount; i++)
|
||||
{
|
||||
//
|
||||
XGuard iGuard = guards[i];
|
||||
|
||||
//
|
||||
switch (iGuard.action)
|
||||
{
|
||||
//
|
||||
// Hedge In Profit Specified Positions ...
|
||||
case X_GUARD_ACTION_HEDGE:
|
||||
HandleGuardHedgeAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
|
||||
//
|
||||
// Trail Stop Loss in Specified Positions ...
|
||||
case X_GUARD_ACTION_TRAIL_STOP:
|
||||
HandleGuardTrailingStopAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period,
|
||||
iGuard.dblPayLoad);
|
||||
break;
|
||||
|
||||
//
|
||||
// Force Close Specified Positions ...
|
||||
case X_GUARD_ACTION_FORCE_CLOSE:
|
||||
HandleGuardForceCloseAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
|
||||
//
|
||||
// Generate and Place Support Signals ...
|
||||
case X_GUARD_ACTION_ADD_SUPPORT_SIGNAL:
|
||||
HandleGuardAddSupportPositionAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
|
||||
//
|
||||
// Delete All Placed Pending Orders ...
|
||||
case X_GUARD_ACTION_CANCEL_PENDING_ORDERS:
|
||||
HandleGuardCancelPendingOrdersAction(
|
||||
iGuard.provider,
|
||||
iGuard.symbol,
|
||||
iGuard.type,
|
||||
iGuard.period);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Close All Specified Provider's Positions in Profit Summary ...
|
||||
void HandleGuardHedgeAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period, // Specified Time Frame
|
||||
double minProfitForHedging = 1 // Specified Profit for Hedge ...
|
||||
)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
//
|
||||
// Force Close Specified Set Of Position ...
|
||||
void HandleGuardForceCloseAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period, // Specified Time Frame
|
||||
ulong ticket = 0 // Specific Ticket
|
||||
)
|
||||
{
|
||||
//
|
||||
string comment = "";
|
||||
|
||||
//
|
||||
// Close All Positions ...
|
||||
if (ticket == 0)
|
||||
{
|
||||
//
|
||||
XPosition positions[];
|
||||
GetPositions(
|
||||
positions,
|
||||
symbol,
|
||||
type,
|
||||
period,
|
||||
provider);
|
||||
if (ArraySize(positions) <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
comment = provider + " Force Close Guard ...";
|
||||
|
||||
//
|
||||
mTrader.ClosePositions(
|
||||
positions,
|
||||
comment);
|
||||
}
|
||||
//
|
||||
// Close Specific Position ...
|
||||
else
|
||||
{
|
||||
//
|
||||
XPosition position;
|
||||
bool hasPosition = mTrader.GetPosition(
|
||||
position,
|
||||
ticket);
|
||||
|
||||
//
|
||||
if (hasPosition)
|
||||
{
|
||||
//
|
||||
comment = provider + "(" + ToString(ticket) + ")" + " Force Close Guard ...";
|
||||
|
||||
//
|
||||
mTrader.Close(
|
||||
ticket,
|
||||
comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (StringLen(comment) > 0)
|
||||
{
|
||||
LogMessage(comment);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Trailing Specified Set Of Positions Stop Losses ...
|
||||
void HandleGuardTrailingStopAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period, // Specified Time Frame
|
||||
double sl // Desired SL Value ...
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Add Support Signal for Specified Positions ...
|
||||
void HandleGuardAddSupportPositionAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period // Specified Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// Cancel all Placed Orders ...
|
||||
void HandleGuardCancelPendingOrdersAction(
|
||||
string provider, // Positions Provided by Specific Provider
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_POSITION_TYPE type, // Trading Type
|
||||
ENUM_TIMEFRAMES period // Specified Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string GetTagPrefix()
|
||||
{
|
||||
//
|
||||
string result = "(" + mSymbol + ")(" + ToString(mPeriod) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// ExpertAdviser MAgic Number ...
|
||||
ulong mMagic;
|
||||
|
||||
//
|
||||
// Slipppage ...
|
||||
int mSlippage;
|
||||
|
||||
//
|
||||
// Tag Identifier ...
|
||||
string mTag;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Define Requirements ...
|
||||
|
||||
//
|
||||
// XSCTrade Event Handlers ...
|
||||
OnStopLoss mOnStopLossTriggered;
|
||||
OnTakeProfit mOnTakeProfitTriggered;
|
||||
OnDealsChanged mOnDealsChangedHandler;
|
||||
OnOrdersChanged mOnOrdersChangedHandler;
|
||||
OnPositionsChanged mOnPositionsChangedHandler;
|
||||
OnTradeStateChanged mOnTradeStateChangedHandler;
|
||||
|
||||
//
|
||||
// Initi Requirements ...
|
||||
void InitRequirements()
|
||||
{
|
||||
//
|
||||
// Account Manager ...
|
||||
mAccount = new XSCAccount();
|
||||
|
||||
//
|
||||
// Trader ...
|
||||
mTrader = new XSCTrade(
|
||||
mSlippage,
|
||||
mMagic);
|
||||
|
||||
//
|
||||
// Attach Event Handlers ...
|
||||
|
||||
//
|
||||
if (mOnStopLossTriggered != NULL)
|
||||
{
|
||||
mTrader.AddOnStopLossEventHandler(mOnStopLossTriggered);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnTakeProfitTriggered != NULL)
|
||||
{
|
||||
mTrader.AddOnTakeProfitEventHandler(mOnTakeProfitTriggered);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnDealsChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnDealsChangedEventHandler(mOnDealsChangedHandler);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnOrdersChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnOrdersChangedEventHandler(mOnOrdersChangedHandler);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnPositionsChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnPositionsChangedEventHandler(mOnPositionsChangedHandler);
|
||||
}
|
||||
|
||||
//
|
||||
if (mOnTradeStateChangedHandler != NULL)
|
||||
{
|
||||
mTrader.AddOnTradeStateChangedEventHandler(mOnTradeStateChangedHandler);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,209 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCBaseHelper
|
||||
// Description: provides all Base Indicator
|
||||
// Helper requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCBaseHelper
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCBaseHelper(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading Time Frame
|
||||
)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
LoopBack(52);
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCBaseHelper()
|
||||
{
|
||||
IndicatorRelease(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// Loopback Bars ...
|
||||
void LoopBack(int value)
|
||||
{
|
||||
mLoopbackBars = value;
|
||||
}
|
||||
|
||||
int Loopback()
|
||||
{
|
||||
return mLoopbackBars;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string GetSymbol()
|
||||
{
|
||||
return mSymbol;
|
||||
}
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES GetPeriod()
|
||||
{
|
||||
return mPeriod;
|
||||
}
|
||||
|
||||
//
|
||||
// Tag ...
|
||||
string GetTag()
|
||||
{
|
||||
return mTag;
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Bars ...
|
||||
int GetBars()
|
||||
{
|
||||
//
|
||||
int result =
|
||||
Bars(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int GetCalculatedBars()
|
||||
{
|
||||
return BarsCalculated(mHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Prepare Tag ...
|
||||
virtual void PrepareTag() {}
|
||||
|
||||
//
|
||||
// Reading Buffers based on Given Bar Index ...
|
||||
virtual void Calculate(
|
||||
int barIndex // Given Bar Index
|
||||
);
|
||||
|
||||
//
|
||||
// Retrieve MAx Required Length for Calculations ...
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string GetTagPrefix()
|
||||
{
|
||||
//
|
||||
string result = "(" + mSymbol + ")(" + ToString(mPeriod) + ")";
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Symbol ...
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
// Period ...
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
// Indicator Handler ...
|
||||
int mHandler;
|
||||
|
||||
//
|
||||
// Number Of Items Read Per Tick ...
|
||||
int mLoopbackBars;
|
||||
|
||||
//
|
||||
// Tag Identifier ...
|
||||
string mTag;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,295 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCNotifier
|
||||
// Description: provides all Base Notification requirements ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Notification Model ...
|
||||
typedef void (*OnMessage)(
|
||||
string, // action ...
|
||||
string // payload ...
|
||||
);
|
||||
|
||||
//
|
||||
struct XNotifierEventListener
|
||||
{
|
||||
string action;
|
||||
OnMessage listeners[];
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Class for Handle base requirements ...
|
||||
// for indicators ...
|
||||
class XSCNotifier
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCNotifier()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// START Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Properties ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Provided Functions ...
|
||||
//
|
||||
bool AddEventListener(
|
||||
string action, // Specific Action ...
|
||||
OnMessage listener // Specific Listener ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int aIndex = FindActionIndex(action);
|
||||
if (aIndex < 0)
|
||||
{
|
||||
//
|
||||
// Create a New Structure ...
|
||||
XNotifierEventListener model;
|
||||
|
||||
//
|
||||
model.action = action;
|
||||
|
||||
//
|
||||
Add(
|
||||
listener,
|
||||
model.listeners);
|
||||
|
||||
//
|
||||
Add(
|
||||
model,
|
||||
mEventListeners);
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// Just Add Listener to Exists model ...
|
||||
Add(
|
||||
listener,
|
||||
mEventListeners[aIndex].listeners);
|
||||
|
||||
//
|
||||
result = true;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool NotifyEvent(
|
||||
string action, // action ...
|
||||
string payload // payload ...
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
int actionIndex = FindActionIndex(action);
|
||||
result = actionIndex >= 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int aListenersCount = ArraySize(mEventListeners[actionIndex].listeners);
|
||||
result = aListenersCount > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < aListenersCount; i++)
|
||||
{
|
||||
//
|
||||
OnMessage iListener = mEventListeners[actionIndex].listeners[i];
|
||||
|
||||
//
|
||||
// Call Listener ...
|
||||
iListener(
|
||||
action,
|
||||
payload);
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// END Provided Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
XNotifierEventListener mEventListeners[];
|
||||
|
||||
//
|
||||
// Find Specific Actions Index in Registered Event Listeners ...
|
||||
int FindActionIndex(string action)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
int listenersCount = ArraySize(mEventListeners);
|
||||
if (listenersCount <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < listenersCount; i++)
|
||||
{
|
||||
//
|
||||
XNotifierEventListener iModel = mEventListeners[i];
|
||||
|
||||
//
|
||||
if (iModel.action == action)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
void Clean(
|
||||
OnMessage &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
0);
|
||||
}
|
||||
void Clean(
|
||||
XNotifierEventListener &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayFree(buffer);
|
||||
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
0);
|
||||
}
|
||||
|
||||
//
|
||||
void Add(
|
||||
OnMessage item, // Item ...
|
||||
OnMessage &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
void Add(
|
||||
XNotifierEventListener &item, // Item ...
|
||||
XNotifierEventListener &buffer[] // Buffer ...
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
@@ -0,0 +1,304 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// SaherElm IT Center MQL5 Class Library
|
||||
// ----------------------------------------------
|
||||
// Name: XSCEABaseProvider
|
||||
// Description: provides base requirements for
|
||||
// Specific Sgnal Provider ...
|
||||
//
|
||||
//
|
||||
// Maintainer:
|
||||
// ------------
|
||||
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
||||
//
|
||||
//////////////////////////////////////////////////////
|
||||
//
|
||||
// Global Properties ...
|
||||
#property library
|
||||
#property copyright "Copyright 2023, SaherElm IT Center"
|
||||
#property link "https://www.saherelm.ir"
|
||||
#property version "1.00"
|
||||
#property strict
|
||||
|
||||
//
|
||||
// START Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// Includes ...
|
||||
#include "../Libraries/x-saherelm.log.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.models.lib.mq5"
|
||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||
|
||||
//
|
||||
// END Import and Inclused requirements ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Notified a Signal was Appears ...
|
||||
typedef void (*OnSignal)(
|
||||
XSignal &signal);
|
||||
|
||||
//
|
||||
// Notified a Guard Appears ...
|
||||
typedef void (*OnGuard)(XGuard &guard);
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// END Overrides ...
|
||||
//
|
||||
|
||||
//
|
||||
// a Base Class for All of our EA's ...
|
||||
class XSCEABaseProvider
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Constructor ...
|
||||
void XSCEABaseProvider()
|
||||
{
|
||||
mSymbol = _Symbol;
|
||||
mPeriod = _Period;
|
||||
}
|
||||
void XSCEABaseProvider(
|
||||
string symbol,
|
||||
ENUM_TIMEFRAMES period)
|
||||
{
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mTag = mSymbol + "," + ToString(mPeriod);
|
||||
|
||||
//
|
||||
mIsInTestMode = IsRunningOnTestMode();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCEABaseProvider()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
bool CanIgnoreTick() {
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
bool result = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Prepare State ...
|
||||
void OnTick()
|
||||
{
|
||||
//
|
||||
mIsNewCandle = IsNewCandle(
|
||||
mSymbol,
|
||||
mPeriod);
|
||||
mCanIgnoreTick = mIsInTestMode
|
||||
? !mIsNewCandle
|
||||
: !mIsNewCandle && mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
ProcessBuffers();
|
||||
|
||||
//
|
||||
if (mCanIgnoreTick)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
mWaitUntilNewCandle = false;
|
||||
|
||||
//
|
||||
ProcessTick();
|
||||
}
|
||||
|
||||
//
|
||||
virtual void PrepareTag();
|
||||
|
||||
//
|
||||
// Initialize Indicators and Requirements ...
|
||||
virtual bool Init();
|
||||
|
||||
//
|
||||
virtual int GetMaxLength();
|
||||
|
||||
//
|
||||
virtual int GetCalculatedBars();
|
||||
|
||||
//
|
||||
// Handle Update Buffers ...
|
||||
virtual void ProcessBuffers()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Handle On Tick Event ...
|
||||
virtual void ProcessTick()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Check for Guards ...
|
||||
virtual bool GuardCheck(XGuard &guards[]);
|
||||
|
||||
//
|
||||
// Add Specific On Signal Event Handler ...
|
||||
int AddOnSignalEventHandler(OnSignal handler)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
mSignalEventHandlers,
|
||||
ArraySize(mSignalEventHandlers) + 1);
|
||||
|
||||
//
|
||||
int result = ArraySize(mSignalEventHandlers) - 1;
|
||||
mSignalEventHandlers[result] = handler;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Remove All On Signal Event Handler ...
|
||||
void ReoveOnSignalEventHandlers()
|
||||
{
|
||||
//
|
||||
ArrayFree(mSignalEventHandlers);
|
||||
}
|
||||
|
||||
//
|
||||
// Notify a Signal Found on all Event Listeners ...
|
||||
void NotifyOnSignalEvent(XSignal &info)
|
||||
{
|
||||
//
|
||||
int listenerCount = ArraySize(mSignalEventHandlers);
|
||||
if (listenerCount <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
// Loop Through Listeners ...
|
||||
for (int i = 0; i < listenerCount; i++)
|
||||
{
|
||||
//
|
||||
OnSignal listener = mSignalEventHandlers[i];
|
||||
|
||||
//
|
||||
listener(info);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
string mSymbol;
|
||||
|
||||
//
|
||||
ENUM_TIMEFRAMES mPeriod;
|
||||
|
||||
//
|
||||
string mTag;
|
||||
|
||||
//
|
||||
bool mIsNewCandle;
|
||||
bool mIsInTestMode;
|
||||
bool mCanIgnoreTick;
|
||||
bool mWaitUntilNewCandle;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Signal Event Handlers ...
|
||||
OnSignal mSignalEventHandlers[];
|
||||
};
|
||||
|
||||
//
|
||||
// START Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Model Signal Providers Definitions ...
|
||||
struct XBaseSignalProvider
|
||||
{
|
||||
//
|
||||
// Provider use Which Symbol ...
|
||||
string symbol;
|
||||
|
||||
//
|
||||
// Provider use Which Time Frame ...
|
||||
ENUM_TIMEFRAMES period;
|
||||
|
||||
//
|
||||
// Risk Amount Per Trades Related to Time Frames ...
|
||||
// Percent of Available Balance ...
|
||||
double riskAmount;
|
||||
|
||||
//
|
||||
// Desired Magic Number ...
|
||||
ulong magicNumber;
|
||||
};
|
||||
|
||||
//
|
||||
struct XLastSignal
|
||||
{
|
||||
datetime at;
|
||||
string provider;
|
||||
};
|
||||
|
||||
//
|
||||
// END Definitions ...
|
||||
//
|
||||
|
||||
//
|
||||
// START Usefull Functions ...
|
||||
//
|
||||
|
||||
//
|
||||
// Add Specific Provider to List ...
|
||||
void Add(
|
||||
XBaseSignalProvider &item, // item want to add
|
||||
XBaseSignalProvider &buffer[] // Destination buffer
|
||||
)
|
||||
{
|
||||
//
|
||||
ArrayResize(
|
||||
buffer,
|
||||
ArraySize(buffer) + 1);
|
||||
|
||||
//
|
||||
buffer[ArraySize(buffer) - 1] = item;
|
||||
}
|
||||
|
||||
//
|
||||
// END Usefull Functions ...
|
||||
//
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user