1373 lines
28 KiB
Plaintext
1373 lines
28 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XCX121XCHEHelper
|
|
// 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_XCHE_BUFFERS
|
|
{
|
|
//
|
|
X121_XCHE_LE_1_LINE = 0,
|
|
X121_XCHE_SE_1_LINE = 1,
|
|
X121_XCHE_LE_2_LINE = 2,
|
|
X121_XCHE_SE_2_LINE = 3,
|
|
X121_XCHE_LE_1_S_LINE = 4,
|
|
X121_XCHE_SE_1_S_LINE = 5,
|
|
X121_XCHE_LE_2_S_LINE = 6,
|
|
X121_XCHE_SE_2_S_LINE = 7,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct X121XCHEInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
int cheLength; // Length
|
|
int cheLoopback; // Loopback
|
|
double cheMultiplier1; // 1st Multiplier
|
|
double cheMultiplier2; // 2nd Multiplier
|
|
ENUM_APPLIED_PRICE cheUpperAppliedTo; // Upper Zone Applied to
|
|
ENUM_APPLIED_PRICE cheLowerAppliedTo; // Lower Zone Applied to
|
|
|
|
//
|
|
int cheArrowCode; // CHE Arrow Code
|
|
|
|
//
|
|
bool showLE1; // Show 1st Long Exit
|
|
bool showSE1; // Show 1st Short Exit
|
|
bool showLE2; // Show 2st Long Exit
|
|
bool showSE2; // Show 2st Short Exit
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
X121XCHEInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
cheLength = 0;
|
|
cheLoopback = 0;
|
|
cheMultiplier1 = 0;
|
|
cheMultiplier2 = 0;
|
|
cheUpperAppliedTo = PRICE_HIGH;
|
|
cheLowerAppliedTo = PRICE_LOW;
|
|
|
|
//
|
|
cheArrowCode = 0;
|
|
|
|
//
|
|
showLE1 = false;
|
|
showSE1 = false;
|
|
showLE2 = false;
|
|
showSE2 = false;
|
|
|
|
//
|
|
ZeroMemory(this);
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
cheLength = 35;
|
|
cheLoopback = 26;
|
|
cheMultiplier1 = 3.0;
|
|
cheMultiplier2 = 3.5;
|
|
cheUpperAppliedTo = PRICE_HIGH;
|
|
cheLowerAppliedTo = PRICE_LOW;
|
|
|
|
//
|
|
cheArrowCode = 159;
|
|
|
|
//
|
|
showLE1 = true;
|
|
showSE1 = true;
|
|
showLE2 = true;
|
|
showSE2 = true;
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = true;
|
|
|
|
//
|
|
result =
|
|
cheLength >= 9 &&
|
|
cheLoopback >= 0;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(cheLength, cheLoopback);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Conditions ...
|
|
struct X121XCHEConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
double le1Buffer[];
|
|
double se1Buffer[];
|
|
double le2Buffer[];
|
|
double se2Buffer[];
|
|
double le1StartBuffer[];
|
|
double se1StartBuffer[];
|
|
double le2StartBuffer[];
|
|
double se2StartBuffer[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isChe1Bullish;
|
|
bool isChe1Bearish;
|
|
|
|
//
|
|
bool isChe1SwitchedToBullish;
|
|
bool isChe1SwitchedToBearish;
|
|
|
|
//
|
|
bool isChe2Bullish;
|
|
bool isChe2Bearish;
|
|
|
|
//
|
|
bool isChe2SwitchedToBullish;
|
|
bool isChe2SwitchedToBearish;
|
|
|
|
//
|
|
bool isCheBullish;
|
|
bool isCheBearish;
|
|
|
|
//
|
|
bool isCheSwitchedToBullish;
|
|
bool isCheSwitchedToBearish;
|
|
|
|
//
|
|
// Constructor ...
|
|
X121XCHEConditions()
|
|
{
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
/**
|
|
* Cleaning Up ...
|
|
*/
|
|
void Clean()
|
|
{
|
|
//
|
|
// Commons ...
|
|
symbol = NULL;
|
|
period = NULL;
|
|
time = NULL;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
Clean(le1Buffer);
|
|
Clean(se1Buffer);
|
|
Clean(le2Buffer);
|
|
Clean(se2Buffer);
|
|
Clean(le1StartBuffer);
|
|
Clean(se1StartBuffer);
|
|
Clean(le2StartBuffer);
|
|
Clean(se2StartBuffer);
|
|
|
|
//
|
|
ArraySetAsSeries(le1Buffer, true);
|
|
ArraySetAsSeries(se1Buffer, true);
|
|
ArraySetAsSeries(le2Buffer, true);
|
|
ArraySetAsSeries(se2Buffer, true);
|
|
ArraySetAsSeries(le1StartBuffer, true);
|
|
ArraySetAsSeries(se1StartBuffer, true);
|
|
ArraySetAsSeries(le2StartBuffer, true);
|
|
ArraySetAsSeries(se2StartBuffer, true);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
isChe1Bullish = false;
|
|
isChe1Bearish = false;
|
|
|
|
//
|
|
isChe1SwitchedToBullish = false;
|
|
isChe1SwitchedToBearish = false;
|
|
|
|
//
|
|
isChe2Bullish = false;
|
|
isChe2Bearish = false;
|
|
|
|
//
|
|
isChe2SwitchedToBullish = false;
|
|
isChe2SwitchedToBearish = false;
|
|
|
|
//
|
|
isCheBullish = false;
|
|
isCheBearish = false;
|
|
|
|
//
|
|
isCheSwitchedToBullish = false;
|
|
isCheSwitchedToBearish = 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;
|
|
|
|
//
|
|
// XCHE ...
|
|
|
|
//
|
|
if (isCheBullish)
|
|
{
|
|
bullishScore += score;
|
|
}
|
|
if (isCheSwitchedToBullish)
|
|
{
|
|
bullishScore += highScore;
|
|
}
|
|
if (isChe1Bullish &&
|
|
!isCheBullish &&
|
|
!isCheSwitchedToBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
if (isChe1SwitchedToBullish &&
|
|
!isCheBullish &&
|
|
!isCheSwitchedToBullish)
|
|
{
|
|
bullishScore += minScore;
|
|
}
|
|
|
|
//
|
|
if (isCheBearish)
|
|
{
|
|
bearishScore += score;
|
|
}
|
|
if (isCheSwitchedToBearish)
|
|
{
|
|
bearishScore += highScore;
|
|
}
|
|
if (isChe1Bearish &&
|
|
!isCheBearish &&
|
|
!isCheSwitchedToBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
if (isChe1SwitchedToBearish &&
|
|
!isCheBearish &&
|
|
!isCheSwitchedToBearish)
|
|
{
|
|
bearishScore += minScore;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 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 +
|
|
"XCHE: " + separator +
|
|
"-----------------------" + separator +
|
|
ToString("isChe1Bullish", isChe1Bullish, ignoreFalseConditions, separator) +
|
|
ToString("isChe1Bearish", isChe1Bearish, ignoreFalseConditions, separator) +
|
|
ToString("isChe1SwitchedToBullish", isChe1SwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isChe1SwitchedToBearish", isChe1SwitchedToBearish, ignoreFalseConditions, separator) +
|
|
ToString("isChe2Bullish", isChe2Bullish, ignoreFalseConditions, separator) +
|
|
ToString("isChe2Bearish", isChe2Bearish, ignoreFalseConditions, separator) +
|
|
ToString("isChe2SwitchedToBullish", isChe2SwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isChe2SwitchedToBearish", isChe2SwitchedToBearish, ignoreFalseConditions, separator) +
|
|
ToString("isCheBullish", isCheBullish, ignoreFalseConditions, separator) +
|
|
ToString("isCheBearish", isCheBearish, ignoreFalseConditions, separator) +
|
|
ToString("isCheSwitchedToBullish", isCheSwitchedToBullish, ignoreFalseConditions, separator) +
|
|
ToString("isCheSwitchedToBearish", isCheSwitchedToBearish, 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 XCX121XCHEHelper : public XCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XCX121XCHEHelper()
|
|
: XCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XCX121XCHEHelper()
|
|
{
|
|
//
|
|
mInputs.Clean();
|
|
|
|
//
|
|
Clean(le1Buffer);
|
|
Clean(se1Buffer);
|
|
Clean(le2Buffer);
|
|
Clean(se2Buffer);
|
|
Clean(le1StartBuffer);
|
|
Clean(se1StartBuffer);
|
|
Clean(le2StartBuffer);
|
|
Clean(se2StartBuffer);
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
X121XCHEInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ArraySetAsSeries(le1Buffer, true);
|
|
ArraySetAsSeries(se1Buffer, true);
|
|
ArraySetAsSeries(le2Buffer, true);
|
|
ArraySetAsSeries(se2Buffer, true);
|
|
ArraySetAsSeries(le1StartBuffer, true);
|
|
ArraySetAsSeries(se1StartBuffer, true);
|
|
ArraySetAsSeries(le2StartBuffer, true);
|
|
ArraySetAsSeries(se2StartBuffer, true);
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.x121.xche",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Market ...
|
|
"",
|
|
mInputs.cheLength,
|
|
mInputs.cheLoopback,
|
|
mInputs.cheMultiplier1,
|
|
mInputs.cheMultiplier2,
|
|
mInputs.cheUpperAppliedTo,
|
|
mInputs.cheLowerAppliedTo,
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
mInputs.cheArrowCode,
|
|
mInputs.showLE1,
|
|
mInputs.showSE1,
|
|
mInputs.showLE2,
|
|
mInputs.showSE2
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
X121XCHEInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
X121XCHEInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Readers ...
|
|
|
|
//
|
|
double GetLE1(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(le1Buffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return le1Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyLE1(
|
|
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,
|
|
le1Buffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetLE1Start(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(le1StartBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return le1StartBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyLE1Start(
|
|
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,
|
|
le1StartBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetLE2(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(le2Buffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return le2Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyLE2(
|
|
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,
|
|
le2Buffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetLE2Start(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(le2StartBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return le2StartBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopyLE2Start(
|
|
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,
|
|
le2StartBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSE1(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(se1Buffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return se1Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySE1(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceCsean = true // Force To Csean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
se1Buffer,
|
|
buffer,
|
|
forceCsean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSE1Start(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(se1StartBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return se1StartBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySE1Start(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceCsean = true // Force To Csean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
se1StartBuffer,
|
|
buffer,
|
|
forceCsean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSE2(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(se2Buffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return se2Buffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySE2(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceCsean = true // Force To Csean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
se2Buffer,
|
|
buffer,
|
|
forceCsean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
double GetSE2Start(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate(barIndex);
|
|
|
|
//
|
|
int count = ArraySize(se2StartBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return se2StartBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
int CopySE2Start(
|
|
int start, // Start
|
|
int count, // Number of Items for read
|
|
double &buffer[], // Dest Buffer
|
|
bool forceCsean = true // Force To Csean buffer
|
|
)
|
|
{
|
|
//
|
|
// Update Calculations ...
|
|
Calculate(start);
|
|
|
|
//
|
|
// Copy Items ...
|
|
return Copy(
|
|
0,
|
|
count,
|
|
se2StartBuffer,
|
|
buffer,
|
|
forceCsean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
void Free() override
|
|
{
|
|
Cleanup(10);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
X121XCHEConditions &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 ...
|
|
|
|
//
|
|
CopyLE1(
|
|
zIndex,
|
|
loopback,
|
|
conditions.le1Buffer //
|
|
);
|
|
|
|
//
|
|
CopySE1(
|
|
zIndex,
|
|
loopback,
|
|
conditions.se1Buffer //
|
|
);
|
|
|
|
//
|
|
CopyLE2(
|
|
zIndex,
|
|
loopback,
|
|
conditions.le2Buffer //
|
|
);
|
|
|
|
//
|
|
CopySE2(
|
|
zIndex,
|
|
loopback,
|
|
conditions.se2Buffer //
|
|
);
|
|
|
|
//
|
|
CopyLE1Start(
|
|
zIndex,
|
|
loopback,
|
|
conditions.le1StartBuffer //
|
|
);
|
|
|
|
//
|
|
CopySE1Start(
|
|
zIndex,
|
|
loopback,
|
|
conditions.se1StartBuffer //
|
|
);
|
|
|
|
//
|
|
CopyLE2Start(
|
|
zIndex,
|
|
loopback,
|
|
conditions.le2StartBuffer //
|
|
);
|
|
|
|
//
|
|
CopySE2Start(
|
|
zIndex,
|
|
loopback,
|
|
conditions.se2StartBuffer //
|
|
);
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
int cIDX = 1;
|
|
int pIDX = cIDX + 1;
|
|
|
|
//
|
|
bool isChe1Bullish = le1Buffer[cIDX] != EMPTY_VALUE &&
|
|
se1Buffer[cIDX] == EMPTY_VALUE;
|
|
bool isChe1BullishPrev = le1Buffer[cIDX] != EMPTY_VALUE &&
|
|
se1Buffer[pIDX] == EMPTY_VALUE;
|
|
|
|
//
|
|
bool isChe1Bearish = se1Buffer[cIDX] != EMPTY_VALUE &&
|
|
le1Buffer[cIDX] == EMPTY_VALUE;
|
|
bool isChe1BearishPrev = se1Buffer[pIDX] != EMPTY_VALUE &&
|
|
le1Buffer[pIDX] == EMPTY_VALUE;
|
|
|
|
//
|
|
bool isChe1SwitchedToBullish = isChe1Bullish &&
|
|
!isChe1BullishPrev;
|
|
bool isChe1SwitchedToBearish = isChe1Bearish &&
|
|
!isChe1BearishPrev;
|
|
|
|
//
|
|
bool isChe2Bullish = le2Buffer[cIDX] != EMPTY_VALUE &&
|
|
se2Buffer[cIDX] == EMPTY_VALUE;
|
|
bool isChe2BullishPrev = le2Buffer[pIDX] != EMPTY_VALUE &&
|
|
se2Buffer[pIDX] == EMPTY_VALUE;
|
|
|
|
//
|
|
bool isChe2Bearish = se2Buffer[cIDX] != EMPTY_VALUE &&
|
|
le2Buffer[cIDX] == EMPTY_VALUE;
|
|
bool isChe2BearishPrev = se2Buffer[pIDX] != EMPTY_VALUE &&
|
|
le2Buffer[pIDX] == EMPTY_VALUE;
|
|
|
|
//
|
|
bool isChe2SwitchedToBullish = isChe2Bullish &&
|
|
!isChe2BullishPrev;
|
|
bool isChe2SwitchedToBearish = isChe2Bearish &&
|
|
!isChe2BearishPrev;
|
|
|
|
//
|
|
bool isCheBullish = isChe1Bullish &&
|
|
isChe2Bullish;
|
|
bool isCheBullishPrev = isChe1BullishPrev &&
|
|
isChe2BullishPrev;
|
|
|
|
//
|
|
bool isCheBearish = isChe1Bearish &&
|
|
isChe2Bearish;
|
|
bool isCheBearishPrev = isChe1BearishPrev &&
|
|
isChe2BearishPrev;
|
|
|
|
//
|
|
bool isCheSwitchedToBullish = isCheBullish &&
|
|
!isCheBullishPrev;
|
|
bool isCheSwitchedToBearish = isCheBearish &&
|
|
!isCheBearishPrev;
|
|
|
|
//
|
|
double ches[];
|
|
double prevCheLE1 = le1Buffer[pIDX];
|
|
double prevCheLE2 = le2Buffer[pIDX];
|
|
double prevCheSE1 = se1Buffer[pIDX];
|
|
double prevCheSE2 = se2Buffer[pIDX];
|
|
if (prevCheLE1 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
prevCheLE1,
|
|
ches //
|
|
);
|
|
}
|
|
if (prevCheLE2 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
prevCheLE2,
|
|
ches //
|
|
);
|
|
}
|
|
if (prevCheSE1 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
prevCheSE1,
|
|
ches //
|
|
);
|
|
}
|
|
if (prevCheSE2 != EMPTY_VALUE)
|
|
{
|
|
//
|
|
Add(
|
|
prevCheSE2,
|
|
ches //
|
|
);
|
|
}
|
|
|
|
//
|
|
double cheMin = GetMin(ches);
|
|
double cheMax = GetMax(ches);
|
|
|
|
//
|
|
conditions.isChe1Bullish = isChe1Bullish;
|
|
conditions.isChe1Bearish = isChe1Bearish;
|
|
conditions.isChe1SwitchedToBullish = isChe1SwitchedToBullish;
|
|
conditions.isChe1SwitchedToBearish = isChe1SwitchedToBearish;
|
|
conditions.isChe2Bullish = isChe2Bullish;
|
|
conditions.isChe2Bearish = isChe2Bearish;
|
|
conditions.isChe2SwitchedToBullish = isChe2SwitchedToBullish;
|
|
conditions.isChe2SwitchedToBearish = isChe2SwitchedToBearish;
|
|
conditions.isCheBullish = isCheBullish;
|
|
conditions.isCheBearish = isCheBearish;
|
|
conditions.isCheSwitchedToBullish = isCheSwitchedToBullish;
|
|
conditions.isCheSwitchedToBearish = isCheSwitchedToBearish;
|
|
|
|
//
|
|
Cleanup();
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
X121XCHEInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double le1Buffer[];
|
|
double se1Buffer[];
|
|
double le2Buffer[];
|
|
double se2Buffer[];
|
|
double le1StartBuffer[];
|
|
double se1StartBuffer[];
|
|
double le2StartBuffer[];
|
|
double se2StartBuffer[];
|
|
|
|
//
|
|
void Calculate(
|
|
int barIndex = 0,
|
|
int maxRequiredBars = 100 //
|
|
)
|
|
{
|
|
//
|
|
// Buffers ...
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
// LE1 Start ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_LE_1_S_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
le1StartBuffer //
|
|
);
|
|
|
|
//
|
|
// LE1 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_LE_1_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
le1Buffer //
|
|
);
|
|
|
|
//
|
|
// LE2 Start ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_LE_2_S_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
le2StartBuffer //
|
|
);
|
|
|
|
//
|
|
// LE2 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_LE_2_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
le2Buffer //
|
|
);
|
|
|
|
//
|
|
// SE1 Start ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_SE_1_S_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
se1StartBuffer //
|
|
);
|
|
|
|
//
|
|
// SE1 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_SE_1_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
se1Buffer //
|
|
);
|
|
|
|
//
|
|
// SE2 Start ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_SE_2_S_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
se2StartBuffer //
|
|
);
|
|
|
|
//
|
|
// SE2 ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
X121_XCHE_SE_2_LINE,
|
|
barIndex,
|
|
maxRequiredBars,
|
|
se2Buffer //
|
|
);
|
|
}
|
|
|
|
//
|
|
void Cleanup(
|
|
int maxAllowed = 100 //
|
|
)
|
|
{
|
|
//
|
|
CleanupArray(
|
|
le1Buffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
se1Buffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
le2Buffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
se2Buffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
le1StartBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
se1StartBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
le2StartBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
CleanupArray(
|
|
se2StartBuffer,
|
|
maxAllowed //
|
|
);
|
|
|
|
//
|
|
}
|
|
|
|
//
|
|
};
|
|
|
|
//
|
|
// Tools ... |