Add Support for atr in x121 indicator ...

This commit is contained in:
2024-12-30 16:58:15 +03:30
parent 1868587608
commit 0bfed000db
3 changed files with 870 additions and 487 deletions
+490 -197
View File
@@ -33,47 +33,50 @@ enum ENUM_X121_BUFFERS
X121_PEAKS_LINE = 0,
X121_VALES_LINE = 1,
X121_SAR_LINE = 2,
X121_VWAP_FAST_LINE = 3,
X121_VWAP_MID_LINE = 5,
X121_VWAP_SLOW_LINE = 7,
X121_DON_OPEN_UPPER_LINE = 9,
X121_DON_OPEN_LOWER_LINE = 10,
X121_DON_HIGH_UPPER_LINE = 11,
X121_DON_HIGH_LOWER_LINE = 12,
X121_DON_LOW_UPPER_LINE = 13,
X121_DON_LOW_LOWER_LINE = 14,
X121_DON_CLOSE_UPPER_LINE = 15,
X121_DON_CLOSE_LOWER_LINE = 16,
X121_FIB_LEVEL_1_LINE = 17,
X121_FIB_LEVEL_2_LINE = 18,
X121_FIB_LEVEL_3_LINE = 19,
X121_FIB_LEVEL_4_LINE = 20,
X121_FIB_LEVEL_5_LINE = 21,
X121_ATR_UPPER_LINE = 3,
X121_ATR_LOWER_LINE = 4,
X121_VWAP_FAST_LINE = 5,
X121_VWAP_MID_LINE = 7,
X121_VWAP_SLOW_LINE = 9,
X121_DON_OPEN_UPPER_LINE = 11,
X121_DON_OPEN_LOWER_LINE = 12,
X121_DON_HIGH_UPPER_LINE = 13,
X121_DON_HIGH_LOWER_LINE = 14,
X121_DON_LOW_UPPER_LINE = 15,
X121_DON_LOW_LOWER_LINE = 16,
X121_DON_CLOSE_UPPER_LINE = 17,
X121_DON_CLOSE_LOWER_LINE = 18,
X121_FIB_LEVEL_1_LINE = 19,
X121_FIB_LEVEL_2_LINE = 20,
X121_FIB_LEVEL_3_LINE = 21,
X121_FIB_LEVEL_4_LINE = 22,
X121_FIB_LEVEL_5_LINE = 23,
//
// Data Buffers ...
//
// XPV Data ...
X121_CURRENT_HH_LINE = 22,
X121_CURRENT_LL_LINE = 23,
X121_SHORT_HH_LINE = 24,
X121_SHORT_LL_LINE = 25,
X121_MEDIUM_HH_LINE = 26,
X121_MEDIUM_LL_LINE = 27,
X121_LONG_HH_LINE = 28,
X121_LONG_LL_LINE = 29,
X121_HIND_HH_LINE = 30,
X121_HIND_LL_LINE = 31,
X121_CURRENT_HH_LINE = 24,
X121_CURRENT_LL_LINE = 25,
X121_SHORT_HH_LINE = 26,
X121_SHORT_LL_LINE = 27,
X121_MEDIUM_HH_LINE = 28,
X121_MEDIUM_LL_LINE = 29,
X121_LONG_HH_LINE = 30,
X121_LONG_LL_LINE = 31,
X121_HIND_HH_LINE = 32,
X121_HIND_LL_LINE = 33,
//
// VWAP Data ...
X121_VWAP_VOLUME_LINE = 32,
X121_VWAP_PRICE_LINE = 33,
X121_VWAP_FAST_STATE_LINE = 34,
X121_VWAP_MID_STATE_LINE = 35,
X121_VWAP_SLOW_STATE_LINE = 36,
X121_VWAP_VOLUME_LINE = 34,
X121_VWAP_PRICE_LINE = 35,
X121_VWAP_FAST_STATE_LINE = 36,
X121_VWAP_MID_STATE_LINE = 37,
X121_VWAP_SLOW_STATE_LINE = 38,
//
// VALID PEAKS and VALES ...
X121_VALID_PEAKS_LINE = 37,
X121_VALID_VALES_LINE = 38,
// ATR ...
X121_ATR_LINE = 39,
X121_ATR_UPPER_RAW_LINE = 40,
X121_ATR_LOWER_RAW_LINE = 41,
};
//
@@ -121,10 +124,18 @@ struct X121Inputs
ENUM_SERIESMODE llMode; // Lowest Low Calculation Method
//
// Paraboli Sar Detection ...
// Parabolic Sar Detection ...
double sarStep; // Step
double sarMax; // Maximum
//
// Atr Detection ...
int atrLength; // Length
double atrMultiplier; // Multiplier
ENUM_APPLIED_PRICE atrUpperAppliedTo; // Upper Zone Applied To
ENUM_APPLIED_PRICE atrLowerAppliedTo; // Lower Zone Applied To
ENUM_X_MA_METHOD atrSmoothingMode; // Smoothing Method
//
// VWap Detection ...
int vwapFastLength; // Fast Length
@@ -158,6 +169,7 @@ struct X121Inputs
//
// Global ...
bool showSar; // Show Parabolic Sar
bool showAtr; // Show Atr
bool showPeaks; // Show Peaks
bool showVales; // Show Vales
bool showVWap; // Show VWap
@@ -171,6 +183,11 @@ struct X121Inputs
bool showFibo4Levels; // Show Fibo 4th Level
bool showFibo5Levels; // Show Fibo 5th Level
//
// Atr Presentation ...
bool showAtrUpper; // Show Upper Zone
bool showAtrLower; // Show Lower Zone
//
// VWap Presentation ...
bool showVWapFast; // Show VWap Fast
@@ -238,6 +255,14 @@ struct X121Inputs
sarStep = 0;
sarMax = 0;
//
// Atr Detection ...
atrLength = 0; // Length
atrMultiplier = 0; // Multiplier
atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
atrSmoothingMode = X_MA_MODE_NONE; // Smoothing Method
//
// VWap Detection ...
vwapFastLength = 0;
@@ -271,6 +296,7 @@ struct X121Inputs
//
// Globals ...
showSar = false;
showAtr = false;
showPeaks = false;
showVales = false;
showVWap = false;
@@ -284,6 +310,11 @@ struct X121Inputs
showFibo4Levels = false;
showFibo5Levels = false;
//
// Atr Presentation ...
showAtrUpper = false; // Show Upper Zone
showAtrLower = false; // Show Lower Zone
//
// VWap Presentation ...
showVWapFast = false;
@@ -342,6 +373,14 @@ struct X121Inputs
sarStep = 0.02;
sarMax = 0.2;
//
// Atr Detection ...
atrLength = 14; // Length
atrMultiplier = 1; // Multiplier
atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
//
// VWap Detection ...
vwapFastLength = 20;
@@ -375,6 +414,7 @@ struct X121Inputs
//
// Globals ...
showSar = true;
showAtr = true;
showPeaks = true;
showVales = true;
showVWap = true;
@@ -388,6 +428,11 @@ struct X121Inputs
showFibo4Levels = false;
showFibo5Levels = false;
//
// Atr Presentation ...
showAtrUpper = true; // Show Upper Zone
showAtrLower = true; // Show Lower Zone
//
// VWap Presentation ...
showVWapFast = true;
@@ -426,6 +471,10 @@ struct X121Inputs
sarStep > 0 &&
sarMax > sarStep &&
//
// ATR ...
atrLength > 0 &&
atrMultiplier > 0 &&
//
// XDON ...
donchainLength > 0 &&
//
@@ -457,10 +506,14 @@ struct X121Inputs
int result = 0;
//
// XVWAP ...
// VWAP ...
result = MathMax(result, vwapFastLength);
result = MathMax(result, vwapFastLength);
result = MathMax(result, vwapMidLength);
result = MathMax(result, vwapSlowLength);
//
// ATR ...
result = MathMax(result, atrLength);
//
return result;
@@ -482,6 +535,8 @@ struct X121Conditions
double peaksBuffer[];
double valesBuffer[];
double sarBuffer[];
double atrUpperBuffer[];
double atrLowerBuffer[];
double vwapFastBuffer[];
double vwapMidBuffer[];
double vwapSlowBuffer[];
@@ -508,6 +563,9 @@ struct X121Conditions
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
double atrBuffer[];
double atrUpperRawBuffer[];
double atrLowerRawBuffer[];
double vwapVolumeBuffer[];
double vwapPriceBuffer[];
double vwapFastStateBuffer[];
@@ -652,6 +710,8 @@ struct X121Conditions
Clean(peaksBuffer);
Clean(valesBuffer);
Clean(sarBuffer);
Clean(atrUpperBuffer);
Clean(atrLowerBuffer);
Clean(vwapFastBuffer);
Clean(vwapMidBuffer);
Clean(vwapSlowBuffer);
@@ -678,6 +738,9 @@ struct X121Conditions
Clean(lLLBuffer);
Clean(hHHBuffer);
Clean(hLLBuffer);
Clean(atrBuffer);
Clean(atrUpperRawBuffer);
Clean(atrLowerRawBuffer);
Clean(vwapVolumeBuffer);
Clean(vwapPriceBuffer);
Clean(vwapFastStateBuffer);
@@ -690,6 +753,8 @@ struct X121Conditions
ArraySetAsSeries(peaksBuffer, true);
ArraySetAsSeries(valesBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(atrUpperBuffer, true);
ArraySetAsSeries(atrLowerBuffer, true);
ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(vwapSlowBuffer, true);
@@ -716,6 +781,9 @@ struct X121Conditions
ArraySetAsSeries(lLLBuffer, true);
ArraySetAsSeries(hHHBuffer, true);
ArraySetAsSeries(hLLBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(atrUpperRawBuffer, true);
ArraySetAsSeries(atrLowerRawBuffer, true);
ArraySetAsSeries(vwapVolumeBuffer, true);
ArraySetAsSeries(vwapPriceBuffer, true);
ArraySetAsSeries(vwapFastStateBuffer, true);
@@ -1064,6 +1132,8 @@ class XCX121Helper : public XCBaseHelper
ArraySetAsSeries(peaksBuffer, true);
ArraySetAsSeries(valesBuffer, true);
ArraySetAsSeries(sarBuffer, true);
ArraySetAsSeries(atrUpperBuffer, true);
ArraySetAsSeries(atrLowerBuffer, true);
ArraySetAsSeries(vwapFastBuffer, true);
ArraySetAsSeries(vwapMidBuffer, true);
ArraySetAsSeries(vwapSlowBuffer, true);
@@ -1090,13 +1160,14 @@ class XCX121Helper : public XCBaseHelper
ArraySetAsSeries(lLLBuffer, true);
ArraySetAsSeries(hHHBuffer, true);
ArraySetAsSeries(hLLBuffer, true);
ArraySetAsSeries(atrBuffer, true);
ArraySetAsSeries(atrUpperRawBuffer, true);
ArraySetAsSeries(atrLowerRawBuffer, true);
ArraySetAsSeries(vwapVolumeBuffer, true);
ArraySetAsSeries(vwapPriceBuffer, true);
ArraySetAsSeries(vwapFastStateBuffer, true);
ArraySetAsSeries(vwapMidStateBuffer, true);
ArraySetAsSeries(vwapSlowStateBuffer, true);
ArraySetAsSeries(validPeaksBuffer, true);
ArraySetAsSeries(validValesBuffer, true);
//
mHandler = iCustom(
@@ -1134,11 +1205,19 @@ class XCX121Helper : public XCBaseHelper
mInputs.hhMode,
mInputs.llMode,
//
// Paraboli Sar Detection ...
// Parabolic Sar Detection ...
"",
mInputs.sarStep,
mInputs.sarMax,
//
// Atr Detection ...
"",
mInputs.atrLength,
mInputs.atrMultiplier,
mInputs.atrUpperAppliedTo,
mInputs.atrLowerAppliedTo,
mInputs.atrSmoothingMode,
//
// VWap Detection ...
"",
mInputs.vwapFastLength,
@@ -1150,23 +1229,13 @@ class XCX121Helper : public XCBaseHelper
"",
mInputs.donchainLength,
//
// Fibonacci ...
"",
mInputs.fiboLevel1,
mInputs.fiboLevel2,
mInputs.fiboLevel3,
mInputs.fiboLevel4,
mInputs.fiboLevel5,
//
// Presentation ...
"",
mInputs.startCalculationForLastBars,
mInputs.sarArrowCode,
mInputs.peaksArrowCode,
mInputs.valesArrowCode,
//
// Commons ...
mInputs.showSar,
mInputs.showAtr,
mInputs.showPeaks,
mInputs.showVales,
mInputs.showVWap,
@@ -1180,6 +1249,11 @@ class XCX121Helper : public XCBaseHelper
mInputs.showFibo4Levels,
mInputs.showFibo5Levels,
//
// Atr Presentation ...
"",
mInputs.showAtrUpper,
mInputs.showAtrLower,
//
// VWap Presentation ...
"",
mInputs.showVWapFast,
@@ -1195,6 +1269,20 @@ class XCX121Helper : public XCBaseHelper
mInputs.showClose,
mInputs.showLow
//
// Non Important Inpust ...
//
// Fibonacci ...
// "",
// mInputs.fiboLevel1,
// mInputs.fiboLevel2,
// mInputs.fiboLevel3,
// mInputs.fiboLevel4,
// mInputs.fiboLevel5,
// //
// mInputs.sarArrowCode,
// mInputs.peaksArrowCode,
// mInputs.valesArrowCode
//
);
result = mHandler != INVALID_HANDLE;
if (!result)
@@ -1235,13 +1323,14 @@ class XCX121Helper : public XCBaseHelper
//
);
}
/**
* Retrieve DON Chain Length ...
*
*
* @return ( int )
*/
int GetDonChainLength() {
int GetDonChainLength()
{
return mInputs.donchainLength;
}
@@ -1249,7 +1338,7 @@ class XCX121Helper : public XCBaseHelper
// Implement Value Getters ...
//
// XSAR ...
// SAR ...
//
double GetSar(
@@ -1301,7 +1390,258 @@ class XCX121Helper : public XCBaseHelper
}
//
// XPV ...
// ATR ...
//
// Common ...
//
double GetAtr(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
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();
//
// Copy Items ...
return Copy(
start,
count,
atrBuffer,
buffer,
forceClean
//
);
}
//
double GetAtrUpper(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(atrUpperBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrUpperBuffer[barIndex];
}
//
int CopyAtrUpper(
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,
atrUpperBuffer,
buffer,
forceClean
//
);
}
//
double GetAtrUpperRaw(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(atrUpperRawBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrUpperRawBuffer[barIndex];
}
//
int CopyAtrUpperRaw(
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,
atrUpperRawBuffer,
buffer,
forceClean
//
);
}
//
double GetAtrLower(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(atrLowerBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrLowerBuffer[barIndex];
}
//
int CopyAtrLower(
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,
atrLowerBuffer,
buffer,
forceClean
//
);
}
//
double GetAtrLowerRaw(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(atrLowerRawBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return atrLowerRawBuffer[barIndex];
}
//
int CopyAtrLowerRaw(
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,
atrLowerRawBuffer,
buffer,
forceClean
//
);
}
//
// PV ...
//
// PEAKS ...
@@ -1943,111 +2283,7 @@ class XCX121Helper : public XCBaseHelper
}
//
// VALID PEAKS ...
//
double GetValidPeak(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(validPeaksBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return validPeaksBuffer[barIndex];
}
//
int CopyValidPeak(
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,
validPeaksBuffer,
buffer,
forceClean
//
);
}
//
// VALID VALES ...
//
double GetValidVale(
int barIndex // Bar Index
)
{
//
if (barIndex < 0)
{
barIndex = 0;
}
//
Calculate();
//
int count = ArraySize(validValesBuffer);
if (barIndex >= count)
{
barIndex = count - 1;
}
//
return validValesBuffer[barIndex];
}
//
int CopyValidVale(
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,
validValesBuffer,
buffer,
forceClean
//
);
}
//
// XVWAP ...
// VWAP ...
//
// FAST ...
@@ -3292,6 +3528,41 @@ class XCX121Helper : public XCBaseHelper
conditions.sarBuffer //
);
//
CopyAtr(
zIndex,
loopback,
conditions.atrBuffer //
);
//
CopyAtrUpper(
zIndex,
loopback,
conditions.atrUpperBuffer //
);
//
CopyAtrUpperRaw(
zIndex,
loopback,
conditions.atrUpperRawBuffer //
);
//
CopyAtrLower(
zIndex,
loopback,
conditions.atrLowerBuffer //
);
//
CopyAtrLowerRaw(
zIndex,
loopback,
conditions.atrLowerRawBuffer //
);
//
CopyPeak(
zIndex,
@@ -3376,20 +3647,6 @@ class XCX121Helper : public XCBaseHelper
conditions.hLLBuffer //
);
//
CopyValidPeak(
zIndex,
loopback,
conditions.validPeaksBuffer //
);
//
CopyValidVale(
zIndex,
loopback,
conditions.validValesBuffer //
);
//
CopyVWapFast(
zIndex,
@@ -3797,6 +4054,8 @@ class XCX121Helper : public XCBaseHelper
double peaksBuffer[];
double valesBuffer[];
double sarBuffer[];
double atrUpperBuffer[];
double atrLowerBuffer[];
double vwapFastBuffer[];
double vwapMidBuffer[];
double vwapSlowBuffer[];
@@ -3823,6 +4082,9 @@ class XCX121Helper : public XCBaseHelper
double lLLBuffer[];
double hHHBuffer[];
double hLLBuffer[];
double atrBuffer[];
double atrUpperRawBuffer[];
double atrLowerRawBuffer[];
double vwapVolumeBuffer[];
double vwapPriceBuffer[];
double vwapFastStateBuffer[];
@@ -3860,6 +4122,59 @@ class XCX121Helper : public XCBaseHelper
//
);
//
// ATR ...
//
CopyBuffer(
mHandler,
X121_ATR_UPPER_LINE,
0,
totalBars,
atrUpperBuffer
//
);
//
CopyBuffer(
mHandler,
X121_ATR_LOWER_LINE,
0,
totalBars,
atrLowerBuffer
//
);
//
CopyBuffer(
mHandler,
X121_ATR_LINE,
0,
totalBars,
atrBuffer
//
);
//
CopyBuffer(
mHandler,
X121_ATR_UPPER_RAW_LINE,
0,
totalBars,
atrUpperRawBuffer
//
);
//
CopyBuffer(
mHandler,
X121_ATR_LOWER_RAW_LINE,
0,
totalBars,
atrLowerRawBuffer
//
);
//
// XPV ...
@@ -3885,28 +4200,6 @@ class XCX121Helper : public XCBaseHelper
//
);
//
// VALID PEAKS ...
CopyBuffer(
mHandler,
X121_VALID_PEAKS_LINE,
0,
totalBars,
validPeaksBuffer
//
);
//
// VALID VALES ...
CopyBuffer(
mHandler,
X121_VALID_VALES_LINE,
0,
totalBars,
validValesBuffer
//
);
//
// CURRENT ...