last ...
This commit is contained in:
@@ -36,7 +36,6 @@ public:
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XSCAlert() {}
|
||||
XSCAlert(
|
||||
string prefix = "X-Alert", // Alerts Prefixe
|
||||
bool enableAlerts = true, // Enable Alerts
|
||||
@@ -1360,4 +1359,217 @@ private:
|
||||
//
|
||||
return message;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
//
|
||||
// a Base Class by Support Alert ...
|
||||
class XSCBaseAlert : public XSCBase
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCBaseAlert()
|
||||
{
|
||||
//
|
||||
// Instance Alert ...
|
||||
mAlert = new XSCAlert();
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructors ...
|
||||
void ~XSCBaseAlert()
|
||||
{
|
||||
//
|
||||
delete mAlert;
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Handler Functions ...
|
||||
|
||||
//
|
||||
// Alert Functions Getter(s) / Setters(s) ...
|
||||
|
||||
//
|
||||
string GetAlertPrefix()
|
||||
{
|
||||
return mAlert.GetPrefix();
|
||||
}
|
||||
|
||||
//
|
||||
void SetAlertPrefix(string value)
|
||||
{
|
||||
mAlert.SetPrefix(value);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetAlertLogAlerts()
|
||||
{
|
||||
return mAlert.GetLogAlerts();
|
||||
}
|
||||
|
||||
//
|
||||
void SetAlertLogAlerts(bool value)
|
||||
{
|
||||
mAlert.SetLogAlerts(value);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetAlertEnableAlerts()
|
||||
{
|
||||
return mAlert.GetEnableAlerts();
|
||||
}
|
||||
|
||||
//
|
||||
void SetAlertEnableAlerts(bool value)
|
||||
{
|
||||
mAlert.SetEnableAlerts(value);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetAlertPushAlerts()
|
||||
{
|
||||
return mAlert.GetPushAlerts();
|
||||
}
|
||||
|
||||
//
|
||||
void SetAlertPushAlerts(bool value)
|
||||
{
|
||||
mAlert.SetPushAlerts(value);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetAlertMailAlerts()
|
||||
{
|
||||
return mAlert.GetMailAlerts();
|
||||
}
|
||||
|
||||
//
|
||||
void SetAlertMailAlerts(bool value)
|
||||
{
|
||||
mAlert.SetMailAlerts(value);
|
||||
}
|
||||
|
||||
//
|
||||
bool GetAlertTerminalAlerts()
|
||||
{
|
||||
return mAlert.GetTerminalAlerts();
|
||||
}
|
||||
|
||||
//
|
||||
void SetAlertTerminalAlerts(bool value)
|
||||
{
|
||||
mAlert.SetTerminalAlerts(value);
|
||||
}
|
||||
|
||||
//
|
||||
// Alert Actions ...
|
||||
|
||||
//
|
||||
// Logging an Alert ...
|
||||
void LogAlert(string message)
|
||||
{
|
||||
mAlert.LogAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Terminal Alert ...
|
||||
void TerminalAlert(string message)
|
||||
{
|
||||
mAlert.TerminalAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Mail Alert ...
|
||||
void MailAlert(string message)
|
||||
{
|
||||
mAlert.MailAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send Push Notification ...
|
||||
void PushAlert(string message)
|
||||
{
|
||||
mAlert.PushAlert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Send an Alert by Handling all Different Specified
|
||||
// type's of Alert's if they are Enabled ...
|
||||
void Alert(string message)
|
||||
{
|
||||
mAlert.Alert(message);
|
||||
}
|
||||
|
||||
//
|
||||
// Logs ...
|
||||
|
||||
//
|
||||
// Log a Message ...
|
||||
void Log(string message)
|
||||
{
|
||||
mAlert.Log(message);
|
||||
}
|
||||
void Log(string tag, string message)
|
||||
{
|
||||
mAlert.Log(tag, message);
|
||||
}
|
||||
void LogEmpty()
|
||||
{
|
||||
mAlert.LogEmpty();
|
||||
}
|
||||
|
||||
//
|
||||
// Log Specific Array ...
|
||||
template <typename T>
|
||||
void LogArray(
|
||||
T &array[], // Array to Log
|
||||
string label = NULL // Array Label
|
||||
)
|
||||
{
|
||||
mAlert.LogArray(array, label);
|
||||
}
|
||||
|
||||
//
|
||||
// Error ...
|
||||
|
||||
//
|
||||
// Log an Error ...
|
||||
void LogError(
|
||||
int error = -1 // Specific Error, if it's equal to -1, use Last Error ...
|
||||
)
|
||||
{
|
||||
mAlert.LogError(error);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Specified Error Code Description ...
|
||||
string GetErrorDescription(int err_code)
|
||||
{
|
||||
return mAlert.GetErrorDescription(err_code);
|
||||
}
|
||||
|
||||
//
|
||||
// Retrieve Specified Error Code Description ...
|
||||
string GetTradeServerReturnCodeDescription(int return_code)
|
||||
{
|
||||
return mAlert.GetTradeServerReturnCodeDescription(return_code);
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Alert ...
|
||||
XSCAlert *mAlert;
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
};
|
||||
|
||||
//
|
||||
@@ -0,0 +1,526 @@
|
||||
///////////////////////////////////////////////////////
|
||||
//
|
||||
// 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
|
||||
double values[]; // Buffer Values
|
||||
bool asSeries; // As Series Flag
|
||||
|
||||
//
|
||||
// Constructor ...
|
||||
XBuffer()
|
||||
{
|
||||
Clean();
|
||||
}
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
bool Init(
|
||||
string mTitle, // Title
|
||||
bool mAsSeries = true // As Series Flag
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValid(mTitle);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
Clean();
|
||||
|
||||
//
|
||||
result = StringToLower(mTitle);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
title = mTitle;
|
||||
|
||||
//
|
||||
result = IsValid();
|
||||
|
||||
//
|
||||
asSeries = mAsSeries;
|
||||
ArraySetAsSeries(values, mAsSeries);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Cleanup ...
|
||||
void Clean()
|
||||
{
|
||||
//
|
||||
Clean(values);
|
||||
|
||||
//
|
||||
title = NULL;
|
||||
}
|
||||
|
||||
//
|
||||
// Validate ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsValid(title)
|
||||
//
|
||||
;
|
||||
|
||||
//
|
||||
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(double value)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
ArraySetAsSeries(values, false);
|
||||
|
||||
//
|
||||
int count = Count();
|
||||
ArrayResize(
|
||||
values,
|
||||
count + 1 //
|
||||
);
|
||||
|
||||
//
|
||||
values[count] = value;
|
||||
|
||||
//
|
||||
result = Count();
|
||||
|
||||
//
|
||||
ArraySetAsSeries(values, asSeries);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Get Specified Index Value ...
|
||||
double Get(
|
||||
int index, // Specified Index
|
||||
bool reverse = false // Retrieve Reversal Index Value
|
||||
)
|
||||
{
|
||||
//
|
||||
double result = EMPTY_VALUE;
|
||||
|
||||
//
|
||||
NormalizeIndex(
|
||||
index,
|
||||
values //
|
||||
);
|
||||
|
||||
//
|
||||
if (reverse)
|
||||
{
|
||||
ArraySetAsSeries(values, !asSeries);
|
||||
}
|
||||
|
||||
//
|
||||
result = values[index];
|
||||
|
||||
//
|
||||
if (reverse)
|
||||
{
|
||||
ArraySetAsSeries(values, asSeries);
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
// Base Indicator Class ...
|
||||
class XSCBaseInd : public XSCBaseAlert
|
||||
{
|
||||
//
|
||||
// Public ...
|
||||
public:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Constructor(s) ...
|
||||
void XSCBaseInd() : XSCBaseAlert()
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// Deconstructor ...
|
||||
void ~XSCBaseInd() {}
|
||||
|
||||
//
|
||||
// Overrides ...
|
||||
|
||||
//
|
||||
virtual string GetTag();
|
||||
|
||||
//
|
||||
virtual string GetToken();
|
||||
|
||||
//
|
||||
// Indicator Initializitation
|
||||
virtual bool Init(
|
||||
string symbol, // Trading Symbol
|
||||
ENUM_TIMEFRAMES period // Trading TimeFrame
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result =
|
||||
//
|
||||
IsSpecifiedValid(symbol) &&
|
||||
IsSpecifiedValid(period)
|
||||
//
|
||||
;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
mSymbol = symbol;
|
||||
mPeriod = period;
|
||||
|
||||
//
|
||||
mCalculatedBars = 0;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
virtual bool DeInit(); // Indicator DeInitialization
|
||||
|
||||
//
|
||||
// Validate Inputs ...
|
||||
virtual bool IsValidInputs()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//
|
||||
// Calculate ...
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// Count available Bars ...
|
||||
int CountBars()
|
||||
{
|
||||
//
|
||||
return iBars(
|
||||
mSymbol,
|
||||
mPeriod //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Validate Indicator States ...
|
||||
bool IsValid()
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = IsValidInputs();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// TODO: Implement this ...
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Protected ...
|
||||
protected:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
string mSymbol; // Trading Symbol
|
||||
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame
|
||||
|
||||
//
|
||||
int mCalculatedBars; // Calculated Bars
|
||||
|
||||
//
|
||||
// Tools ...
|
||||
|
||||
//
|
||||
// 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 (!IsValid(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;
|
||||
}
|
||||
|
||||
//
|
||||
// Private ...
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
|
||||
//
|
||||
// Indicators Buffers ...
|
||||
XBuffer mBuffers[];
|
||||
}
|
||||
Reference in New Issue
Block a user