1632 lines
31 KiB
Plaintext
1632 lines
31 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Helper Class Library
|
|
// ----------------------------------------------
|
|
// Name: XSCXMRBHelper
|
|
// 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.xhelper.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
enum ENUM_XMRB_BUFFERS
|
|
{
|
|
//
|
|
// Ribbon ...
|
|
XMRB_FAST_LINE = 0,
|
|
XMRB_SLOW_LINE = 1,
|
|
//
|
|
// Ribbon 1 ...
|
|
XMRB_R1_FAST_LINE = 2,
|
|
XMRB_R1_SLOW_LINE = 3,
|
|
//
|
|
// Ribbon 2 ...
|
|
XMRB_R2_FAST_LINE = 4,
|
|
XMRB_R2_SLOW_LINE = 5,
|
|
//
|
|
// Ribbon 3 ...
|
|
XMRB_R3_FAST_LINE = 6,
|
|
XMRB_R3_SLOW_LINE = 7,
|
|
//
|
|
// Ribbon 4 ...
|
|
XMRB_R4_FAST_LINE = 8,
|
|
XMRB_R4_SLOW_LINE = 9,
|
|
//
|
|
// Ribbon 5 ...
|
|
XMRB_R5_FAST_LINE = 10,
|
|
XMRB_R5_SLOW_LINE = 11,
|
|
//
|
|
// Ribbon 5 ...
|
|
XMRB_R6_FAST_LINE = 12,
|
|
XMRB_R6_SLOW_LINE = 13,
|
|
};
|
|
|
|
//
|
|
// Input Models ...
|
|
struct XMRBInputs
|
|
{
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Ribbon 1 ...
|
|
int fast1Length; // Fast
|
|
int slow1Length; // Slow
|
|
ENUM_APPLIED_PRICE r1AppliedTo; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 2 ...
|
|
int fast2Length; // Fast
|
|
int slow2Length; // Slow
|
|
ENUM_APPLIED_PRICE r2AppliedTo; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 3 ...
|
|
int fast3Length; // Fast
|
|
int slow3Length; // Slow
|
|
ENUM_APPLIED_PRICE r3AppliedTo; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 4 ...
|
|
int fast4Length; // Fast
|
|
int slow4Length; // Slow
|
|
ENUM_APPLIED_PRICE r4AppliedTo; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 5 ...
|
|
int fast5Length; // Fast
|
|
int slow5Length; // Slow
|
|
ENUM_APPLIED_PRICE r5AppliedTo; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 6 ...
|
|
int fast6Length; // Fast
|
|
int slow6Length; // Slow
|
|
ENUM_APPLIED_PRICE r6AppliedTo; // AppliedTo
|
|
|
|
//
|
|
// Calculation ...
|
|
ENUM_MA_METHOD ribbonMode; // Mode
|
|
|
|
//
|
|
// Presentation ...
|
|
bool showFastMa; // Show Fast
|
|
bool showSlowMa; // Show Slow
|
|
bool showRibbon; // Show Ribbon
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
XMRBInputs()
|
|
{
|
|
//
|
|
Clean();
|
|
}
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Clean ...
|
|
void Clean()
|
|
{
|
|
//
|
|
// Ribbon 1 ...
|
|
fast1Length = 0; // Fast
|
|
slow1Length = 0; // Slow
|
|
r1AppliedTo = PRICE_HIGH; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 2 ...
|
|
fast2Length = 0; // Fast
|
|
slow2Length = 0; // Slow
|
|
r2AppliedTo = PRICE_OPEN; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 3 ...
|
|
fast3Length = 0; // Fast
|
|
slow3Length = 0; // Slow
|
|
r3AppliedTo = PRICE_CLOSE; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 4 ...
|
|
fast4Length = 0; // Fast
|
|
slow4Length = 0; // Slow
|
|
r4AppliedTo = PRICE_MEDIAN; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 5 ...
|
|
fast5Length = 0; // Fast
|
|
slow5Length = 0; // Slow
|
|
r5AppliedTo = PRICE_TYPICAL; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 6 ...
|
|
fast6Length = 0; // Fast
|
|
slow6Length = 0; // Slow
|
|
r6AppliedTo = PRICE_LOW; // AppliedTo
|
|
|
|
//
|
|
// Calculation ...
|
|
ribbonMode = MODE_EMA; // Mode
|
|
|
|
//
|
|
// Presentation ...
|
|
showFastMa = false; // Show Fast
|
|
showSlowMa = false; // Show Slow
|
|
showRibbon = false; // Show Ribbon
|
|
}
|
|
|
|
//
|
|
// Default ...
|
|
void Default()
|
|
{
|
|
//
|
|
// Ribbon 1 ...
|
|
fast1Length = 20; // Fast
|
|
slow1Length = 50; // Slow
|
|
r1AppliedTo = PRICE_HIGH; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 2 ...
|
|
fast2Length = 20; // Fast
|
|
slow2Length = 50; // Slow
|
|
r2AppliedTo = PRICE_OPEN; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 3 ...
|
|
fast3Length = 20; // Fast
|
|
slow3Length = 50; // Slow
|
|
r3AppliedTo = PRICE_CLOSE; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 4 ...
|
|
fast4Length = 20; // Fast
|
|
slow4Length = 50; // Slow
|
|
r4AppliedTo = PRICE_MEDIAN; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 5 ...
|
|
fast5Length = 20; // Fast
|
|
slow5Length = 50; // Slow
|
|
r5AppliedTo = PRICE_TYPICAL; // AppliedTo
|
|
|
|
//
|
|
// Ribbon 6 ...
|
|
fast6Length = 20; // Fast
|
|
slow6Length = 50; // Slow
|
|
r6AppliedTo = PRICE_LOW; // AppliedTo
|
|
|
|
//
|
|
// Calculation ...
|
|
ribbonMode = MODE_EMA; // Mode
|
|
|
|
//
|
|
// Presentation ...
|
|
showFastMa = true; // Show Fast
|
|
showSlowMa = true; // Show Slow
|
|
showRibbon = false; // Show Ribbon
|
|
}
|
|
|
|
//
|
|
// Validate ...
|
|
bool IsValid()
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
result =
|
|
//
|
|
(fast1Length > 2 &&
|
|
fast2Length > 2 &&
|
|
fast3Length > 2 &&
|
|
fast4Length > 2 &&
|
|
fast5Length > 2 &&
|
|
fast6Length > 2 &&
|
|
slow1Length > fast1Length &&
|
|
slow2Length > fast2Length &&
|
|
slow3Length > fast3Length &&
|
|
slow4Length > fast4Length &&
|
|
slow5Length > fast5Length &&
|
|
slow6Length > fast6Length
|
|
//
|
|
)
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Retrieve MAx Length ...
|
|
int Max()
|
|
{
|
|
//
|
|
int result = 0;
|
|
|
|
//
|
|
result = MathMax(fast1Length, fast2Length);
|
|
result = MathMax(result, fast3Length);
|
|
result = MathMax(result, fast4Length);
|
|
result = MathMax(result, fast5Length);
|
|
result = MathMax(result, fast6Length);
|
|
|
|
//
|
|
result = MathMax(result, slow1Length);
|
|
result = MathMax(result, slow2Length);
|
|
result = MathMax(result, slow3Length);
|
|
result = MathMax(result, slow4Length);
|
|
result = MathMax(result, slow5Length);
|
|
result = MathMax(result, slow6Length);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
};
|
|
|
|
//
|
|
// Define Conditions ...
|
|
struct XMRBConditions
|
|
{
|
|
//
|
|
// Common ...
|
|
string symbol;
|
|
ENUM_TIMEFRAMES period;
|
|
datetime time;
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
double fast[];
|
|
double slow[];
|
|
|
|
//
|
|
// Conditions ...
|
|
|
|
//
|
|
bool isFastOverSlow;
|
|
bool isFastUnderSlow;
|
|
bool isFastCrossedOverSlow;
|
|
bool isFastCrossedUnderSlow;
|
|
|
|
//
|
|
void Clean()
|
|
{
|
|
//
|
|
Clean(fast);
|
|
Clean(slow);
|
|
|
|
//
|
|
ArraySetAsSeries(fast, true);
|
|
ArraySetAsSeries(slow, true);
|
|
|
|
//
|
|
isFastOverSlow = false;
|
|
isFastUnderSlow = false;
|
|
isFastCrossedOverSlow = false;
|
|
isFastCrossedUnderSlow = false;
|
|
}
|
|
|
|
//
|
|
void GenerateScore(
|
|
double &bullishScore,
|
|
double &bearishScore //
|
|
)
|
|
{
|
|
//
|
|
bullishScore = 0;
|
|
bearishScore = 0;
|
|
|
|
//
|
|
if (isFastOverSlow)
|
|
{
|
|
bullishScore++;
|
|
}
|
|
if (isFastCrossedOverSlow)
|
|
{
|
|
bullishScore++;
|
|
}
|
|
|
|
//
|
|
if (isFastUnderSlow)
|
|
{
|
|
bearishScore++;
|
|
}
|
|
if (isFastCrossedUnderSlow)
|
|
{
|
|
bearishScore++;
|
|
}
|
|
}
|
|
|
|
//
|
|
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 =
|
|
//
|
|
ToString("isFastOverSlow", isFastOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isFastUnderSlow", isFastUnderSlow, ignoreFalseConditions, separator) +
|
|
ToString("isFastCrossedOverSlow", isFastCrossedOverSlow, ignoreFalseConditions, separator) +
|
|
ToString("isFastCrossedUnderSlow", isFastCrossedUnderSlow, ignoreFalseConditions, separator) +
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
result =
|
|
//
|
|
"[" + GetTag() + "]" + separator +
|
|
(onlyConditions
|
|
? ""
|
|
: commonStr) +
|
|
(!includeScores
|
|
? ""
|
|
: scoresStr) +
|
|
" " + separator +
|
|
(onlyCommons
|
|
? ""
|
|
: conditionsStr) +
|
|
""
|
|
//
|
|
;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string GetTag()
|
|
{
|
|
return "XMRB";
|
|
}
|
|
};
|
|
|
|
//
|
|
// Class ...
|
|
class XSCXMRBHelper : public XSCBaseHelper
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Constructors ...
|
|
XSCXMRBHelper() : XSCBaseHelper(_Symbol, _Period)
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
~XSCXMRBHelper() {}
|
|
|
|
//
|
|
// Tools ...
|
|
bool Init(
|
|
string symbol, // Trading Symbol
|
|
ENUM_TIMEFRAMES period, // Trading Period
|
|
XMRBInputs &inputs // Inputs
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
mSymbol = symbol;
|
|
mPeriod = period;
|
|
|
|
//
|
|
result = inputs.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
mInputs = inputs;
|
|
|
|
//
|
|
ArraySetAsSeries(fastBuffer, true);
|
|
ArraySetAsSeries(slowBuffer, true);
|
|
ArraySetAsSeries(r1FastBuffer, true);
|
|
ArraySetAsSeries(r1SlowBuffer, true);
|
|
ArraySetAsSeries(r2FastBuffer, true);
|
|
ArraySetAsSeries(r2SlowBuffer, true);
|
|
ArraySetAsSeries(r3FastBuffer, true);
|
|
ArraySetAsSeries(r3SlowBuffer, true);
|
|
ArraySetAsSeries(r4FastBuffer, true);
|
|
ArraySetAsSeries(r4SlowBuffer, true);
|
|
ArraySetAsSeries(r5FastBuffer, true);
|
|
ArraySetAsSeries(r5SlowBuffer, true);
|
|
ArraySetAsSeries(r6FastBuffer, true);
|
|
ArraySetAsSeries(r6SlowBuffer, true);
|
|
|
|
//
|
|
mHandler = iCustom(
|
|
mSymbol,
|
|
mPeriod,
|
|
"x-saherelm.xmrb",
|
|
//
|
|
// Inputs ...
|
|
//
|
|
// Ribbon 1 ...
|
|
"",
|
|
mInputs.fast1Length, // Fast
|
|
mInputs.slow1Length, // Slow
|
|
mInputs.r1AppliedTo, // AppliedTo
|
|
//
|
|
// Ribbon 2 ...
|
|
"",
|
|
mInputs.fast2Length, // Fast
|
|
mInputs.slow2Length, // Slow
|
|
mInputs.r2AppliedTo, // AppliedTo
|
|
//
|
|
// Ribbon 3 ...
|
|
"",
|
|
mInputs.fast3Length, // Fast
|
|
mInputs.slow3Length, // Slow
|
|
mInputs.r3AppliedTo, // AppliedTo
|
|
//
|
|
// Ribbon 4 ...
|
|
"",
|
|
mInputs.fast4Length, // Fast
|
|
mInputs.slow4Length, // Slow
|
|
mInputs.r4AppliedTo, // AppliedTo
|
|
//
|
|
// Ribbon 5 ...
|
|
"",
|
|
mInputs.fast5Length, // Fast
|
|
mInputs.slow5Length, // Slow
|
|
mInputs.r5AppliedTo, // AppliedTo
|
|
//
|
|
// Ribbon 6 ...
|
|
"",
|
|
mInputs.fast6Length, // Fast
|
|
mInputs.slow6Length, // Slow
|
|
mInputs.r6AppliedTo, // AppliedTo
|
|
//
|
|
// Calculation ...
|
|
"",
|
|
mInputs.ribbonMode, // Mode
|
|
//
|
|
// Presentation ...
|
|
"",
|
|
mInputs.showFastMa, // Show Fast
|
|
mInputs.showSlowMa, // Show Slow
|
|
mInputs.showRibbon // Show Ribbon
|
|
//
|
|
);
|
|
result = mHandler != INVALID_HANDLE;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Inputs ...
|
|
|
|
//
|
|
XMRBInputs GetInputs()
|
|
{
|
|
return mInputs;
|
|
}
|
|
|
|
//
|
|
bool SetInputs(
|
|
XMRBInputs &inputs // Configs
|
|
)
|
|
{
|
|
//
|
|
return Init(
|
|
mSymbol,
|
|
mPeriod,
|
|
inputs
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Buffers ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetFast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(fastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return fastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyFast(
|
|
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,
|
|
fastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetSlow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(slowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return slowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopySlow(
|
|
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,
|
|
slowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Ribbon 1 ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetR1Fast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r1FastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r1FastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR1Fast(
|
|
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,
|
|
r1FastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetR1Slow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r1SlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r1SlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR1Slow(
|
|
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,
|
|
r1SlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Ribbon 2 ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetR2Fast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r2FastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r2FastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR2Fast(
|
|
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,
|
|
r2FastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetR2Slow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r2SlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r2SlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR2Slow(
|
|
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,
|
|
r2SlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Ribbon 3 ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetR3Fast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r3FastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r3FastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR3Fast(
|
|
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,
|
|
r3FastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetR3Slow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r3SlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r3SlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR3Slow(
|
|
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,
|
|
r3SlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Ribbon 4 ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetR4Fast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r4FastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r4FastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR4Fast(
|
|
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,
|
|
r4FastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetR4Slow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r4SlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r4SlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR4Slow(
|
|
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,
|
|
r4SlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Ribbon 5 ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetR5Fast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r5FastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r5FastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR5Fast(
|
|
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,
|
|
r5FastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetR5Slow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r5SlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r5SlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR5Slow(
|
|
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,
|
|
r5SlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Ribbon 6 ...
|
|
|
|
//
|
|
// Fast ...
|
|
|
|
//
|
|
double GetR6Fast(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r6FastBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r6FastBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR6Fast(
|
|
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,
|
|
r6FastBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
// Slow ...
|
|
|
|
//
|
|
double GetR6Slow(
|
|
int barIndex // Bar Index
|
|
)
|
|
{
|
|
//
|
|
if (barIndex < 0)
|
|
{
|
|
barIndex = 0;
|
|
}
|
|
|
|
//
|
|
Calculate();
|
|
|
|
//
|
|
int count = ArraySize(r6SlowBuffer);
|
|
if (barIndex >= count)
|
|
{
|
|
barIndex = count - 1;
|
|
}
|
|
|
|
//
|
|
return r6SlowBuffer[barIndex];
|
|
}
|
|
|
|
//
|
|
// Copy Required Items ...
|
|
int CopyR6Slow(
|
|
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,
|
|
r6SlowBuffer,
|
|
buffer,
|
|
forceClean
|
|
//
|
|
);
|
|
}
|
|
|
|
//
|
|
bool GetConditions(
|
|
XMRBConditions &conditions, //
|
|
int barIndex = 0, //
|
|
int loopback = 3 //
|
|
)
|
|
{
|
|
//
|
|
bool result = true;
|
|
|
|
//
|
|
if (loopback < 3)
|
|
{
|
|
loopback = 3;
|
|
}
|
|
|
|
//
|
|
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;
|
|
|
|
//
|
|
CopyFast(
|
|
zIndex,
|
|
loopback,
|
|
conditions.fast //
|
|
);
|
|
CopySlow(
|
|
zIndex,
|
|
loopback,
|
|
conditions.slow //
|
|
);
|
|
|
|
//
|
|
// Calculate Conditions ...
|
|
|
|
//
|
|
bool isFastOverSlow = conditions.fast[cIndex] > conditions.slow[cIndex];
|
|
bool isFastUnderSlow = conditions.fast[cIndex] < conditions.slow[cIndex];
|
|
|
|
//
|
|
bool isFastOverSlowPrev = conditions.fast[pIndex] > conditions.slow[pIndex];
|
|
bool isFastUnderSlowPrev = conditions.fast[pIndex] < conditions.slow[pIndex];
|
|
|
|
//
|
|
bool isFastCrossedOverSlow = isFastOverSlow &&
|
|
!isFastOverSlowPrev;
|
|
bool isFastCrossedUnderSlow = isFastUnderSlow &&
|
|
!isFastUnderSlowPrev;
|
|
|
|
//
|
|
conditions.isFastOverSlow = isFastOverSlow;
|
|
conditions.isFastUnderSlow = isFastUnderSlow;
|
|
conditions.isFastCrossedOverSlow = isFastCrossedOverSlow;
|
|
conditions.isFastCrossedUnderSlow = isFastCrossedUnderSlow;
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
XMRBInputs mInputs; // Inputs ...
|
|
|
|
//
|
|
// Buffers ...
|
|
double fastBuffer[];
|
|
double slowBuffer[];
|
|
double r1FastBuffer[];
|
|
double r1SlowBuffer[];
|
|
double r2FastBuffer[];
|
|
double r2SlowBuffer[];
|
|
double r3FastBuffer[];
|
|
double r3SlowBuffer[];
|
|
double r4FastBuffer[];
|
|
double r4SlowBuffer[];
|
|
double r5FastBuffer[];
|
|
double r5SlowBuffer[];
|
|
double r6FastBuffer[];
|
|
double r6SlowBuffer[];
|
|
|
|
//
|
|
// Tools ...
|
|
|
|
//
|
|
// Calculate Values Until Now ...
|
|
void Calculate()
|
|
{
|
|
//
|
|
int totalBars = CountBars();
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
fastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
slowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Ribbon 1 ...
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R1_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
r1FastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R1_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
r1SlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Ribbon 2 ...
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R2_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
r2FastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R2_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
r2SlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Ribbon 3 ...
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R3_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
r3FastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R3_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
r3SlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Ribbon 4 ...
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R4_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
r4FastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R4_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
r4SlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Ribbon 5 ...
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R5_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
r5FastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R5_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
r5SlowBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Ribbon 6 ...
|
|
|
|
//
|
|
// Fast Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R6_FAST_LINE,
|
|
0,
|
|
totalBars,
|
|
r6FastBuffer
|
|
//
|
|
);
|
|
|
|
//
|
|
// Slow Buffer ...
|
|
CopyBuffer(
|
|
mHandler,
|
|
XMRB_R6_SLOW_LINE,
|
|
0,
|
|
totalBars,
|
|
r6SlowBuffer
|
|
//
|
|
);
|
|
}
|
|
};
|
|
|
|
//
|
|
// Tools ... |