Cleanup all EQM and Trail and State Manage ment ...

This commit is contained in:
2024-05-31 00:58:22 +03:30
parent 48a8386fe5
commit a5e28b4679
3 changed files with 0 additions and 2350 deletions
-349
View File
@@ -1,349 +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 ...
};
//
// XSCMid Indicator Inputs ...
struct XSCMidInputs
{
//
// Props ...
//
int length; // Market Length ...
//
// Constructor ...
XSCMidInputs()
{
Clean();
}
//
// Tools ...
//
// Initial Inputs ...
bool Init(
int mLength // Market Length
)
{
//
bool result = false;
//
result =
//
mLength >= 2
//
;
if (!result)
{
return result;
}
//
this.length = mLength;
//
result = IsValid();
//
return result;
}
//
// Cleanup ...
void Clean()
{
//
this.length = 0;
}
//
// Default ...
void Default()
{
//
this.length = 2;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
length > 1
//
;
//
return result;
}
//
// Retrieve Max Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(this.length, this.length);
//
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)
{
//
string token = GetTag();
//
SetAlertPrefix(token);
}
//
// 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;
result = main.Init(
"XSCMid" //
);
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 = GetBufferIndex("XSCMid");
//
int start = prevCalculated;
if (start == totalBars) {
start-=1;
}
//
// Loop through Bars ...
for (int i = start; i < totalBars - 1 && !IsStopped(); i++)
{
//
// XOHCL iBar;
// iBar.Init(
// mSymbol,
// mPeriod,
// i //
// );
//
double iValue = iClose(mSymbol, mPeriod, i);
// Print("BarIndex: " + ToString(i), ", iValue: ", iValue);
//
int count = mBuffers[mainIDX].Count();
if (count > 0 && i == count - 1)
{
mBuffers[mainIDX].Set(i, iValue);
}
else
{
mBuffers[mainIDX].Add(iValue);
}
}
//
// Prevent Double Calculation Same Bars ...
mCalculatedBars = totalBars;
}
//
// De Initialize Class ...
void DeInit(int reason)
{
}
//
// Tools ...
//
// Reading Values ...
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
//
// Inputs ...
XSCMidInputs mInputs;
};
File diff suppressed because it is too large Load Diff
-812
View File
@@ -1,812 +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
double values[]; // Buffer Values
//
// Constructor ...
XBuffer()
{
Clean();
}
//
// Tools ...
bool Init(
string mTitle // Title
)
{
//
bool result = false;
//
result = IsValid(mTitle);
if (!result)
{
return result;
}
//
Clean();
//
result = StringToLower(mTitle);
if (!result)
{
return result;
}
//
title = mTitle;
// ArraySetAsSeries(values, false);
//
result = IsValid();
//
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;
}
//
int count = Count();
ArrayResize(
values,
count + 1 //
);
//
values[count] = value;
//
result = Count();
//
return result;
}
//
void Set(
int index,
double value //
)
{
//
NormalizeIndex(index, values);
//
values[index] = value;
}
//
// 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;
}
};
//
struct XBufferPlotStyle
{
//
int width; // Width
color clr; // Color
uchar arrow; // Arrow Code
ENUM_DRAW_TYPE type; // Type
ENUM_LINE_STYLE style; // Style
//
// Constructor ...
XBufferPlotStyle()
{
Default();
}
//
// Tools ...
//
// Default ...
void Default()
{
//
width = 1;
arrow = 0;
clr = CLR_NONE;
type = DRAW_NONE;
style = STYLE_SOLID;
}
};
//
// 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 ...
//
// 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;
}
//
// Protected ...
protected:
//
// Props ...
//
string mSymbol; // Trading Symbol
ENUM_TIMEFRAMES mPeriod; // Trading TimeFrame
//
int mCalculatedBars; // Calculated Bars
//
// Tools ...
//
// Private ...
private:
//
// Props ...
};
//
// Tools ...
//
// Register a Buffer as Indexed Buffer ...
void SetIndexBuffer(
int &index, // the Index refrence for Buffer
double &buffer[], // Buffer to Set
XBufferPlotStyle &style, // Style to Apply to Buffer
double &colorBuffer[], // Color Buffer
string label = NULL, // Buffer Label
bool showData = true, // Show Data on Data Window
double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value
int drawBegin = -1 // if Set More Than -1 applied
)
{
//
// Set Buffer Index ...
SetIndexBuffer(index, buffer, INDICATOR_DATA);
//
// Show Date ...
PlotIndexSetInteger(index, PLOT_SHOW_DATA, showData);
//
// Set Buffer Label ...
if (IsValid(label))
{
PlotIndexSetString(index, PLOT_LABEL, label);
}
//
if (empty == 0 || empty == EMPTY_VALUE)
{
PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, empty);
}
//
if (drawBegin > -1)
{
PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, drawBegin);
}
//
if (style.type == DRAW_ARROW)
{
PlotIndexSetInteger(index, PLOT_ARROW, style.arrow);
}
//
PlotIndexSetInteger(index, PLOT_LINE_STYLE, style.style);
PlotIndexSetInteger(index, PLOT_LINE_WIDTH, style.width);
//
string drawTypeStr = EnumToString(style.type);
bool hasColorBuffer = Contains("COLOR", drawTypeStr);
//
if (!hasColorBuffer)
{
PlotIndexSetInteger(index, PLOT_LINE_COLOR, style.clr);
}
else
{
//
// Since Color Buffers must add as next Index of it's own Buffer
// here before applied Color Buffer increase index ...
index++;
//
SetIndexBuffer(index, colorBuffer, INDICATOR_COLOR_INDEX);
}
//
// Increase Index for Next Buffer ...
index++;
}
//
void SetIndexCandleBuffers(
int &index, // the Index refrence for Buffer
string openLabel, // Open Label
double &open[], // Open Buffer
string highLabel, // High Label
double &high[], // High Buffer
string lowLabel, // Low Label
double &low[], // Low Buffer
string closeLabel, // Close Label
double &close[], // Close Buffer
bool showData = true, // Show Data on Data Window
double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value
int drawBegin = -1 // if Set More Than -1 applied
)
{
//
bool hasLabel =
//
IsValid(openLabel) &&
IsValid(highLabel) &&
IsValid(lowLabel) &&
IsValid(closeLabel)
//
;
//
string label =
!hasLabel
? NULL
: openLabel + ";" + highLabel + ";" + lowLabel + ";" + closeLabel;
//
// Set Buffer Index ...
SetIndexBuffer(index, open, INDICATOR_DATA);
//
// Set Draw Candles Type ...
PlotIndexSetInteger(index, PLOT_LINE_STYLE, DRAW_CANDLES);
//
// Show Date ...
PlotIndexSetInteger(index, PLOT_SHOW_DATA, showData);
//
// Set Buffer Label ...
if (IsValid(label))
{
PlotIndexSetString(index, PLOT_LABEL, label);
}
//
if (empty == 0 || empty == EMPTY_VALUE)
{
PlotIndexSetDouble(index, PLOT_EMPTY_VALUE, empty);
}
//
if (drawBegin > -1)
{
PlotIndexSetInteger(index, PLOT_DRAW_BEGIN, drawBegin);
}
//
index++;
//
// Set Buffer Index ...
SetIndexBuffer(index, high, INDICATOR_DATA);
index++;
//
// Set Buffer Index ...
SetIndexBuffer(index, low, INDICATOR_DATA);
index++;
//
// Set Buffer Index ...
SetIndexBuffer(index, close, INDICATOR_DATA);
index++;
}
//
void SetIndexCandleBuffers(
int &index, // the Index refrence for Buffer
string openLabel, // Open Label
double &open[], // Open Buffer
string highLabel, // High Label
double &high[], // High Buffer
string lowLabel, // Low Label
double &low[], // Low Buffer
string closeLabel, // Close Label
double &close[], // Close Buffer
double &colorBuffer[], // Candle Color Buffer
bool showData = true, // Show Data on Data Window
double empty = -1, // Set 0 or EMPTY_VALUE used for setting Empty Value
int drawBegin = -1 // if Set More Than -1 applied
)
{
//
SetIndexCandleBuffers(
index,
openLabel,
open,
highLabel,
high,
lowLabel,
low,
closeLabel,
close,
showData,
empty,
drawBegin //
);
//
int mFirstIndex = index - 4;
//
// Set Draw Candles Type ...
PlotIndexSetInteger(mFirstIndex, PLOT_LINE_STYLE, DRAW_COLOR_CANDLES);
//
// Set Color Buffer ...
SetIndexBuffer(index, colorBuffer, INDICATOR_COLOR_INDEX);
//
index++;
}
//