cleanup workspace ...
This commit is contained in:
@@ -1,404 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Class Library
|
|
||||||
// ----------------------------------------------
|
|
||||||
// Name: XSCBaseInd
|
|
||||||
// Description: provides Indicator implementation
|
|
||||||
// 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
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../../Classes/x-saherelm.xind.class.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// XSCMid Indicator Buffers ...
|
|
||||||
enum ENUM_XSCMID_BUFFERS
|
|
||||||
{
|
|
||||||
XSCMID_MAIN_LINE = 0, // Main Buffer ...
|
|
||||||
XSCMID_STATE_LINE = 1, // State Buffer ...
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
string GetTitle(ENUM_XSCMID_BUFFERS bufferLine)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string result = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
switch (bufferLine)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
case XSCMID_MAIN_LINE:
|
|
||||||
result = "XMID";
|
|
||||||
break;
|
|
||||||
|
|
||||||
//
|
|
||||||
case XSCMID_STATE_LINE:
|
|
||||||
result = "XSTATE";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// XSCMid Indicator Inputs ...
|
|
||||||
struct XSCMidInputs
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
string version;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor ...
|
|
||||||
XSCMidInputs()
|
|
||||||
{
|
|
||||||
Clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Initial Inputs ...
|
|
||||||
bool Init()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Cleanup ...
|
|
||||||
void Clean()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Default ...
|
|
||||||
void Default()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
bool IsValid()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
true
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Max Length ...
|
|
||||||
int Max()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// a Simple Indicator ...
|
|
||||||
|
|
||||||
class XSCMid : public XSCBaseInd
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor(s) ...
|
|
||||||
void XSCMid(
|
|
||||||
string symbol, // Trading Symbol
|
|
||||||
ENUM_TIMEFRAMES period // Trading TimeFrame
|
|
||||||
) : XSCBaseInd(symbol, period)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mSymbol = symbol;
|
|
||||||
mPeriod = period;
|
|
||||||
|
|
||||||
//
|
|
||||||
mCalculatedBars = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Deconstructor ...
|
|
||||||
void ~XSCMid() {}
|
|
||||||
//
|
|
||||||
// Initialize Indicator ...
|
|
||||||
bool Init(
|
|
||||||
XSCMidInputs &inputs // Indicator Inputs ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = inputs.IsValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Set Inputs ...
|
|
||||||
this.mInputs = inputs;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Indicator State ...
|
|
||||||
result = this.IsValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Required Buffers ...
|
|
||||||
XBuffer main;
|
|
||||||
string mTitle = GetTitle(XSCMID_MAIN_LINE);
|
|
||||||
result = main.Init(
|
|
||||||
mTitle,
|
|
||||||
mSymbol,
|
|
||||||
mPeriod //
|
|
||||||
);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = SetBuffer(main);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate First Time ...
|
|
||||||
Calculate();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Property Getter(s) / Setter(s) ...
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCMidInputs GetInputs()
|
|
||||||
{
|
|
||||||
return mInputs;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool SetInputs(
|
|
||||||
XSCMidInputs &inputs // Indicator Inputs
|
|
||||||
)
|
|
||||||
{
|
|
||||||
return Init(inputs);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Override(s) ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Tag ...
|
|
||||||
string GetTag() override
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string result = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = GetToken();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Token ...
|
|
||||||
string GetToken() override
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string result = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = GetSpecificToken(this);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
bool IsValidInputs() override
|
|
||||||
{
|
|
||||||
return mInputs.IsValid();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Buffers ...
|
|
||||||
void Calculate() override
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int max = mInputs.Max();
|
|
||||||
int limit = CountLimit();
|
|
||||||
int totalBars = CountBars();
|
|
||||||
int prevCalculated = GetCalculatedBars();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Prepare Buffers Index ...
|
|
||||||
int mainIDX = GetBufferIndexByLine(XSCMID_MAIN_LINE);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Print("Total: ", totalBars, ", prevCalculated: ", prevCalculated, ", Limit: ", limit);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Only Calculate Last Item ...
|
|
||||||
bool onlyLast = false;
|
|
||||||
if (prevCalculated == totalBars - 1)
|
|
||||||
{
|
|
||||||
onlyLast = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int start = totalBars - prevCalculated - 1;
|
|
||||||
for (int i = start; i >= 0; i--)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int barIndex = i - 1;
|
|
||||||
// Print("barIndex: ", barIndex, ", onlyLast: ", onlyLast);
|
|
||||||
if (barIndex < 0 && !onlyLast)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (onlyLast)
|
|
||||||
{
|
|
||||||
barIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
datetime iBarTime = iTime(
|
|
||||||
mSymbol,
|
|
||||||
mPeriod,
|
|
||||||
barIndex - 1
|
|
||||||
//
|
|
||||||
);
|
|
||||||
int iBarIndex = iBarShift(
|
|
||||||
mSymbol,
|
|
||||||
mPeriod,
|
|
||||||
iBarTime //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
double iValue = iClose(mSymbol, mPeriod, iBarIndex);
|
|
||||||
|
|
||||||
//
|
|
||||||
Print("Bar: ", barIndex, ", Bar Time: ", iBarTime, ", Bar Index: ", iBarIndex, ", iValue: ", iValue);
|
|
||||||
if (iValue != 0.0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Print("Bar: ", barIndex, ", Bar Time: ", iBarTime, ", Bar Index: ", iBarIndex, ", iValue: ", iValue);
|
|
||||||
mBuffers[mainIDX].Add(barIndex, iValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Prevent Double Calculation Same Bars ...
|
|
||||||
mCalculatedBars = totalBars - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// De Initialize Class ...
|
|
||||||
void DeInit(int reason)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
int GetBufferIndexByLine(
|
|
||||||
ENUM_XSCMID_BUFFERS bufferLine // Specified Buffer Line
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string mTitle = GetTitle(bufferLine);
|
|
||||||
return GetBufferIndex(mTitle);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool GetBufferByLine(
|
|
||||||
ENUM_XSCMID_BUFFERS bufferLine, // Specified Buffer Line
|
|
||||||
XBuffer &buffer // Hold Result
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string mTitle = GetTitle(bufferLine);
|
|
||||||
return GetBuffer(mTitle, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
// //
|
|
||||||
// double GetBufferValueByLine(
|
|
||||||
// ENUM_XSCMID_BUFFERS bufferLine, // Specified Buffer Line
|
|
||||||
// datetime time = NULL // Time
|
|
||||||
// )
|
|
||||||
// {
|
|
||||||
// //
|
|
||||||
// string mTitle = GetTitle(bufferLine);
|
|
||||||
// return GetBufferValue(mTitle, time);
|
|
||||||
// }
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inputs ...
|
|
||||||
XSCMidInputs mInputs;
|
|
||||||
};
|
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,481 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Class Library
|
|
||||||
// ----------------------------------------------
|
|
||||||
// Name: XSCDataCollector
|
|
||||||
// Description: provides Data Collection 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
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Classes/x-saherelm.base.class.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
template <typename T>
|
|
||||||
class XSCDataCollector : public XSCBase
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructors ...
|
|
||||||
void XSCDataCollector(
|
|
||||||
string path = NULL, // Base Folder for Data Store
|
|
||||||
string fileName = NULL // File Name for Data Store
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (!IsValid(path))
|
|
||||||
{
|
|
||||||
path = GetType();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!IsValid(fileName))
|
|
||||||
{
|
|
||||||
fileName = GetType() + ".txt";
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Path(path);
|
|
||||||
FileName(fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Deconstructor ...
|
|
||||||
void ~XSCDataCollector() {}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Properties ...
|
|
||||||
|
|
||||||
//
|
|
||||||
bool Path(string value)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid(value);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = value != mPath;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
mPath = value;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string Path()
|
|
||||||
{
|
|
||||||
return mPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool FileName(string value)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid(value);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = value != mFileName;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
mFileName = value;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string FileName()
|
|
||||||
{
|
|
||||||
return mFileName;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Clear Exists Collected Data ...
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
ResetLastError();
|
|
||||||
|
|
||||||
//
|
|
||||||
string dataStorePath = GetStorePath();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Data Store Exists or not ...
|
|
||||||
bool isExists = FileIsExist(dataStorePath);
|
|
||||||
if (!isExists)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
FileDelete(dataStorePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Collect All Stored Items ...
|
|
||||||
int Collect(
|
|
||||||
T &items[] // Hold Result
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
Clean(items);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Reading Store Whole Content ...
|
|
||||||
|
|
||||||
//
|
|
||||||
string storePath = GetStorePath();
|
|
||||||
int mFileHandler = FileOpen(
|
|
||||||
storePath,
|
|
||||||
FILE_READ | FILE_TXT);
|
|
||||||
result = mFileHandler != INVALID_HANDLE;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Parse Store Content and Read Data ...
|
|
||||||
while (!FileIsEnding(mFileHandler))
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Each Line Represent One Model ...
|
|
||||||
string content = FileReadString(mFileHandler);
|
|
||||||
|
|
||||||
//
|
|
||||||
T iItem;
|
|
||||||
bool isValid = iItem.ParseModel(content);
|
|
||||||
if (isValid)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
iItem,
|
|
||||||
items
|
|
||||||
//
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Close File ...
|
|
||||||
FileClose(mFileHandler);
|
|
||||||
|
|
||||||
//
|
|
||||||
result = ArraySize(items);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Item ...
|
|
||||||
bool Add(
|
|
||||||
T &item // Item to Store
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = item.IsModelValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string content = item.ToModelString();
|
|
||||||
result = IsValid(content);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string storePath = GetStorePath();
|
|
||||||
int mFileHandler = FileOpen(
|
|
||||||
storePath,
|
|
||||||
FILE_READ | FILE_WRITE | FILE_TXT);
|
|
||||||
result = mFileHandler != INVALID_HANDLE;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
FileSeek(mFileHandler, 0, SEEK_END);
|
|
||||||
FileWrite(mFileHandler, content);
|
|
||||||
FileFlush(mFileHandler);
|
|
||||||
FileClose(mFileHandler);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Item ...
|
|
||||||
bool Add(
|
|
||||||
string content // Content
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid(content);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
string storePath = GetStorePath();
|
|
||||||
int mFileHandler = FileOpen(
|
|
||||||
storePath,
|
|
||||||
FILE_READ | FILE_WRITE | FILE_TXT);
|
|
||||||
result = mFileHandler != INVALID_HANDLE;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
FileSeek(mFileHandler, 0, SEEK_END);
|
|
||||||
FileWrite(mFileHandler, content);
|
|
||||||
FileFlush(mFileHandler);
|
|
||||||
FileClose(mFileHandler);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Items ...
|
|
||||||
int Add(
|
|
||||||
T &items[] // Items to Add ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsCount = ArraySize(items);
|
|
||||||
if (itemsCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < itemsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
T iItem = items[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!iItem.IsModelValid())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isAdded = Add(iItem);
|
|
||||||
if (isAdded)
|
|
||||||
{
|
|
||||||
result++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Remove Item ...
|
|
||||||
bool Remove(
|
|
||||||
T &item // Item to Remove
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = item.IsModelValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
T items[];
|
|
||||||
int itemsCount = Collect(items);
|
|
||||||
if (itemsCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemIndex = item.FindIndex(items);
|
|
||||||
result = ArrayRemove(
|
|
||||||
items,
|
|
||||||
itemIndex,
|
|
||||||
1);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Clear();
|
|
||||||
|
|
||||||
//
|
|
||||||
int itemsAdded = Add(items);
|
|
||||||
|
|
||||||
//
|
|
||||||
result = itemsAdded == ArraySize(items);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Type of Class as String ...
|
|
||||||
string GetType()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string mType = (string) typename(T);
|
|
||||||
|
|
||||||
//
|
|
||||||
string result = mType;
|
|
||||||
|
|
||||||
//
|
|
||||||
string parts[];
|
|
||||||
int partsCount = SplitContent(
|
|
||||||
parts,
|
|
||||||
result,
|
|
||||||
" "
|
|
||||||
//
|
|
||||||
);
|
|
||||||
if (partsCount <= 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = mType;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
bool hasLastPart = GetLastItem(
|
|
||||||
result,
|
|
||||||
parts
|
|
||||||
//
|
|
||||||
);
|
|
||||||
if (!hasLastPart)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = mType;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Pricate ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
string mPath; // Path
|
|
||||||
string mFileName; // Data Store File Name
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Generate Full File Path ...
|
|
||||||
string GetFilePath(string fileName)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string result = "";
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
Path() + "\\" + fileName
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Data Store File Address ...
|
|
||||||
string GetStorePath()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string result = NULL;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = GetFilePath(mFileName);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -819,452 +819,6 @@ struct XPositionTrack
|
|||||||
// Type Definitions for XPosition Tracker Events ...
|
// Type Definitions for XPosition Tracker Events ...
|
||||||
typedef void (*TOnPositionState)(const XPositionTrack &track);
|
typedef void (*TOnPositionState)(const XPositionTrack &track);
|
||||||
|
|
||||||
//
|
|
||||||
// an Struct for Holding Event Handled Items for Position Tracker ...
|
|
||||||
struct XPositionTrackerState
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack inProfits[];
|
|
||||||
XPositionTrack inDrawdowns[];
|
|
||||||
|
|
||||||
//
|
|
||||||
XPositionTrack onProfits[];
|
|
||||||
XPositionTrack onDrawdowns[];
|
|
||||||
|
|
||||||
//
|
|
||||||
XPositionTrackerState()
|
|
||||||
{
|
|
||||||
Clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Cleanup ...
|
|
||||||
void Clean()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Clean(inProfits);
|
|
||||||
Clean(inDrawdowns);
|
|
||||||
|
|
||||||
//
|
|
||||||
Clean(onProfits);
|
|
||||||
Clean(onDrawdowns);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Position Tracker Class ...
|
|
||||||
class XSCPositionTracker
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor ...
|
|
||||||
void XSCPositionTracker(bool cleanStore = false)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XSCDataCollector<XPositionTrack> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (cleanStore)
|
|
||||||
{
|
|
||||||
mBase.Clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Cleaning Store ...
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XSCDataCollector<XPositionTrack> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
mBase.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Collect All Store ...
|
|
||||||
int Collect(XPositionTrack &result[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int mResult = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XPositionTrack> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
mResult = mBase.Collect(result);
|
|
||||||
|
|
||||||
//
|
|
||||||
return mResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Item To Store ...
|
|
||||||
bool Add(XPositionTrack &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XPositionTrack> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBase.Add(item);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Item(s) To Store ...
|
|
||||||
int Add(XPositionTrack &items[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XPositionTrack> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBase.Add(items);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Remove an Item from Store ...
|
|
||||||
bool Remove(XPositionTrack &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XPositionTrack> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBase.Remove(item);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Sync all Content using Specific Trader Class ...
|
|
||||||
int Sync(
|
|
||||||
XPositionTrackerState &state, // Hold all Changes State ...
|
|
||||||
XSCTrade *mTrader // XSCTrade Instance for Synchronize ...
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XPosition positions[];
|
|
||||||
int positionsCount = mTrader.GetPositions(positions);
|
|
||||||
|
|
||||||
//
|
|
||||||
ulong trackTickets[];
|
|
||||||
XPositionTrack trackers[];
|
|
||||||
int trackersCount = Collect(trackers);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Nothing to Do ...
|
|
||||||
if (positionsCount <= 0 && trackersCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Collect Exists Trackers Ticket's For Managing ...
|
|
||||||
for (int i = 0; i < trackersCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack iTrack = trackers[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isValid = iTrack.IsValid();
|
|
||||||
if (isValid)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddSpecific(
|
|
||||||
iTrack.ticket,
|
|
||||||
trackTickets //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Clear Tracker Store for Update Later ...
|
|
||||||
Clear();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Collect All Required to Add/Update Trackers here ...
|
|
||||||
XPositionTrack syncedTracks[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// a Flag for Synchronization Performance ...
|
|
||||||
bool hasTracker = trackersCount > 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Loop through Position for Managing Trackers ...
|
|
||||||
for (int i = 0; i < positionsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPosition iPosition = positions[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
// if there isn't any Track before ...
|
|
||||||
if (!hasTracker)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack iTrack;
|
|
||||||
bool isInited = iTrack.Init(iPosition);
|
|
||||||
if (isInited)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
iTrack,
|
|
||||||
syncedTracks //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
FillState(
|
|
||||||
iTrack,
|
|
||||||
state //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// if there was some tracks ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Try to Find Position Ticket in Track Tickets ...
|
|
||||||
int iTicketIdx = FindIndex(
|
|
||||||
iPosition.ticket,
|
|
||||||
trackTickets //
|
|
||||||
);
|
|
||||||
bool isTrackedBefore = iTicketIdx >= 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add new Track ...
|
|
||||||
if (!isTrackedBefore)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack iTrack;
|
|
||||||
bool isInited = iTrack.Init(iPosition);
|
|
||||||
if (isInited)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
iTrack,
|
|
||||||
syncedTracks //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
FillState(
|
|
||||||
iTrack,
|
|
||||||
state //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//
|
|
||||||
// Update Exists Track ...
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack iTrack = trackers[iTicketIdx];
|
|
||||||
bool isUpdated = iTrack.Update(iPosition);
|
|
||||||
if (isUpdated)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
iTrack,
|
|
||||||
syncedTracks //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
FillState(
|
|
||||||
iTrack,
|
|
||||||
state //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Synced Tracks ...
|
|
||||||
int syncedTracksCount = ArraySize(syncedTracks);
|
|
||||||
if (syncedTracksCount <= 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = Add(syncedTracks);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Profit Event Handler ...
|
|
||||||
void AddOnProfitEventHandler(TOnPositionState handler)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddSpecific(
|
|
||||||
handler,
|
|
||||||
mOnProfitEventHandlers //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Drawdown Event Handler ...
|
|
||||||
void AddOnDrawdownEventHandler(TOnPositionState handler)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddSpecific(
|
|
||||||
handler,
|
|
||||||
mOnDrawdownEventHandlers //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Event Handlers ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// OnProfit ...
|
|
||||||
void NotifyOnProfitEvent(XPositionTrack &track)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int count = ArraySize(mOnProfitEventHandlers);
|
|
||||||
if (count <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
TOnPositionState iHandler = mOnProfitEventHandlers[i];
|
|
||||||
iHandler(track);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// OnDrawdown ...
|
|
||||||
void NotifyOnDrawdownEvent(XPositionTrack &track)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int count = ArraySize(mOnDrawdownEventHandlers);
|
|
||||||
if (count <= 0)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
TOnPositionState iHandler = mOnDrawdownEventHandlers[i];
|
|
||||||
iHandler(track);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
TOnPositionState mOnProfitEventHandlers[];
|
|
||||||
TOnPositionState mOnDrawdownEventHandlers[];
|
|
||||||
|
|
||||||
//
|
|
||||||
void FillState(
|
|
||||||
XPositionTrack &track,
|
|
||||||
XPositionTrackerState &state //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// In Profit ...
|
|
||||||
bool isInProfit = track.profit[0] > 0;
|
|
||||||
if (isInProfit)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
track,
|
|
||||||
state.inProfits //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// In Drawdown ...
|
|
||||||
bool isInDrawdown = track.profit[0] < 0;
|
|
||||||
if (isInDrawdown)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
track,
|
|
||||||
state.inDrawdowns //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// On Profit ...
|
|
||||||
bool isOnProfit = track.IsCrossedInProfit();
|
|
||||||
if (isOnProfit)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
track,
|
|
||||||
state.onProfits //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// On Drawdown ...
|
|
||||||
bool isOnDrawdown = track.IsCrossedInDrawdown();
|
|
||||||
if (isOnDrawdown)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
track,
|
|
||||||
state.onDrawdowns //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
//
|
||||||
class XSCPositionHolder
|
class XSCPositionHolder
|
||||||
{
|
{
|
||||||
@@ -2212,18 +1766,6 @@ public:
|
|||||||
{
|
{
|
||||||
mTrader.AddOnTradeStateChangedEventHandler(mOnTradeStateChangedHandler);
|
mTrader.AddOnTradeStateChangedEventHandler(mOnTradeStateChangedHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Instantiate XPositionTracker Class ...
|
|
||||||
mPositionTracker = new XSCPositionTracker();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Do Synchronisation after Instantiate everything ...
|
|
||||||
XPositionTrackerState state;
|
|
||||||
mPositionTracker.Sync(
|
|
||||||
state,
|
|
||||||
mTrader //
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2232,7 +1774,6 @@ public:
|
|||||||
{
|
{
|
||||||
//
|
//
|
||||||
delete mTrader;
|
delete mTrader;
|
||||||
delete mPositionTracker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -2605,7 +2146,6 @@ protected:
|
|||||||
//
|
//
|
||||||
// Trade Class Instance ...
|
// Trade Class Instance ...
|
||||||
XSCTrade *mTrader;
|
XSCTrade *mTrader;
|
||||||
XSCPositionTracker *mPositionTracker;
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Check in Test Mode or not ...
|
// Check in Test Mode or not ...
|
||||||
@@ -3025,85 +2565,6 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// Synchronize Positions and Position Tracker ...
|
|
||||||
void SyncPositionTracker()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Check Syncing Interval ...
|
|
||||||
|
|
||||||
//
|
|
||||||
static datetime lastSyncPositionTracker = NULL;
|
|
||||||
datetime cTime = TimeCurrent();
|
|
||||||
|
|
||||||
//
|
|
||||||
int syncInterval = PeriodSeconds(PERIOD_M5);
|
|
||||||
int lastDiff = (int)cTime - (int)lastSyncPositionTracker;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool canSync =
|
|
||||||
//
|
|
||||||
lastSyncPositionTracker == NULL
|
|
||||||
? true
|
|
||||||
: lastDiff >= syncInterval
|
|
||||||
//
|
|
||||||
;
|
|
||||||
if (!canSync)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
lastSyncPositionTracker = cTime;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Do Sync ...
|
|
||||||
|
|
||||||
//
|
|
||||||
XPositionTrackerState state;
|
|
||||||
int synced = mPositionTracker.Sync(
|
|
||||||
state,
|
|
||||||
mTrader //
|
|
||||||
);
|
|
||||||
if (synced > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Check State and Do What we Want ...
|
|
||||||
int onProfitsCount = ArraySize(state.onProfits);
|
|
||||||
int onDrawdownCount = ArraySize(state.onDrawdowns);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Do What we want whe a Position Dropped to Prefit ...
|
|
||||||
if (onProfitsCount > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
for (int i = 0; i < onProfitsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack iTrack = state.onProfits[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
OnPositionGoingInProfit(iTrack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Do what we want when a Position Dropped to Drawdown ...
|
|
||||||
if (onDrawdownCount > 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
for (int i = 0; i < onDrawdownCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XPositionTrack iTrack = state.onDrawdowns[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
OnPositionGoingToDrawdown(iTrack);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Guards ...
|
// Guards ...
|
||||||
|
|
||||||
|
|||||||
@@ -1,891 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Class Library
|
|
||||||
// ----------------------------------------------
|
|
||||||
// Name: XSCBaseInd
|
|
||||||
// Description: provides all Indicator 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
|
|
||||||
|
|
||||||
//
|
|
||||||
// Imports ...
|
|
||||||
#include "../Classes/x-saherelm.base.class.mq5"
|
|
||||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
|
||||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Definitions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
struct XBuffer
|
|
||||||
{
|
|
||||||
//
|
|
||||||
string title; // Buffer Title
|
|
||||||
string symbol; // Buffer Symbol
|
|
||||||
double values[]; // Buffer Values
|
|
||||||
ENUM_TIMEFRAMES period; // Buffer Period
|
|
||||||
datetime times[]; // Buffer Values Time
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor ...
|
|
||||||
XBuffer()
|
|
||||||
{
|
|
||||||
Clean();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
bool Init(
|
|
||||||
string mTitle, // Title
|
|
||||||
string mSymbol, // Symbol
|
|
||||||
ENUM_TIMEFRAMES mPeriod // TimeFrame
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid(mTitle) &&
|
|
||||||
IsValid(mSymbol) &&
|
|
||||||
IsValid(mPeriod);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Clean();
|
|
||||||
|
|
||||||
//
|
|
||||||
this.symbol = mSymbol;
|
|
||||||
this.period = mPeriod;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = StringToLower(mTitle);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
this.title = mTitle;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Cleanup ...
|
|
||||||
void Clean()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
Clean(values);
|
|
||||||
Clean(times);
|
|
||||||
|
|
||||||
//
|
|
||||||
title = NULL;
|
|
||||||
symbol = NULL;
|
|
||||||
period = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
bool IsValid()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
IsValid(title) &&
|
|
||||||
IsValid(period) &&
|
|
||||||
IsValid(symbol)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Owwn ...
|
|
||||||
bool IsOwn(
|
|
||||||
string mTitle // Checking Title
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValid(mTitle);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = StringToLower(mTitle);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = this.title == mTitle;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Count Size ...
|
|
||||||
int Count()
|
|
||||||
{
|
|
||||||
return ArraySize(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Value to Buffer ...
|
|
||||||
int Add(
|
|
||||||
int index,
|
|
||||||
double value //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!IsValid())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (index > 0)
|
|
||||||
{
|
|
||||||
Add(value, values);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
values[Count() - 1] = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = Count();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Get Specified Index Value ...
|
|
||||||
double Get(
|
|
||||||
int index // Specified Index
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double result = EMPTY_VALUE;
|
|
||||||
|
|
||||||
//
|
|
||||||
NormalizeIndex(
|
|
||||||
index,
|
|
||||||
values //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
result = values[index];
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Remove Specified Index Value ...
|
|
||||||
bool Remove(int index)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
int count = Count();
|
|
||||||
result = IsValidSize(count);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = index > 0 && index < count - 1;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = ArrayRemove(
|
|
||||||
values,
|
|
||||||
index,
|
|
||||||
1 //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
class XSCBaseBufferClass : public XSCBaseAlert
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Virtual ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate ...
|
|
||||||
virtual bool IsValid()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculations ...
|
|
||||||
virtual void Calculate() {}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicators Buffers ...
|
|
||||||
XBuffer mBuffers[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer Management ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Count Registered Buffers ...
|
|
||||||
int CountBuffers()
|
|
||||||
{
|
|
||||||
return ArraySize(mBuffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Specified Buffer Index ...
|
|
||||||
int GetBufferIndex(
|
|
||||||
string title // Specified Buffer Title
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!IsSpecifiedValid(title))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int buffersCount = CountBuffers();
|
|
||||||
if (!IsValidSize(buffersCount))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < buffersCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XBuffer iBuffer = mBuffers[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isOwn = iBuffer.IsOwn(title);
|
|
||||||
if (isOwn)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Contains Specific Buffer or not ...
|
|
||||||
bool HasBuffer(
|
|
||||||
string title // Specified Buffer Title
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
int bufferIndex = GetBufferIndex(title);
|
|
||||||
result = bufferIndex >= 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Specified Buffer ...
|
|
||||||
bool GetBuffer(
|
|
||||||
string title, // Specified Buffer Title
|
|
||||||
XBuffer &buffer // Hold Result
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
int idx = GetBufferIndex(title);
|
|
||||||
result = idx >= 0;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
buffer = mBuffers[idx];
|
|
||||||
|
|
||||||
//
|
|
||||||
result = buffer.IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Specified Buffer ...
|
|
||||||
bool SetBuffer(
|
|
||||||
XBuffer &buffer // Specified Buffer for Registration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate buffer ...
|
|
||||||
result = buffer.IsValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Buffer Doesn't Exists before ...
|
|
||||||
int idx = GetBufferIndex(buffer.title);
|
|
||||||
result = idx == -1;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
buffer,
|
|
||||||
mBuffers //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double GetBufferValue(
|
|
||||||
string mTitle, // Required Buffer Title
|
|
||||||
int index // Bar Index
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double result = EMPTY_VALUE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate State ...
|
|
||||||
if (!IsValid())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int bufferIDX = GetBufferIndex(mTitle);
|
|
||||||
if (bufferIDX < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Calculate();
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBuffers[bufferIDX].Get(index);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int CopyBufferValue(
|
|
||||||
string mTitle,
|
|
||||||
double &buffer[],
|
|
||||||
int start,
|
|
||||||
int count //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!IsValid())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int sourceIDX = GetBufferIndex(mTitle);
|
|
||||||
if (sourceIDX < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Calculate();
|
|
||||||
|
|
||||||
//
|
|
||||||
result = ArrayCopy(
|
|
||||||
buffer,
|
|
||||||
mBuffers[sourceIDX].values,
|
|
||||||
start,
|
|
||||||
start,
|
|
||||||
count //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Base Indicator Class ...
|
|
||||||
class XSCBaseInd : public XSCBaseAlert
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Indicators Buffers ...
|
|
||||||
XBuffer mBuffers[];
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor(s) ...
|
|
||||||
void XSCBaseInd(
|
|
||||||
string symbol, // Trading Symbol
|
|
||||||
ENUM_TIMEFRAMES period // Trading TimeFrame
|
|
||||||
) : XSCBaseAlert()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
mSymbol = symbol;
|
|
||||||
mPeriod = period;
|
|
||||||
|
|
||||||
//
|
|
||||||
mCalculatedBars = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Deconstructor ...
|
|
||||||
void ~XSCBaseInd() {}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Property Getter(s) / Setter(s) ...
|
|
||||||
|
|
||||||
//
|
|
||||||
string GetSymbol()
|
|
||||||
{
|
|
||||||
return mSymbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_TIMEFRAMES GetPeriod()
|
|
||||||
{
|
|
||||||
return mPeriod;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Overrides ...
|
|
||||||
|
|
||||||
//
|
|
||||||
virtual string GetTag();
|
|
||||||
|
|
||||||
//
|
|
||||||
virtual string GetToken();
|
|
||||||
|
|
||||||
//
|
|
||||||
virtual void DeInit(int reason); // Indicator DeInitialization
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Inputs ...
|
|
||||||
virtual bool IsValidInputs()
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate ...
|
|
||||||
virtual void Calculate() {}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
datetime GetBarTime(
|
|
||||||
datetime time = NULL //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
NormalizeTime(time);
|
|
||||||
|
|
||||||
//
|
|
||||||
datetime result = GetPeriodStartTime(
|
|
||||||
mSymbol,
|
|
||||||
mPeriod,
|
|
||||||
time //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int GetBarIndex(
|
|
||||||
datetime time = NULL //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
datetime iBarTime = GetBarTime(time);
|
|
||||||
|
|
||||||
//
|
|
||||||
int result = iBarShift(
|
|
||||||
mSymbol,
|
|
||||||
mPeriod,
|
|
||||||
iBarTime //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Calculate Bars ...
|
|
||||||
int GetCalculatedBars()
|
|
||||||
{
|
|
||||||
return mCalculatedBars;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Count available Bars ...
|
|
||||||
int CountBars()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return iBars(
|
|
||||||
mSymbol,
|
|
||||||
mPeriod //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate Indicator States ...
|
|
||||||
bool IsValid()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = IsValidInputs();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
IsSpecifiedValid(mSymbol) &&
|
|
||||||
IsSpecifiedValid(mPeriod)
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Calculate Limit ...
|
|
||||||
// this means Required Bars for Calculation ...
|
|
||||||
int CountLimit()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
int totalBars = CountBars();
|
|
||||||
int calculatedBars = GetCalculatedBars();
|
|
||||||
result = MathAbs(totalBars - calculatedBars);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Buffer Registrations ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Count Registered Buffers ...
|
|
||||||
int CountBuffers()
|
|
||||||
{
|
|
||||||
return ArraySize(mBuffers);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Specified Buffer Index ...
|
|
||||||
int GetBufferIndex(
|
|
||||||
string title // Specified Buffer Title
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = -1;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!IsSpecifiedValid(title))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int buffersCount = CountBuffers();
|
|
||||||
if (!IsValidSize(buffersCount))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
for (int i = 0; i < buffersCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XBuffer iBuffer = mBuffers[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isOwn = iBuffer.IsOwn(title);
|
|
||||||
if (isOwn)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
result = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Contains Specific Buffer or not ...
|
|
||||||
bool HasBuffer(
|
|
||||||
string title // Specified Buffer Title
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
int bufferIndex = GetBufferIndex(title);
|
|
||||||
result = bufferIndex >= 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Retrieve Specified Buffer ...
|
|
||||||
bool GetBuffer(
|
|
||||||
string title, // Specified Buffer Title
|
|
||||||
XBuffer &buffer // Hold Result
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
int idx = GetBufferIndex(title);
|
|
||||||
result = idx >= 0;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
buffer = mBuffers[idx];
|
|
||||||
|
|
||||||
//
|
|
||||||
result = buffer.IsValid();
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Register Specified Buffer ...
|
|
||||||
bool SetBuffer(
|
|
||||||
XBuffer &buffer // Specified Buffer for Registration
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate buffer ...
|
|
||||||
result = buffer.IsValid();
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check Buffer Doesn't Exists before ...
|
|
||||||
int idx = GetBufferIndex(buffer.title);
|
|
||||||
result = idx == -1;
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
buffer,
|
|
||||||
mBuffers //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
double GetBufferValue(
|
|
||||||
string mTitle, // Required Buffer Title
|
|
||||||
int index // Bar Index
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
double result = EMPTY_VALUE;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Validate State ...
|
|
||||||
if (!IsValid())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int bufferIDX = GetBufferIndex(mTitle);
|
|
||||||
if (bufferIDX < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Calculate();
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBuffers[bufferIDX].Get(index);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int CopyBufferValue(
|
|
||||||
string mTitle,
|
|
||||||
double &buffer[],
|
|
||||||
int start,
|
|
||||||
int count //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!IsValid())
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
int sourceIDX = GetBufferIndex(mTitle);
|
|
||||||
if (sourceIDX < 0)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
Calculate();
|
|
||||||
|
|
||||||
//
|
|
||||||
result = ArrayCopy(
|
|
||||||
buffer,
|
|
||||||
mBuffers[sourceIDX].values,
|
|
||||||
start,
|
|
||||||
start,
|
|
||||||
count //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
string mSymbol; // Trading Symbol
|
|
||||||
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame
|
|
||||||
|
|
||||||
//
|
|
||||||
int mCalculatedBars; // Calculated Bars
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SaherElm IT Center MQL5 Class Library
|
|
||||||
// ----------------------------------------------
|
|
||||||
// Name: XSCBaseProvider
|
|
||||||
// Description: provides all Base Provider
|
|
||||||
// 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
|
|
||||||
|
|
||||||
//
|
|
||||||
// Includes ...
|
|
||||||
#include "../Classes/x-saherelm.xalert.class.mq5"
|
|
||||||
#include "../Libraries/x-saherelm.xtrade.lib.mq5"
|
|
||||||
|
|
||||||
//
|
|
||||||
// Class ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Base Provider Class ...
|
|
||||||
class XSCBaseProvider : public XSCBaseAlert
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor ...
|
|
||||||
XSCBaseProvider(
|
|
||||||
string symbol, // Trading Symbol
|
|
||||||
ENUM_TIMEFRAMES period // Trading Period
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Initialize Cycle ...
|
|
||||||
mCycle.Init(
|
|
||||||
symbol,
|
|
||||||
period,
|
|
||||||
X_MARKET_CYCLE_SHORT,
|
|
||||||
X_PERIOD_MANUALLY,
|
|
||||||
period,
|
|
||||||
"HOST Period"
|
|
||||||
//
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Deconstructor ...
|
|
||||||
~XSCBaseProvider()
|
|
||||||
{
|
|
||||||
DeInit();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Properties Gettr(s) / Setter(s) ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// DeInit all Requirements ...
|
|
||||||
virtual void DeInit();
|
|
||||||
|
|
||||||
//
|
|
||||||
// Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
string GetSymbol()
|
|
||||||
{
|
|
||||||
return mCycle.symbol;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
ENUM_TIMEFRAMES GetPeriod()
|
|
||||||
{
|
|
||||||
return mCycle.hostPeriod;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Count Bars ...
|
|
||||||
int CountBars()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return mCycle
|
|
||||||
.CountBars();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Check New Bar ...
|
|
||||||
bool IsNewBar()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
return mCycle
|
|
||||||
.IsNewBar();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Can Ignore Process ...
|
|
||||||
bool CanIgnoreProcess()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
result =
|
|
||||||
//
|
|
||||||
IsRunningOnTestMode()
|
|
||||||
? !IsNewBar()
|
|
||||||
: !IsNewBar() && mWaitsUntilNewBar
|
|
||||||
//
|
|
||||||
;
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
mWaitsUntilNewBar = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Toggle Waititng Until New Candle ...
|
|
||||||
void ToggleWaitingUntilNewBar()
|
|
||||||
{
|
|
||||||
mWaitsUntilNewBar = !mWaitsUntilNewBar;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void SetWaitsUntilNewBar(bool value)
|
|
||||||
{
|
|
||||||
mWaitsUntilNewBar = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
XMarketCycle mCycle;
|
|
||||||
|
|
||||||
//
|
|
||||||
bool mWaitsUntilNewBar;
|
|
||||||
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
@@ -1,351 +0,0 @@
|
|||||||
///////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// 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
|
|
||||||
|
|
||||||
//
|
|
||||||
#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"
|
|
||||||
|
|
||||||
//
|
|
||||||
#define ShortName "XSAMPLE"
|
|
||||||
|
|
||||||
//
|
|
||||||
int swingLifeTime = 20;
|
|
||||||
ENUM_TIMEFRAMES destPEriod = PERIOD_H4;
|
|
||||||
|
|
||||||
//
|
|
||||||
XOHCL hSwing0;
|
|
||||||
XOHCL hSwing1;
|
|
||||||
|
|
||||||
//
|
|
||||||
XOHCL lSwing0;
|
|
||||||
XOHCL lSwing1;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCAlert *mAlert;
|
|
||||||
XSCTrade *mTrader;
|
|
||||||
|
|
||||||
//
|
|
||||||
XBarTracker xBarTracker;
|
|
||||||
XMarketCycle xDestCycle;
|
|
||||||
|
|
||||||
//
|
|
||||||
// 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 ...
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// On Tick Handler ...
|
|
||||||
void OnTick()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
if (!xBarTracker.IsNewBar())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
xDestCycle.Update(0);
|
|
||||||
|
|
||||||
//
|
|
||||||
Analyze();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
bool InitialEA()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
mAlert = new XSCAlert();
|
|
||||||
mAlert.SetLogAlerts(true);
|
|
||||||
mAlert.SetPrefix(ShortName);
|
|
||||||
mAlert.SetEnableAlerts(true);
|
|
||||||
mAlert.SetPushAlerts(false);
|
|
||||||
mAlert.SetMailAlerts(false);
|
|
||||||
mAlert.SetTerminalAlerts(false);
|
|
||||||
|
|
||||||
//
|
|
||||||
mTrader = new XSCTrade(
|
|
||||||
10,
|
|
||||||
78692110,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0 //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
result = xBarTracker.Init(
|
|
||||||
_Symbol,
|
|
||||||
_Period //
|
|
||||||
);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = xDestCycle.Init(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
X_MARKET_CYCLE_MEDIUM,
|
|
||||||
X_PERIOD_MANUALLY,
|
|
||||||
destPEriod,
|
|
||||||
"DEST" //
|
|
||||||
);
|
|
||||||
if (!result)
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
result = true;
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void Analyze()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XOHCL cBar;
|
|
||||||
cBar.Init(
|
|
||||||
_Symbol,
|
|
||||||
_Period,
|
|
||||||
1 //
|
|
||||||
);
|
|
||||||
|
|
||||||
//
|
|
||||||
FindSwings(cBar);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
void FindSwings(XOHCL &bar)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// High Swings ...
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!hSwing0.IsValid())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int index = bar.FindSwing(X_SWING_HIGH, 10);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (index >= 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool isInited = hSwing0.Init(
|
|
||||||
bar.symbol,
|
|
||||||
bar.period,
|
|
||||||
index //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (hSwing0.IsValid() && !hSwing1.IsValid())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int index = bar.FindNextSwing(X_SWING_HIGH, hSwing0.Index(), 10);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (index >= 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
index += hSwing0.Index();
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isInited = hSwing1.Init(
|
|
||||||
bar.symbol,
|
|
||||||
bar.period,
|
|
||||||
index //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Swings ...
|
|
||||||
if (hSwing0.IsValid() && hSwing1.IsValid())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
DrawSwing(
|
|
||||||
hSwing1,
|
|
||||||
X_PRICE_HIGH,
|
|
||||||
hSwing0,
|
|
||||||
X_PRICE_HIGH,
|
|
||||||
clrAqua,
|
|
||||||
"HH" //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Low Swings ...
|
|
||||||
|
|
||||||
//
|
|
||||||
if (!lSwing0.IsValid())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int index = bar.FindSwing(X_SWING_LOW, 10);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (index >= 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool isInited = lSwing0.Init(
|
|
||||||
bar.symbol,
|
|
||||||
bar.period,
|
|
||||||
index //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
if (lSwing0.IsValid() && !lSwing1.IsValid())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int index = bar.FindNextSwing(X_SWING_LOW, lSwing0.Index(), 10);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (index >= 0)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
index += lSwing0.Index();
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isInited = lSwing1.Init(
|
|
||||||
bar.symbol,
|
|
||||||
bar.period,
|
|
||||||
index //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Swings ...
|
|
||||||
if (lSwing0.IsValid() && lSwing1.IsValid())
|
|
||||||
{
|
|
||||||
//
|
|
||||||
DrawSwing(
|
|
||||||
lSwing1,
|
|
||||||
X_PRICE_LOW,
|
|
||||||
lSwing0,
|
|
||||||
X_PRICE_LOW,
|
|
||||||
clrMagenta,
|
|
||||||
"LL" //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Draw Line ...
|
|
||||||
|
|
||||||
//
|
|
||||||
void DrawSwing(
|
|
||||||
XOHCL &bar1, // From (Old) ...
|
|
||||||
ENUM_X_PRICE price1, // How to Select Bar 1 Price ...
|
|
||||||
XOHCL &bar0, // To (New) ...
|
|
||||||
ENUM_X_PRICE price0, // How to Select Bar 0 Price ...
|
|
||||||
color clr,
|
|
||||||
string prefix,
|
|
||||||
bool forceRemove = false //
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
long chartID = ChartID();
|
|
||||||
|
|
||||||
//
|
|
||||||
double b1Price = bar1.GetPrice(price1);
|
|
||||||
double b0Price = bar0.GetPrice(price0);
|
|
||||||
|
|
||||||
//
|
|
||||||
string lName = prefix + "Swing_" +
|
|
||||||
ToString(b1Price) + "_TO_" +
|
|
||||||
ToString(b0Price);
|
|
||||||
|
|
||||||
//
|
|
||||||
if (IsDrawExists(prefix) && forceRemove)
|
|
||||||
{
|
|
||||||
RemoveDraws(prefix);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// if (IsDrawExists(lName))
|
|
||||||
// {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
//
|
|
||||||
DrawTrendLine(
|
|
||||||
chartID,
|
|
||||||
lName,
|
|
||||||
0,
|
|
||||||
bar1.time,
|
|
||||||
b1Price,
|
|
||||||
bar0.time,
|
|
||||||
b0Price,
|
|
||||||
clr,
|
|
||||||
STYLE_SOLID,
|
|
||||||
2,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
true //
|
|
||||||
);
|
|
||||||
}
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -24,7 +24,6 @@
|
|||||||
#include <Trade/Trade.mqh>
|
#include <Trade/Trade.mqh>
|
||||||
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
#include "../Libraries/x-saherelm.draw.lib.mq5"
|
||||||
#include "../Libraries/x-saherelm.common.lib.mq5"
|
#include "../Libraries/x-saherelm.common.lib.mq5"
|
||||||
#include "../Classes/x-saherelm.xdata-collector.class.mq5"
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Definitions ...
|
// Definitions ...
|
||||||
@@ -2894,190 +2893,6 @@ typedef void (*TOnTradeStateChanged)(const XOnTradeHandlerState &state);
|
|||||||
//
|
//
|
||||||
// Classes ...
|
// Classes ...
|
||||||
|
|
||||||
//
|
|
||||||
// Create a Signal Specfic Data Collector ...
|
|
||||||
class XSCSignalCollector
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Public ...
|
|
||||||
public:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Constructor ...
|
|
||||||
void XSCSignalCollector()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XSCDataCollector<XSignal> mBase;
|
|
||||||
mBase.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Deconstructor ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Inheritanced Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Cleaning Store ...
|
|
||||||
void Clear()
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XSCDataCollector<XSignal> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
mBase.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Collect All Store ...
|
|
||||||
int Collect(XSignal &result[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int mResult = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XSignal> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
mResult = mBase.Collect(result);
|
|
||||||
|
|
||||||
//
|
|
||||||
return mResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Item To Store ...
|
|
||||||
bool Add(XSignal &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XSignal> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBase.Add(item);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Add Item(s) To Store ...
|
|
||||||
int Add(XSignal &items[])
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int result = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XSignal> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBase.Add(items);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Remove an Item from Store ...
|
|
||||||
bool Remove(XSignal &item)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
bool result = false;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSCDataCollector<XSignal> mBase;
|
|
||||||
|
|
||||||
//
|
|
||||||
result = mBase.Remove(item);
|
|
||||||
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Custom Functions ...
|
|
||||||
|
|
||||||
//
|
|
||||||
int CollectSignals(
|
|
||||||
XSignal &result[], // Hold Result
|
|
||||||
string symbol = NULL, // Trading Symbol
|
|
||||||
string provider = NULL, // Signal Provider
|
|
||||||
ENUM_TIMEFRAMES period = NULL, // Trading Timeframe
|
|
||||||
ENUM_POSITION_TYPE type = NULL, // Long (Buy), Short (Sell)
|
|
||||||
ENUM_X_ORDER_MODES mode = NULL // Execution Mode
|
|
||||||
)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
int mResult = 0;
|
|
||||||
|
|
||||||
//
|
|
||||||
XSignal signals[];
|
|
||||||
int signalsCount = Collect(signals);
|
|
||||||
if (signalsCount <= 0)
|
|
||||||
{
|
|
||||||
return mResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
mResult = ArraySize(result);
|
|
||||||
|
|
||||||
//
|
|
||||||
// Now we Have to Apply Filters ...
|
|
||||||
for (int i = 0; i < signalsCount; i++)
|
|
||||||
{
|
|
||||||
//
|
|
||||||
XSignal iSignal = signals[i];
|
|
||||||
|
|
||||||
//
|
|
||||||
bool isFiltersPassed =
|
|
||||||
iSignal.IsFiltersPassed(
|
|
||||||
symbol,
|
|
||||||
provider,
|
|
||||||
period,
|
|
||||||
type,
|
|
||||||
mode
|
|
||||||
//
|
|
||||||
);
|
|
||||||
if (!isFiltersPassed)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
AddRef(
|
|
||||||
iSignal,
|
|
||||||
result
|
|
||||||
//
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
return mResult;
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Protected ...
|
|
||||||
protected:
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Private ...
|
|
||||||
private:
|
|
||||||
//
|
|
||||||
// Props ...
|
|
||||||
|
|
||||||
//
|
|
||||||
// Tools ...
|
|
||||||
};
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Tools ...
|
// Tools ...
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user