Files
MQL5Data/Helpers/x-saherelm.x121.xdon.helper.mq5
T

1194 lines
22 KiB
Plaintext

///////////////////////////////////////////////////////
//
// SaherElm IT Center MQL5 Helper Class Library
// ----------------------------------------------
// Name: XCX121XDONHelper
// Description: provides all Indicator
// Helper requirements ...
//
//
// Maintainer:
// ------------
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
//
//////////////////////////////////////////////////////
//
// Global Properties ...
#property library
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://www.saherelm.ir"
#property version "1.00"
#property strict
//
// Imports ...
#include "../Classes/x-saherelm.x-helper.class.mq5"
//
// Definitions ...
//
// Definitions ...
enum ENUM_X121_XDON_BUFFERS
{
//
X121_XDON_OPEN_UPPER_LINE = 0,
X121_XDON_OPEN_LOWER_LINE = 1,
X121_XDON_HIGH_UPPER_LINE = 2,
X121_XDON_HIGH_LOWER_LINE = 3,
X121_XDON_LOW_UPPER_LINE = 4,
X121_XDON_LOW_LOWER_LINE = 5,
X121_XDON_CLOSE_UPPER_LINE = 6,
X121_XDON_CLOSE_LOWER_LINE = 7,
};
//
// Input Models ...
struct X121XDONInputs
{
//
// Props ...
//
int donchainLength; // Donchain Length
//
int startCalculationForLastBars; // Calculate Last n Bars
//
bool showUpper; // Show Upper Band
bool showLower; // Show Lower Band
//
bool showOpen; // Show Open
bool showHigh; // Show High
bool showClose; // Show Close
bool showLow; // Show Low
//
// Constructor(s) ...
X121XDONInputs()
{
//
Clean();
}
//
// Tools ...
//
// Clean ...
void Clean()
{
//
donchainLength = 0;
//
startCalculationForLastBars = 0;
//
showUpper = false;
showLower = false;
//
showOpen = false;
showHigh = false;
showClose = false;
showLow = false;
//
ZeroMemory(this);
}
//
// Default ...
void Default()
{
//
donchainLength = 40;
//
startCalculationForLastBars = 1000;
//
showUpper = true;
showLower = true;
//
showOpen = true;
showHigh = true;
showClose = true;
showLow = true;
}
//
// Validate ...
bool IsValid()
{
//
bool result = false;
//
result =
//
donchainLength > 0
//
;
//
return result;
}
//
// Retrieve MAx Length ...
int Max()
{
//
int result = 0;
//
result = MathMax(1, donchainLength);
//
return result;
}
};
//
// Conditions ...
struct X121XDONConditions
{
//
// Common ...
string symbol;
ENUM_TIMEFRAMES period;
datetime time;
//
// Buffers ...
double donOpenUpperBuffer[];
double donOpenLowerBuffer[];
double donHighUpperBuffer[];
double donHighLowerBuffer[];
double donLowUpperBuffer[];
double donLowLowerBuffer[];
double donCloseUpperBuffer[];
double donCloseLowerBuffer[];
//
// Conditions ...
//
// Constructor ...
X121XDONConditions()
{
Clean();
}
//
// Tools ...
/**
* Cleaning Up ...
*/
void Clean()
{
//
// Commons ...
symbol = NULL;
period = NULL;
time = NULL;
//
// Buffers ...
//
Clean(donOpenUpperBuffer);
Clean(donOpenLowerBuffer);
Clean(donHighUpperBuffer);
Clean(donHighLowerBuffer);
Clean(donLowUpperBuffer);
Clean(donLowLowerBuffer);
Clean(donCloseUpperBuffer);
Clean(donCloseLowerBuffer);
//
ArraySetAsSeries(donOpenUpperBuffer, true);
ArraySetAsSeries(donOpenLowerBuffer, true);
ArraySetAsSeries(donHighUpperBuffer, true);
ArraySetAsSeries(donHighLowerBuffer, true);
ArraySetAsSeries(donLowUpperBuffer, true);
ArraySetAsSeries(donLowLowerBuffer, true);
ArraySetAsSeries(donCloseUpperBuffer, true);
ArraySetAsSeries(donCloseLowerBuffer, true);
//
// Conditions ...
//
ZeroMemory(this);
}
/**
* Generate Conditions Scores ...
*
* @param bullishScore: Double, Directional Scores Reference ...
* @param bearishScore: Double, Directional Scores Reference ...
*/
void GenerateScore(
double &bullishScore,
double &bearishScore //
)
{
//
bullishScore = 0;
bearishScore = 0;
//
// TODO: Implement if Required ...
}
/**
* Generate Summary String for Represent Conditions State ...
*
* @param onlyCommons: Boolean, Just Generate Only Commons Conditions ...
* @param onlyConditions: Boolean, Just Generate Only Conditions ...
* @param includeScores: Boolean, Attach Scores Representations on Result ...
* @param ignoreFalseConditions: Boolean, Ignore False Conditions on Result ...
* @param separator: String, Separate Lines ...
*
* @return ( string )
*/
string GenerateSummary(
bool onlyCommons = false,
bool onlyConditions = false,
bool includeScores = true,
bool ignoreFalseConditions = true,
string separator = "\n" //
)
{
//
string result = NULL;
//
double bullishScore = 0;
double bearishScore = 0;
GenerateScore(
bullishScore,
bearishScore //
);
//
string scoresStr =
//
"Scores: " + separator +
"---------------" + separator +
"Bullish: " + ToString(bullishScore) + separator +
"Bearish: " + ToString(bearishScore) + separator +
""
//
;
//
string commonStr = GenerateSpecifiedCommonSummary(
this,
separator,
includeScores //
);
//
string conditionsStr =
//
//
""
//
;
//
result =
//
"[" + GetTag() + "]" + separator +
(onlyConditions
? ""
: commonStr) +
(!includeScores
? ""
: scoresStr) +
" " + separator +
(onlyCommons
? ""
: conditionsStr) +
""
//
;
//
return result;
}
/**
* Retrieve nique Tag Identifier ...
*
* @return ( string )
*/
string GetTag()
{
return GetTypeName(this);
}
//
};
//
// Class ...
class XCX121XDONHelper : public XCBaseHelper
{
//
// Public ...
public:
//
// Props ...
//
// Constructors ...
XCX121XDONHelper()
: XCBaseHelper(_Symbol, _Period)
{
}
//
// Deconstructor ...
~XCX121XDONHelper()
{
//
mInputs.Clean();
//
Clean(donOpenUpperBuffer);
Clean(donOpenLowerBuffer);
Clean(donHighUpperBuffer);
Clean(donHighLowerBuffer);
Clean(donLowUpperBuffer);
Clean(donLowLowerBuffer);
Clean(donCloseUpperBuffer);
Clean(donCloseLowerBuffer);
}
//
// Tools ...
bool Init(
string symbol, // Trading Symbol
ENUM_TIMEFRAMES period, // Trading Period
X121XDONInputs &inputs // Inputs
)
{
//
bool result = false;
//
mSymbol = symbol;
mPeriod = period;
//
result = inputs.IsValid();
if (!result)
{
return result;
}
//
ArraySetAsSeries(donOpenUpperBuffer, true);
ArraySetAsSeries(donOpenLowerBuffer, true);
ArraySetAsSeries(donHighUpperBuffer, true);
ArraySetAsSeries(donHighLowerBuffer, true);
ArraySetAsSeries(donLowUpperBuffer, true);
ArraySetAsSeries(donLowLowerBuffer, true);
ArraySetAsSeries(donCloseUpperBuffer, true);
ArraySetAsSeries(donCloseLowerBuffer, true);
//
mInputs = inputs;
//
mHandler = iCustom(
mSymbol,
mPeriod,
"x-saherelm.x121.xdon",
//
// Inputs ...
//
// Market ...
"",
mInputs.donchainLength,
//
// Presentation ...
"",
mInputs.startCalculationForLastBars,
//
mInputs.showUpper,
mInputs.showLower,
//
mInputs.showOpen,
mInputs.showHigh,
mInputs.showClose,
mInputs.showLow
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
{
return result;
}
//
return result;
}
//
// Inputs ...
//
X121XDONInputs GetInputs()
{
return mInputs;
}
//
bool SetInputs(
X121XDONInputs &inputs // Configs
)
{
//
return Init(
mSymbol,
mPeriod,
inputs
//
);
}
//
// Readers ...
//
// OPEN ...
//
// UPPER ...
//
double GetDonOpenUpper(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donOpenUpperBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donOpenUpperBuffer[barIndex];
}
//
int CopyDonOpenUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donOpenUpperBuffer,
buffer,
forceClean
//
);
}
//
// LOWER ...
//
double GetDonOpenLower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donOpenLowerBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donOpenLowerBuffer[barIndex];
}
//
int CopyDonOpenLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donOpenLowerBuffer,
buffer,
forceClean
//
);
}
//
// CLOSE ...
//
// UPPER ...
//
double GetDonCloseUpper(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donCloseUpperBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donCloseUpperBuffer[barIndex];
}
//
int CopyDonCloseUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donCloseUpperBuffer,
buffer,
forceClean
//
);
}
//
// LOWER ...
//
double GetDonCloseLower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donCloseLowerBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donCloseLowerBuffer[barIndex];
}
//
int CopyDonCloseLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donCloseLowerBuffer,
buffer,
forceClean
//
);
}
//
// HIGH ...
//
// UPPER ...
//
double GetDonHighUpper(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donHighUpperBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donHighUpperBuffer[barIndex];
}
//
int CopyDonHighUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donHighUpperBuffer,
buffer,
forceClean
//
);
}
//
// LOWER ...
//
double GetDonHighLower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donHighLowerBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donHighLowerBuffer[barIndex];
}
//
int CopyDonHighLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donHighLowerBuffer,
buffer,
forceClean
//
);
}
//
// LOW ...
//
// UPPER ...
//
double GetDonLowUpper(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donLowUpperBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donLowUpperBuffer[barIndex];
}
//
int CopyDonLowUpper(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donLowUpperBuffer,
buffer,
forceClean
//
);
}
//
// LOWER ...
//
double GetDonLoweLower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(donLowLowerBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return donLowLowerBuffer[barIndex];
}
//
int CopyDonLoweLower(
int start, // Start
int count, // Number of Items for read
double &buffer[], // Dest Buffer
bool forceClean = true // Force To Clean buffer
)
{
//
// Update Calculations ...
Calculate();
//
// Copy Items ...
return Copy(
start,
count,
donLowLowerBuffer,
buffer,
forceClean
//
);
}
//
void Free() override
{
Cleanup(10);
}
//
bool GetConditions(
X121XDONConditions &conditions, //
int barIndex = 0, //
int loopback = 5 //
)
{
//
bool result = true;
//
if (loopback < 5)
{
loopback = 5;
}
//
conditions.Clean();
//
conditions.symbol = mSymbol;
conditions.period = mPeriod;
conditions.time = TimeCurrent();
//
int zIndex = barIndex;
int cIndex = zIndex + 1;
int pIndex = cIndex + 1;
int ppIndex = pIndex + 1;
//
// Buffers ...
//
CopyDonOpenUpper(
zIndex,
loopback,
conditions.donOpenUpperBuffer //
);
//
CopyDonOpenLower(
zIndex,
loopback,
conditions.donOpenLowerBuffer //
);
//
CopyDonCloseUpper(
zIndex,
loopback,
conditions.donCloseUpperBuffer //
);
//
CopyDonCloseLower(
zIndex,
loopback,
conditions.donCloseLowerBuffer //
);
//
CopyDonHighUpper(
zIndex,
loopback,
conditions.donHighUpperBuffer //
);
//
CopyDonHighLower(
zIndex,
loopback,
conditions.donHighLowerBuffer //
);
//
CopyDonLowUpper(
zIndex,
loopback,
conditions.donLowUpperBuffer //
);
//
CopyDonLoweLower(
zIndex,
loopback,
conditions.donLowLowerBuffer //
);
//
// Conditions ...
//
int cIDX = 1;
int pIDX = cIDX + 1;
//
Cleanup();
//
return result;
}
//
// Protected ...
protected:
//
// Private ...
private:
//
// Props ...
X121XDONInputs mInputs; // Inputs ...
//
// Buffers ...
double donOpenUpperBuffer[];
double donOpenLowerBuffer[];
double donHighUpperBuffer[];
double donHighLowerBuffer[];
double donLowUpperBuffer[];
double donLowLowerBuffer[];
double donCloseUpperBuffer[];
double donCloseLowerBuffer[];
//
void Calculate(
int maxRequiredBars = 100 //
)
{
//
// Upper ...
CopyBuffer(
mHandler,
X121_XDON_OPEN_UPPER_LINE,
0,
maxRequiredBars,
donOpenUpperBuffer
//
);
//
// Lower ...
CopyBuffer(
mHandler,
X121_XDON_OPEN_LOWER_LINE,
0,
maxRequiredBars,
donOpenLowerBuffer
//
);
//
// CLOSE ...
//
// Upper ...
CopyBuffer(
mHandler,
X121_XDON_CLOSE_UPPER_LINE,
0,
maxRequiredBars,
donCloseUpperBuffer
//
);
//
// Lower ...
CopyBuffer(
mHandler,
X121_XDON_CLOSE_LOWER_LINE,
0,
maxRequiredBars,
donCloseLowerBuffer
//
);
//
// HIGH ...
//
// Upper ...
CopyBuffer(
mHandler,
X121_XDON_HIGH_UPPER_LINE,
0,
maxRequiredBars,
donHighUpperBuffer
//
);
//
// Lower ...
CopyBuffer(
mHandler,
X121_XDON_HIGH_LOWER_LINE,
0,
maxRequiredBars,
donHighLowerBuffer
//
);
//
// LOW ...
//
// Upper ...
CopyBuffer(
mHandler,
X121_XDON_LOW_UPPER_LINE,
0,
maxRequiredBars,
donLowUpperBuffer
//
);
//
// Lower ...
CopyBuffer(
mHandler,
X121_XDON_LOW_LOWER_LINE,
0,
maxRequiredBars,
donLowLowerBuffer
//
);
}
//
void Cleanup(
int maxAllowed = 100 //
)
{
//
CleanupArray(
donOpenUpperBuffer,
maxAllowed //
);
//
CleanupArray(
donOpenLowerBuffer,
maxAllowed //
);
//
CleanupArray(
donHighUpperBuffer,
maxAllowed //
);
//
CleanupArray(
donHighLowerBuffer,
maxAllowed //
);
//
CleanupArray(
donLowUpperBuffer,
maxAllowed //
);
//
CleanupArray(
donLowLowerBuffer,
maxAllowed //
);
//
CleanupArray(
donCloseUpperBuffer,
maxAllowed //
);
//
CleanupArray(
donCloseLowerBuffer,
maxAllowed //
);
//
}
//
};
//
// Tools ...