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 ...
|
||||
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
|
||||
{
|
||||
@@ -2212,18 +1766,6 @@ public:
|
||||
{
|
||||
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 mPositionTracker;
|
||||
}
|
||||
|
||||
//
|
||||
@@ -2605,7 +2146,6 @@ protected:
|
||||
//
|
||||
// Trade Class Instance ...
|
||||
XSCTrade *mTrader;
|
||||
XSCPositionTracker *mPositionTracker;
|
||||
|
||||
//
|
||||
// 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 ...
|
||||
|
||||
|
||||
@@ -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 ...
|
||||
Reference in New Issue
Block a user