Add Support for atr in x121 indicator ...
This commit is contained in:
+359
-279
@@ -63,10 +63,18 @@ input ENUM_SERIESMODE hhMode = MODE_HIGH; // Highest High Calculation Method
|
||||
input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
|
||||
|
||||
//
|
||||
input group "Paraboli Sar Detection";
|
||||
input group "Parabolic Sar Detection";
|
||||
input double sarStep = 0.02; // Step
|
||||
input double sarMax = 0.2; // Maximum
|
||||
|
||||
//
|
||||
input group "Atr Detection";
|
||||
input int atrLength = 14; // Length
|
||||
input double atrMultiplier = 1; // Multiplier
|
||||
input ENUM_APPLIED_PRICE atrUpperAppliedTo = PRICE_HIGH; // Upper Zone Applied To
|
||||
input ENUM_APPLIED_PRICE atrLowerAppliedTo = PRICE_LOW; // Lower Zone Applied To
|
||||
input ENUM_X_MA_METHOD atrSmoothingMode = X_MA_MODE_EMA; // Smoothing Method
|
||||
|
||||
//
|
||||
input group "VWap Detection";
|
||||
input int vwapFastLength = 20; // Fast Length
|
||||
@@ -78,27 +86,15 @@ input ENUM_APPLIED_PRICE vwapAppliedTo = PRICE_CLOSE; // Applied To
|
||||
input group "Donchain Detection";
|
||||
input int donchainLength = 40; // Donchain Length
|
||||
|
||||
//
|
||||
input group "Fibonacci";
|
||||
input double fiboLevel1 = 0.236; // Fibio 1st Level
|
||||
input double fiboLevel2 = 0.382; // Fibio 2st Level
|
||||
input double fiboLevel3 = 0.5; // Fibio 3rd Level
|
||||
input double fiboLevel4 = 0.618; // Fibio 4th Level
|
||||
input double fiboLevel5 = 0.764; // Fibio 5th Level
|
||||
|
||||
//
|
||||
input group "Presentation";
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1000; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input int sarArrowCode = 159; // Parabolic Sar Arrow Code
|
||||
input int peaksArrowCode = 159; // Peaks Arrow Code
|
||||
input int valesArrowCode = 159; // Vales Arrow Code
|
||||
|
||||
//
|
||||
input bool showSar = true; // Show Parabolic Sar
|
||||
input bool showAtr = true; // Show Atr
|
||||
input bool showPeaks = true; // Show Peaks
|
||||
input bool showVales = true; // Show Vales
|
||||
input bool showVWap = true; // Show VWap
|
||||
@@ -112,6 +108,11 @@ input bool showFibo3Levels = false; // Show Fibo 3rd Level
|
||||
input bool showFibo4Levels = false; // Show Fibo 4th Level
|
||||
input bool showFibo5Levels = false; // Show Fibo 5th Level
|
||||
|
||||
//
|
||||
input group "Atr Presentation";
|
||||
input bool showAtrUpper = true; // Show Upper Zone
|
||||
input bool showAtrLower = true; // Show Lower Zone
|
||||
|
||||
//
|
||||
input group "VWap Presentation";
|
||||
input bool showVWapFast = true; // Show VWap Fast
|
||||
@@ -127,6 +128,22 @@ input bool showHigh = false; // Show High
|
||||
input bool showClose = true; // Show Close
|
||||
input bool showLow = false; // Show Low
|
||||
|
||||
//
|
||||
// Non Important Inputs ...
|
||||
|
||||
//
|
||||
input group "Fibonacci";
|
||||
input double fiboLevel1 = 0.236; // Fibio 1st Level
|
||||
input double fiboLevel2 = 0.382; // Fibio 2st Level
|
||||
input double fiboLevel3 = 0.5; // Fibio 3rd Level
|
||||
input double fiboLevel4 = 0.618; // Fibio 4th Level
|
||||
input double fiboLevel5 = 0.764; // Fibio 5th Level
|
||||
|
||||
//
|
||||
input int sarArrowCode = 159; // Parabolic Sar Arrow Code
|
||||
input int peaksArrowCode = 159; // Peaks Arrow Code
|
||||
input int valesArrowCode = 159; // Vales Arrow Code
|
||||
|
||||
//
|
||||
// Buffers ...
|
||||
|
||||
@@ -140,8 +157,8 @@ input bool showLow = false; // Show Low
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 39
|
||||
#property indicator_plots 19
|
||||
#property indicator_buffers 42
|
||||
#property indicator_plots 21
|
||||
|
||||
//
|
||||
// PEAKS ...
|
||||
@@ -169,6 +186,9 @@ double valesBuffer[];
|
||||
#property indicator_color2 clrMagenta
|
||||
#property indicator_width2 1
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
//
|
||||
#define sarBufferIndex 2
|
||||
double sarBuffer[];
|
||||
@@ -180,52 +200,84 @@ double sarBuffer[];
|
||||
#property indicator_width3 1
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define vwapFastBufferIndex 3
|
||||
double vwapFastBuffer[];
|
||||
|
||||
#define vwapFastColorBufferIndex 4
|
||||
double vwapFastColorBuffer[];
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
#define vwapFastPlotBufferIndex 3
|
||||
#property indicator_label4 "X121 VWF"
|
||||
#property indicator_type4 DRAW_COLOR_LINE
|
||||
#property indicator_color4 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style4 STYLE_SOLID
|
||||
// Upper ...
|
||||
|
||||
//
|
||||
#define atrUpperBufferIndex 3
|
||||
double atrUpperBuffer[];
|
||||
|
||||
#property indicator_label4 "X121 ATRU"
|
||||
#property indicator_type4 DRAW_LINE
|
||||
#property indicator_color4 clrYellow
|
||||
#property indicator_style4 STYLE_DOT
|
||||
#property indicator_width4 2
|
||||
|
||||
//
|
||||
// MID ...
|
||||
#define vwapMidBufferIndex 5
|
||||
double vwapMidBuffer[];
|
||||
|
||||
#define vwapMidColorBufferIndex 6
|
||||
double vwapMidColorBuffer[];
|
||||
// Lower ...
|
||||
|
||||
//
|
||||
#define vwapMidPlotBufferIndex 4
|
||||
#property indicator_label5 "X121 VWM"
|
||||
#property indicator_type5 DRAW_COLOR_LINE
|
||||
#property indicator_color5 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style5 STYLE_SOLID
|
||||
#define atrLowerBufferIndex 4
|
||||
double atrLowerBuffer[];
|
||||
|
||||
#property indicator_label5 "X121 ATRL"
|
||||
#property indicator_type5 DRAW_LINE
|
||||
#property indicator_color5 clrYellow
|
||||
#property indicator_style5 STYLE_DOT
|
||||
#property indicator_width5 2
|
||||
|
||||
//
|
||||
// VWAP ...
|
||||
|
||||
//
|
||||
// FAST ...
|
||||
#define vwapFastBufferIndex 5
|
||||
double vwapFastBuffer[];
|
||||
|
||||
#define vwapFastColorBufferIndex 6
|
||||
double vwapFastColorBuffer[];
|
||||
|
||||
//
|
||||
#define vwapFastPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 VWF"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 2
|
||||
|
||||
//
|
||||
// MID ...
|
||||
#define vwapMidBufferIndex 7
|
||||
double vwapMidBuffer[];
|
||||
|
||||
#define vwapMidColorBufferIndex 8
|
||||
double vwapMidColorBuffer[];
|
||||
|
||||
//
|
||||
#define vwapMidPlotBufferIndex 6
|
||||
#property indicator_label7 "X121 VWM"
|
||||
#property indicator_type7 DRAW_COLOR_LINE
|
||||
#property indicator_color7 CLR_NONE, clrGreen, clrRed, clrGray
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
#property indicator_width7 2
|
||||
|
||||
//
|
||||
// SLOW ...
|
||||
#define vwapSlowBufferIndex 7
|
||||
#define vwapSlowBufferIndex 9
|
||||
double vwapSlowBuffer[];
|
||||
|
||||
#define vwapSlowColorBufferIndex 8
|
||||
#define vwapSlowColorBufferIndex 10
|
||||
double vwapSlowColorBuffer[];
|
||||
|
||||
//
|
||||
#define vwapSlowPlotBufferIndex 5
|
||||
#property indicator_label6 "X121 VWS"
|
||||
#property indicator_type6 DRAW_COLOR_LINE
|
||||
#property indicator_color6 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
|
||||
#property indicator_style6 STYLE_SOLID
|
||||
#property indicator_width6 2
|
||||
#define vwapSlowPlotBufferIndex 7
|
||||
#property indicator_label8 "X121 VWS"
|
||||
#property indicator_type8 DRAW_COLOR_LINE
|
||||
#property indicator_color8 CLR_NONE, clrSteelBlue, clrDarkRed, clrGray
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 2
|
||||
|
||||
//
|
||||
// XDON ...
|
||||
@@ -234,101 +286,101 @@ double vwapSlowColorBuffer[];
|
||||
// Open ...
|
||||
|
||||
//
|
||||
#define donOpenUpperBufferIndex 9
|
||||
#define donOpenUpperBufferIndex 11
|
||||
double donOpenUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donOpenUpperPlotBufferIndex 6
|
||||
#property indicator_label7 "X121 O U"
|
||||
#property indicator_type7 DRAW_LINE
|
||||
#property indicator_color7 clrCornflowerBlue
|
||||
#property indicator_width7 1
|
||||
#define donOpenUpperPlotBufferIndex 8
|
||||
#property indicator_label9 "X121 O U"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrCornflowerBlue
|
||||
#property indicator_width9 1
|
||||
|
||||
//
|
||||
#define donOpenLowerBufferIndex 10
|
||||
#define donOpenLowerBufferIndex 12
|
||||
double donOpenLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donOpenLowerPlotBufferIndex 7
|
||||
#property indicator_label8 "X121 O L"
|
||||
#property indicator_type8 DRAW_LINE
|
||||
#property indicator_color8 clrCornflowerBlue
|
||||
#property indicator_width8 1
|
||||
#define donOpenLowerPlotBufferIndex 9
|
||||
#property indicator_label10 "X121 O L"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrCornflowerBlue
|
||||
#property indicator_width10 1
|
||||
|
||||
//
|
||||
// High ...
|
||||
|
||||
//
|
||||
#define donHighUpperBufferIndex 11
|
||||
#define donHighUpperBufferIndex 13
|
||||
double donHighUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donHighUpperPlotBufferIndex 8
|
||||
#property indicator_label9 "X121 H U"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrAquamarine
|
||||
#property indicator_width9 1
|
||||
#define donHighUpperPlotBufferIndex 10
|
||||
#property indicator_label11 "X121 H U"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrAquamarine
|
||||
#property indicator_width11 1
|
||||
|
||||
//
|
||||
#define donHighLowerBufferIndex 12
|
||||
#define donHighLowerBufferIndex 14
|
||||
double donHighLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donHighLowerPlotBufferIndex 9
|
||||
#property indicator_label10 "X121 H L"
|
||||
#property indicator_type10 DRAW_LINE
|
||||
#property indicator_color10 clrAquamarine
|
||||
#property indicator_width10 1
|
||||
#define donHighLowerPlotBufferIndex 11
|
||||
#property indicator_label12 "X121 H L"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrAquamarine
|
||||
#property indicator_width12 1
|
||||
|
||||
//
|
||||
// Low ...
|
||||
|
||||
//
|
||||
#define donLowUpperBufferIndex 13
|
||||
#define donLowUpperBufferIndex 15
|
||||
double donLowUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donLowUpperPlotBufferIndex 10
|
||||
#property indicator_label11 "X121 L U"
|
||||
#property indicator_type11 DRAW_LINE
|
||||
#property indicator_color11 clrDarkOrchid
|
||||
#property indicator_width11 1
|
||||
#define donLowUpperPlotBufferIndex 12
|
||||
#property indicator_label13 "X121 L U"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrDarkOrchid
|
||||
#property indicator_width13 1
|
||||
|
||||
//
|
||||
#define donLowLowerBufferIndex 14
|
||||
#define donLowLowerBufferIndex 16
|
||||
double donLowLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donLowLowerPlotBufferIndex 11
|
||||
#property indicator_label12 "X121 L L"
|
||||
#property indicator_type12 DRAW_LINE
|
||||
#property indicator_color12 clrDarkOrchid
|
||||
#property indicator_width12 1
|
||||
#define donLowLowerPlotBufferIndex 13
|
||||
#property indicator_label14 "X121 L L"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrDarkOrchid
|
||||
#property indicator_width14 1
|
||||
|
||||
//
|
||||
// Close ...
|
||||
|
||||
//
|
||||
#define donCloseUpperBufferIndex 15
|
||||
#define donCloseUpperBufferIndex 17
|
||||
double donCloseUpperBuffer[];
|
||||
|
||||
//
|
||||
#define donCloseUpperPlotBufferIndex 12
|
||||
#property indicator_label13 "X121 C U"
|
||||
#property indicator_type13 DRAW_LINE
|
||||
#property indicator_color13 clrCoral
|
||||
#property indicator_width13 1
|
||||
#define donCloseUpperPlotBufferIndex 14
|
||||
#property indicator_label15 "X121 C U"
|
||||
#property indicator_type15 DRAW_LINE
|
||||
#property indicator_color15 clrCoral
|
||||
#property indicator_width15 1
|
||||
|
||||
//
|
||||
#define donCloseLowerBufferIndex 16
|
||||
#define donCloseLowerBufferIndex 18
|
||||
double donCloseLowerBuffer[];
|
||||
|
||||
//
|
||||
#define donCloseLowerPlotBufferIndex 13
|
||||
#property indicator_label14 "X121 C L"
|
||||
#property indicator_type14 DRAW_LINE
|
||||
#property indicator_color14 clrCoral
|
||||
#property indicator_width14 1
|
||||
#define donCloseLowerPlotBufferIndex 15
|
||||
#property indicator_label16 "X121 C L"
|
||||
#property indicator_type16 DRAW_LINE
|
||||
#property indicator_color16 clrCoral
|
||||
#property indicator_width16 1
|
||||
|
||||
//
|
||||
// FIBONACCI ...
|
||||
@@ -337,82 +389,82 @@ double donCloseLowerBuffer[];
|
||||
// FIBBO Level 1 ...
|
||||
|
||||
//
|
||||
#define fl1BufferIndex 17
|
||||
#define fl1BufferIndex 19
|
||||
double fl1Buffer[];
|
||||
|
||||
//
|
||||
#define fl1PlotBufferIndex 14
|
||||
#property indicator_label15 "X121 FL1"
|
||||
#property indicator_type15 DRAW_LINE
|
||||
#property indicator_color15 clrGold
|
||||
#property indicator_style15 STYLE_DASHDOTDOT
|
||||
#property indicator_width15 1
|
||||
|
||||
//
|
||||
// FIBBO Level 2 ...
|
||||
|
||||
//
|
||||
#define fl2BufferIndex 18
|
||||
double fl2Buffer[];
|
||||
|
||||
//
|
||||
#define fl2PlotBufferIndex 15
|
||||
#property indicator_label16 "X121 FL2"
|
||||
#property indicator_type16 DRAW_LINE
|
||||
#property indicator_color16 clrGold
|
||||
#property indicator_style16 STYLE_DASHDOTDOT
|
||||
#property indicator_width16 1
|
||||
|
||||
//
|
||||
// FIBBO Level 3 ...
|
||||
|
||||
//
|
||||
#define fl3BufferIndex 19
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
#define fl3PlotBufferIndex 16
|
||||
#property indicator_label17 "X121 FL3"
|
||||
#define fl1PlotBufferIndex 16
|
||||
#property indicator_label17 "X121 FL1"
|
||||
#property indicator_type17 DRAW_LINE
|
||||
#property indicator_color17 clrGold
|
||||
#property indicator_style17 STYLE_DASHDOTDOT
|
||||
#property indicator_width17 1
|
||||
|
||||
//
|
||||
// FIBBO Level 4 ...
|
||||
// FIBBO Level 2 ...
|
||||
|
||||
//
|
||||
#define fl4BufferIndex 20
|
||||
double fl4Buffer[];
|
||||
#define fl2BufferIndex 20
|
||||
double fl2Buffer[];
|
||||
|
||||
//
|
||||
#define fl4PlotBufferIndex 17
|
||||
#property indicator_label18 "X121 FL4"
|
||||
#define fl2PlotBufferIndex 17
|
||||
#property indicator_label18 "X121 FL2"
|
||||
#property indicator_type18 DRAW_LINE
|
||||
#property indicator_color18 clrGold
|
||||
#property indicator_style18 STYLE_DASHDOTDOT
|
||||
#property indicator_width18 1
|
||||
|
||||
//
|
||||
// FIBBO Level 5 ...
|
||||
// FIBBO Level 3 ...
|
||||
|
||||
//
|
||||
#define fl5BufferIndex 21
|
||||
double fl5Buffer[];
|
||||
#define fl3BufferIndex 21
|
||||
double fl3Buffer[];
|
||||
|
||||
//
|
||||
#define fl5PlotBufferIndex 18
|
||||
#property indicator_label19 "X121 FL5"
|
||||
#define fl3PlotBufferIndex 18
|
||||
#property indicator_label19 "X121 FL3"
|
||||
#property indicator_type19 DRAW_LINE
|
||||
#property indicator_color19 clrGold
|
||||
#property indicator_style19 STYLE_DASHDOTDOT
|
||||
#property indicator_width19 1
|
||||
|
||||
//
|
||||
// FIBBO Level 4 ...
|
||||
|
||||
//
|
||||
#define fl4BufferIndex 22
|
||||
double fl4Buffer[];
|
||||
|
||||
//
|
||||
#define fl4PlotBufferIndex 19
|
||||
#property indicator_label20 "X121 FL4"
|
||||
#property indicator_type20 DRAW_LINE
|
||||
#property indicator_color20 clrGold
|
||||
#property indicator_style20 STYLE_DASHDOTDOT
|
||||
#property indicator_width20 1
|
||||
|
||||
//
|
||||
// FIBBO Level 5 ...
|
||||
|
||||
//
|
||||
#define fl5BufferIndex 23
|
||||
double fl5Buffer[];
|
||||
|
||||
//
|
||||
#define fl5PlotBufferIndex 20
|
||||
#property indicator_label21 "X121 FL5"
|
||||
#property indicator_type21 DRAW_LINE
|
||||
#property indicator_color21 clrGold
|
||||
#property indicator_style21 STYLE_DASHDOTDOT
|
||||
#property indicator_width21 1
|
||||
|
||||
//
|
||||
// Data Buffers ...
|
||||
|
||||
//
|
||||
int mLastBufferIndex = 21;
|
||||
int mLastBufferIndex = 23;
|
||||
|
||||
//
|
||||
// CURRENT ...
|
||||
@@ -495,13 +547,16 @@ double vwapMidStateBuffer[];
|
||||
double vwapSlowStateBuffer[];
|
||||
|
||||
//
|
||||
// Valid Peaks and Vales ...
|
||||
// ATR ...
|
||||
|
||||
#define validPeaksBufferIndex mLastBufferIndex + 16
|
||||
double validPeaksBuffer[];
|
||||
#define atrBufferIndex mLastBufferIndex + 16
|
||||
double atrBuffer[];
|
||||
|
||||
#define validValesBufferIndex mLastBufferIndex + 17
|
||||
double validValesBuffer[];
|
||||
#define atrUpperRawBufferIndex mLastBufferIndex + 17
|
||||
double atrUpperRawBuffer[];
|
||||
|
||||
#define atrLowerRawBufferIndex mLastBufferIndex + 18
|
||||
double atrLowerRawBuffer[];
|
||||
|
||||
//
|
||||
// Variables, Properties and etc ...
|
||||
@@ -517,6 +572,10 @@ int maxLength;
|
||||
// SAR Handler ...
|
||||
int sarHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
// ATR Handler ...
|
||||
int atrHandler = INVALID_HANDLE;
|
||||
|
||||
//
|
||||
double mHideColorIDX = 0;
|
||||
|
||||
@@ -574,6 +633,19 @@ int OnInit()
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
atrHandler = iATR(
|
||||
_Symbol,
|
||||
_Period,
|
||||
atrLength //
|
||||
);
|
||||
isInited = atrHandler != INVALID_HANDLE;
|
||||
if (!isInited)
|
||||
{
|
||||
return INIT_FAILED;
|
||||
}
|
||||
|
||||
//
|
||||
if (!InitMarketCycles())
|
||||
{
|
||||
@@ -621,6 +693,7 @@ void OnDeinit(const int reason)
|
||||
|
||||
//
|
||||
IndicatorRelease(sarHandler);
|
||||
IndicatorRelease(atrHandler);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -680,10 +753,17 @@ int OnCalculate(
|
||||
// SAR ...
|
||||
int sarCalculatedBars = BarsCalculated(sarHandler);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int atrCalculatedBars = BarsCalculated(atrHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
//
|
||||
// SAR ...
|
||||
sarCalculatedBars >= maxLength &&
|
||||
//
|
||||
// ATR...
|
||||
sarCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
@@ -702,13 +782,18 @@ int OnCalculate(
|
||||
// SAR ...
|
||||
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
int copiedAtrs = CopyBuffer(atrHandler, 0, 0, limit, atrBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
bool isPassedRequiredCopiedItems =
|
||||
//
|
||||
//
|
||||
// SAR ...
|
||||
copiedSars > 0
|
||||
copiedSars > 0 &&
|
||||
copiedAtrs > 0
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
@@ -756,6 +841,10 @@ bool ValidateInputs()
|
||||
sarStep > 0 &&
|
||||
sarMax > sarStep &&
|
||||
//
|
||||
// ATR ...
|
||||
atrLength > 0 &&
|
||||
atrMultiplier > 0 &&
|
||||
//
|
||||
// XDON ...
|
||||
donchainLength > 0 &&
|
||||
//
|
||||
@@ -798,6 +887,10 @@ int ExtractMaxLengthOfInputs()
|
||||
result = MathMax(result, vwapMidLength);
|
||||
result = MathMax(result, vwapSlowLength);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
result = MathMax(result, atrLength);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -827,6 +920,7 @@ void DefineBuffers()
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE valesDrawType = showVales ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
@@ -844,6 +938,7 @@ void DefineBuffers()
|
||||
|
||||
//
|
||||
// SAR ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE sarDrawType = showSar ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
@@ -859,6 +954,29 @@ void DefineBuffers()
|
||||
PlotIndexSetDouble(sarBufferIndex, PLOT_EMPTY_VALUE, 0);
|
||||
PlotIndexSetInteger(sarBufferIndex, PLOT_ARROW, sarArrowCode);
|
||||
|
||||
//
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
// UPPER ...
|
||||
bool canShowAtrUpper = showAtr && showAtrUpper;
|
||||
ENUM_DRAW_TYPE atrUpperDrawType = canShowAtrUpper ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrUpperBuffer, true);
|
||||
SetIndexBuffer(atrUpperBufferIndex, atrUpperBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrUpperBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_SHOW_DATA, canShowAtrUpper);
|
||||
PlotIndexSetInteger(atrUpperBufferIndex, PLOT_DRAW_TYPE, atrUpperDrawType);
|
||||
|
||||
//
|
||||
// LOWER ...
|
||||
bool canShowAtrLower = showAtr && showAtrLower;
|
||||
ENUM_DRAW_TYPE atrLowerDrawType = canShowAtrLower ? DRAW_LINE : DRAW_NONE;
|
||||
ArraySetAsSeries(atrLowerBuffer, true);
|
||||
SetIndexBuffer(atrLowerBufferIndex, atrLowerBuffer, INDICATOR_DATA);
|
||||
PlotIndexSetDouble(atrLowerBufferIndex, PLOT_EMPTY_VALUE, EMPTY_VALUE);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_SHOW_DATA, canShowAtrLower);
|
||||
PlotIndexSetInteger(atrLowerBufferIndex, PLOT_DRAW_TYPE, atrLowerDrawType);
|
||||
|
||||
//
|
||||
// XVWAP ...
|
||||
|
||||
@@ -1118,15 +1236,19 @@ void DefineBuffers()
|
||||
SetIndexBuffer(vwapSlowStateBufferIndex, vwapSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
// VALID Peaks and Vales ...
|
||||
// ATR ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(validPeaksBuffer, true);
|
||||
SetIndexBuffer(validPeaksBufferIndex, validPeaksBuffer, INDICATOR_CALCULATIONS);
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
SetIndexBuffer(atrBufferIndex, atrBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(validValesBuffer, true);
|
||||
SetIndexBuffer(validValesBufferIndex, validValesBuffer, INDICATOR_CALCULATIONS);
|
||||
ArraySetAsSeries(atrUpperRawBuffer, true);
|
||||
SetIndexBuffer(atrUpperRawBufferIndex, atrUpperRawBuffer, INDICATOR_CALCULATIONS);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(atrLowerRawBuffer, true);
|
||||
SetIndexBuffer(atrLowerRawBufferIndex, atrLowerRawBuffer, INDICATOR_CALCULATIONS);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1192,14 +1314,15 @@ void CalculateBuffers(
|
||||
);
|
||||
|
||||
//
|
||||
// if (bar_index <= barsLimit + 576)
|
||||
// {
|
||||
// //
|
||||
// CalculateValidPeaksAndVales(
|
||||
// bar_index,
|
||||
// prevCalculated //
|
||||
// );
|
||||
// }
|
||||
CalculateAtrZones(
|
||||
bar_index,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low //
|
||||
);
|
||||
|
||||
//
|
||||
CalculateFibonacci(
|
||||
@@ -1416,6 +1539,14 @@ void FillBuffersZero(int barIndex)
|
||||
// SARS ...
|
||||
sarBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
// ATRS ...
|
||||
atrBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrUpperRawBuffer[barIndex] = 0;
|
||||
atrUpperBuffer[barIndex] = 0;
|
||||
atrLowerRawBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
// VWAP ...
|
||||
|
||||
@@ -1434,10 +1565,6 @@ void FillBuffersZero(int barIndex)
|
||||
vwapMidStateBuffer[barIndex] = hideColorIDX;
|
||||
vwapSlowStateBuffer[barIndex] = hideColorIDX;
|
||||
|
||||
//
|
||||
validPeaksBuffer[barIndex] = 0;
|
||||
validValesBuffer[barIndex] = 0;
|
||||
|
||||
//
|
||||
donOpenUpperBuffer[barIndex] = 0;
|
||||
donOpenLowerBuffer[barIndex] = 0;
|
||||
@@ -1989,147 +2116,100 @@ void CalculateDonchains(
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate Valid Vales and Peaks ...
|
||||
* Calculate Different VWaps ...
|
||||
*
|
||||
* @param bar_index: Integer, current Bar Index ...
|
||||
* @param bar_index: Integer, Represent Current Bar ...
|
||||
* @param prevCalculated: Integer, Represent Previous Calculated Bars ...
|
||||
* @param ratesTotal: Integer, Represents All Available Bars ...
|
||||
* @param open: Double Array, History of Open Prices ...
|
||||
* @param high: Double Array, History of High Prices ...
|
||||
* @param close: Double Array, History of Close Prices ...
|
||||
* @param low: Double Array, History of Low Prices ...
|
||||
*/
|
||||
void CalculateValidPeaksAndVales(
|
||||
int bar_index,
|
||||
int prevCalculated //
|
||||
void CalculateAtrZones(
|
||||
int bar_index, // Selected Bar Index
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int minRepetition = donchainLength;
|
||||
int maxAllowedLoopbackBars = 576;
|
||||
// Select ATr Value ...
|
||||
double atrValue = atrBuffer[bar_index];
|
||||
double appliedAtrMultiplierValue = atrValue * atrMultiplier;
|
||||
|
||||
//
|
||||
int barIndex = bar_index;
|
||||
int start = barIndex;
|
||||
int end = start + maxAllowedLoopbackBars;
|
||||
// Select Upper Price ...
|
||||
double upperPrice = GetAppliedPrice(
|
||||
atrUpperAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double peak = 0;
|
||||
int peakRepeate = 0;
|
||||
int peakToBarIndex = 0;
|
||||
int peakFromBarIndex = 0;
|
||||
// Select Lower Price ...
|
||||
double lowerPrice = GetAppliedPrice(
|
||||
atrLowerAppliedTo,
|
||||
open,
|
||||
high,
|
||||
low,
|
||||
close,
|
||||
bar_index //
|
||||
);
|
||||
|
||||
//
|
||||
double vale = 0;
|
||||
int valeRepeate = 0;
|
||||
int valeToBarIndex = 0;
|
||||
int valeFromBarIndex = 0;
|
||||
// Calculate Raw Atrs ...
|
||||
|
||||
//
|
||||
bool canLookupPeak = true;
|
||||
bool canLookupVale = true;
|
||||
bool canLookup = true;
|
||||
// Upper ...
|
||||
double atrUpperRawValue = upperPrice + appliedAtrMultiplierValue;
|
||||
atrUpperRawBuffer[bar_index] = atrUpperRawValue;
|
||||
|
||||
//
|
||||
while (canLookup)
|
||||
// Lower ...
|
||||
double atrLowerRawValue = lowerPrice - appliedAtrMultiplierValue;
|
||||
atrLowerRawBuffer[bar_index] = atrLowerRawValue;
|
||||
|
||||
//
|
||||
bool canSmooth = atrSmoothingMode != X_MA_MODE_NONE;
|
||||
if (canSmooth)
|
||||
{
|
||||
//
|
||||
// Check Peak ...
|
||||
if (canLookupPeak)
|
||||
{
|
||||
//
|
||||
double iPeak = peaksBuffer[barIndex];
|
||||
if (iPeak != peak)
|
||||
{
|
||||
//
|
||||
if (peak != 0 &&
|
||||
peakRepeate >= minRepetition)
|
||||
{
|
||||
//
|
||||
canLookupPeak = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
peak = iPeak;
|
||||
peakRepeate = 0;
|
||||
peakFromBarIndex = 0;
|
||||
peakToBarIndex = barIndex;
|
||||
}
|
||||
}
|
||||
else if (iPeak == peak)
|
||||
{
|
||||
//
|
||||
peakRepeate++;
|
||||
peakFromBarIndex = barIndex;
|
||||
}
|
||||
}
|
||||
// Upper ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrUpperRawBuffer,
|
||||
atrUpperBuffer,
|
||||
atrSmoothingMode //
|
||||
);
|
||||
|
||||
//
|
||||
// Check Vale ...
|
||||
if (canLookupVale)
|
||||
{
|
||||
//
|
||||
double iVale = valesBuffer[barIndex];
|
||||
if (iVale != vale)
|
||||
{
|
||||
//
|
||||
if (vale != 0 &&
|
||||
valeRepeate >= minRepetition)
|
||||
{
|
||||
canLookupVale = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
vale = iVale;
|
||||
valeRepeate = 0;
|
||||
valeFromBarIndex = 0;
|
||||
valeToBarIndex = barIndex;
|
||||
}
|
||||
}
|
||||
else if (iVale == vale)
|
||||
{
|
||||
//
|
||||
valeRepeate++;
|
||||
valeFromBarIndex = barIndex;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
canLookup = barIndex < end &&
|
||||
(canLookupPeak ||
|
||||
canLookupVale);
|
||||
if (canLookup)
|
||||
{
|
||||
barIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (!canLookupPeak)
|
||||
{
|
||||
validPeaksBuffer[bar_index] = peak;
|
||||
// Lower ...
|
||||
iMAOnBuffer(
|
||||
ratesTotal,
|
||||
prevCalculated,
|
||||
bar_index,
|
||||
atrLength,
|
||||
atrLowerRawBuffer,
|
||||
atrLowerBuffer,
|
||||
atrSmoothingMode //
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double lastValidPeak = prevCalculated == 0
|
||||
? 0
|
||||
: validPeaksBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
validPeaksBuffer[bar_index] = lastValidPeak;
|
||||
}
|
||||
|
||||
//
|
||||
if (!canLookupVale)
|
||||
{
|
||||
validValesBuffer[bar_index] = vale;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
double lastValidVale = prevCalculated == 0
|
||||
? 0
|
||||
: validValesBuffer[bar_index + 1];
|
||||
|
||||
//
|
||||
validValesBuffer[bar_index] = lastValidVale;
|
||||
// Use Raw Values ...
|
||||
atrUpperBuffer[bar_index] = atrUpperRawValue;
|
||||
atrLowerBuffer[bar_index] = atrLowerRawValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user