1468 lines
28 KiB
Plaintext
1468 lines
28 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XCX121XSTRHelper
|
|
// 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_XSTR_BUFFERS
|
|
{
|
|
//
|
|
X121_XSTR_LINE = 0,
|
|
X121_XSTR_UP_LINE = 2,
|
|
X121_XSTR_DOWN_LINE = 3,
|
|
X121_XSTR_HSM_LINE = 4,
|
|
X121_XSTR_LSM_LINE = 5,
|
|
X121_XSTR_MID_LINE = 6,
|
|
X121_XSTR_MID_STATE_LINE = 7,
|
|
X121_XSTR_ATR_LINE = 8,
|
|
X121_XSTR_PRICE_LINE = 9,
|
|
X121_XSTR_STATE_LINE = 10,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct X121XSTRInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
int strLength; // Length
|
|
double strMultiplier; // Multiplier
|
|
ENUM_MA_METHOD strBoundaryMode; // Boundary Mode
|
|
ENUM_APPLIED_PRICE strAppliedTo; // Applied To
|
|
|
|
//
|
|
bool showStr; // Show Str
|
|
bool showStrMid; // Show Str Mid
|
|
bool showStrUpper; // Show Str Upper
|
|
bool showStrLower; // Show Str Lower
|
|
bool showStrSMLow; // Show Str SM Low
|
|
bool showStrSMHigh; // Show Str SM High
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
X121XSTRInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
strLength = 0;
|
|
strMultiplier = 0.0;
|
|
strBoundaryMode = MODE_SMA;
|
|
strAppliedTo = PRICE_MEDIAN;
|
|
|
|
//
|
|
showStr = false;
|
|
showStrMid = false;
|
|
showStrUpper = false;
|
|
showStrLower = false;
|
|
showStrSMLow = false;
|
|
showStrSMHigh = false;
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
strLength = 14;
|
|
strMultiplier = 3.0;
|
|
strBoundaryMode = MODE_SMA;
|
|
strAppliedTo = PRICE_CLOSE;
|
|
|
|
//
|
|
showStr = true;
|
|
showStrMid = true;
|
|
showStrUpper = true;
|
|
showStrLower = true;
|
|
showStrSMLow = true;
|
|
showStrSMHigh = true;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
strLength > 0 &&
|
|
strMultiplier > 0
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(1, strLength);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Conditions ...
|
|
struct X121XSTRConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
double strBuffer[];
|
|
double atrBuffer[];
|
|
double strUpBuffer[];
|
|
double strMidBuffer[];
|
|
double strDownBuffer[];
|
|
double strPriceBuffer[];
|
|
double strStateBuffer[];
|
|
double strSMLowBuffer[];
|
|
double strSMHighBuffer[];
|
|
double strMidStateBuffer[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isStrBullish;
|
|
bool isStrBearish;
|
|
|
|
//
|
|
bool isStrSwitchedToBullish;
|
|
bool isStrSwitchedToBearish;
|
|
|
|
//
|
|
// bool isCloseLower
|
|
|
|
//
|
|
// Constructor ...
|
|
X121XSTRConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Commons ...
|
|
symbol = NULL;
|
|
period = NULL;
|
|
time = NULL;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
Clean(strBuffer);
|
|
Clean(atrBuffer);
|
|
Clean(strUpBuffer);
|
|
Clean(strMidBuffer);
|
|
Clean(strDownBuffer);
|
|
Clean(strPriceBuffer);
|
|
Clean(strStateBuffer);
|
|
Clean(strSMLowBuffer);
|
|
Clean(strSMHighBuffer);
|
|
Clean(strMidStateBuffer);
|
|
|
|
//
|
|
ArraySetAsSeries(strBuffer, true);
|
|
ArraySetAsSeries(atrBuffer, true);
|
|
ArraySetAsSeries(strUpBuffer, true);
|
|
ArraySetAsSeries(strMidBuffer, true);
|
|
ArraySetAsSeries(strDownBuffer, true);
|
|
ArraySetAsSeries(strPriceBuffer, true);
|
|
ArraySetAsSeries(strStateBuffer, true);
|
|
ArraySetAsSeries(strSMLowBuffer, true);
|
|
ArraySetAsSeries(strSMHighBuffer, true);
|
|
ArraySetAsSeries(strMidStateBuffer, true);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
isStrBullish = false;
|
|
isStrBearish = false;
|
|
|
|
//
|
|
isStrSwitchedToBullish = false;
|
|
isStrSwitchedToBearish = false;
|
|
|
|
//
|
|
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;
|
|
|
|
//
|
|
double score = 1;
|
|
double minScore = 0.5;
|
|
double highScore = 1.5;
|
|
|
|
//
|
|
if (isStrBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isStrSwitchedToBullish)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
|
|
//
|
|
if (isStrBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isStrSwitchedToBearish)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 =
|
|
//
|
|
"-----------------------" + separator +
|
|
"XSTR: " + separator +
|
|
"-----------------------" + separator +
|
|
ToString("isStrBullish", isStrBullish, ignoreFalseConditions, separator) +
|
|
ToString("isStrBearish", isStrBearish, ignoreFalseConditions, separator) +
|
|
ToString("isStrSwitchedToBullish", isStrSwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isStrSwitchedToBearish", isStrSwitchedToBearish, ignoreFalseConditions, separator) +
|
|
//
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
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 XCX121XSTRHelper : public XCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XCX121XSTRHelper()
|
|
: XCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121XSTRHelper()
|
|
{
|
|
//
|
|
mInputs.Clean();
|
|
|
|
//
|
|
Clean(strBuffer);
|
|
Clean(atrBuffer);
|
|
Clean(strPriceBuffer);
|
|
Clean(strUpBuffer);
|
|
Clean(strDownBuffer);
|
|
Clean(strStateBuffer);
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
X121XSTRInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ArraySetAsSeries(strBuffer, true);
|
|
ArraySetAsSeries(atrBuffer, true);
|
|
ArraySetAsSeries(strUpBuffer, true);
|
|
ArraySetAsSeries(strMidBuffer, true);
|
|
ArraySetAsSeries(strDownBuffer, true);
|
|
ArraySetAsSeries(strPriceBuffer, true);
|
|
ArraySetAsSeries(strStateBuffer, true);
|
|
ArraySetAsSeries(strSMLowBuffer, true);
|
|
ArraySetAsSeries(strSMHighBuffer, true);
|
|
ArraySetAsSeries(strMidStateBuffer, true);
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.xstr",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
mInputs.strLength,
|
|
mInputs.strMultiplier,
|
|
mInputs.strBoundaryMode,
|
|
mInputs.strAppliedTo,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
mInputs.showStr,
|
|
mInputs.showStrMid,
|
|
mInputs.showStrUpper,
|
|
mInputs.showStrLower,
|
|
mInputs.showStrSMLow,
|
|
mInputs.showStrSMHigh
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
X121XSTRInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
X121XSTRInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Readers ...
|
|
|
|
//
|
|
// ATR ...
|
|
|
|
//
|
|
double GetATR(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(atrBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return atrBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyATR(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
atrBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTR(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTR(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRState(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRMid(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strMidBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strMidBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRMid(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strMidBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRMidState(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strMidStateBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strMidStateBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRMidState(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strMidStateBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRPrice(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strPriceBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strPriceBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRPrice(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strPriceBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRUp(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strUpBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strUpBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRUp(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strUpBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRDown(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strDownBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strDownBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRDown(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strDownBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRSMLow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strSMLowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strSMLowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRSMLow(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strSMLowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSTRSMHigh(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(strSMHighBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return strSMHighBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySTRSMHigh(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceClean = true // Force To Clean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
strSMHighBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetLastSTR(
|
|
ENUM_X_DIRECTION dir,
|
|
int barIndex = 0 //
|
|
)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
if (!HasDirection(dir))
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = barIndex;
|
|
bool isBullish = IsBullish(dir);
|
|
|
|
//
|
|
bool canContinue = true;
|
|
while (canContinue)
|
|
{
|
|
//
|
|
double iStr = GetSTR(index);
|
|
double iState = GetSTRState(index);
|
|
|
|
//
|
|
canContinue =
|
|
isBullish
|
|
? iState < 0
|
|
: iState > 0;
|
|
if (!canContinue)
|
|
{
|
|
//
|
|
result = iStr;
|
|
break;
|
|
}
|
|
|
|
//
|
|
index++;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
void Free() override
|
|
{
|
|
Cleanup(10);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
X121XSTRConditions &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;
|
|
|
|
//
|
|
XOHCL zBar;
|
|
result = zBar.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
zIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL cBar;
|
|
result = cBar.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
cIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
XOHCL pBar;
|
|
result = pBar.Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
pIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
CopyATR(
|
|
zIndex,
|
|
loopback,
|
|
conditions.atrBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTR(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strStateBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRMid(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strMidBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRMidState(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strMidStateBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRPrice(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strPriceBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRUp(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strUpBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRDown(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strDownBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRSMLow(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strSMLowBuffer //
|
|
);
|
|
|
|
//
|
|
CopySTRSMHigh(
|
|
zIndex,
|
|
loopback,
|
|
conditions.strSMHighBuffer //
|
|
);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
int cIDX = 1;
|
|
int pIDX = cIDX + 1;
|
|
|
|
//
|
|
bool isStrBullish = strStateBuffer[cIDX] > 0;
|
|
bool isStrBullishPrev = strStateBuffer[pIDX] > 0;
|
|
|
|
//
|
|
bool isStrBearish = strStateBuffer[cIDX] < 0;
|
|
bool isStrBearishPrev = strStateBuffer[pIDX] < 0;
|
|
|
|
//
|
|
bool isStrSwitchedToBullish = isStrBullish &&
|
|
!isStrBullishPrev;
|
|
bool isStrSwitchedToBearish = isStrBearish &&
|
|
!isStrBearishPrev;
|
|
|
|
//
|
|
conditions.isStrBullish = isStrBullish;
|
|
conditions.isStrBearish = isStrBearish;
|
|
conditions.isStrSwitchedToBullish = isStrSwitchedToBullish;
|
|
conditions.isStrSwitchedToBearish = isStrSwitchedToBearish;
|
|
|
|
//
|
|
Cleanup();
|
|
|
|
//
|
|
zBar.Clean();
|
|
cBar.Clean();
|
|
pBar.Clean();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
X121XSTRInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double strBuffer[];
|
|
double atrBuffer[];
|
|
double strUpBuffer[];
|
|
double strMidBuffer[];
|
|
double strDownBuffer[];
|
|
double strPriceBuffer[];
|
|
double strStateBuffer[];
|
|
double strSMLowBuffer[];
|
|
double strSMHighBuffer[];
|
|
double strMidStateBuffer[];
|
|
|
|
//
|
|
void Calculate(
|
|
int barIndex = 0,
|
|
int maxRequiredBars = 100 //
|
|
)
|
|
{
|
|
//
|
|
// Buffers ...
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
// STR ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// State ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_STATE_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strStateBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_MID_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strMidBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_MID_STATE_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strMidStateBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Price ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_PRICE_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strPriceBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Up ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_UP_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strUpBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// STR ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_DOWN_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strDownBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_LSM_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strSMLowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_HSM_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
strSMHighBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// ATR ...
|
|
|
|
//
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XSTR_ATR_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
atrBuffer
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
void Cleanup(
|
|
int maxAllowed = 100 //
|
|
)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
strBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
atrBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strUpBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strMidBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strDownBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strPriceBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strSMLowBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strSMHighBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
strMidStateBuffer,
|
|
maxAllowed //
|
|
);
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Tools ... |