some cleanups, refactor unnecessary requirements, implement rejected checkers and also counters ...
ass support for PV and KISuperSlow and MASuper Slow in KI Indicator and also Helper and implement them in BackTester ...
This commit is contained in:
@@ -35,8 +35,10 @@
|
||||
input group "Calculation";
|
||||
input int kiFastLength = 26; // KI Fast Length
|
||||
input int kiSlowLength = 104; // KI Slow Length
|
||||
input int maFastLength = 9; // MA Fast Length
|
||||
input int maSlowLength = 26; // MA Slow Length
|
||||
input int kiSuperSlowLength = 208; // KI Super Slow Length
|
||||
input int maFastLength = 26; // MA Fast Length
|
||||
input int maSlowLength = 104; // MA Slow Length
|
||||
input int maSuperSlowLength = 208; // MA Super Slow Length
|
||||
input ENUM_MA_METHOD maMethod = MODE_EMA; // MA Mode
|
||||
input ENUM_APPLIED_PRICE maAppliedTo = PRICE_CLOSE; // MA Applied To
|
||||
input int rsiLength = 14; // RSI Length
|
||||
@@ -54,16 +56,23 @@ input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // ATR Lower Price T
|
||||
//
|
||||
// Presentation ...
|
||||
input group "Presentation";
|
||||
input bool showKIFast = true; // Show KI Fast
|
||||
input bool showKISlow = true; // Show KI Slow
|
||||
input bool showMaFast = true; // Show Ma Fast
|
||||
input bool showMaSlow = true; // Show MA Slow
|
||||
input bool showKIWave = true; // Show KI Wave
|
||||
input bool showKIUpper = true; // Show KI Upper
|
||||
input bool showKILower = true; // Show KI Lower
|
||||
input bool showPV = true; // Show PV
|
||||
input bool showKIFast = true; // Show KI Fast
|
||||
input bool showKISlow = true; // Show KI Slow
|
||||
input bool showKISuperSlow = true; // Show KI Super Slow
|
||||
input bool showMaFast = true; // Show Ma Fast
|
||||
input bool showMaSlow = true; // Show MA Slow
|
||||
input bool showMaSuperSlow = true; // Show MA Super Slow
|
||||
input bool showKIWave = true; // Show KI Wave
|
||||
input bool showKIUpper = true; // Show KI Upper
|
||||
input bool showKILower = true; // Show KI Lower
|
||||
|
||||
//
|
||||
input int startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||
|
||||
//
|
||||
input int peakArrowCode = 159; // Peaks Arrow Code
|
||||
input int valeArrowCode = 159; // Vales Arrow Code
|
||||
// #endregion
|
||||
|
||||
// #region Non Inputs ...
|
||||
@@ -87,8 +96,8 @@ input int startCalculationForLastBars = 1500; // Calculate Last n Bars
|
||||
#property indicator_chart_window
|
||||
|
||||
//
|
||||
#property indicator_buffers 19
|
||||
#property indicator_plots 7
|
||||
#property indicator_buffers 25
|
||||
#property indicator_plots 11
|
||||
|
||||
// #region Plot Buffers ...
|
||||
// #region KI ...
|
||||
@@ -200,10 +209,72 @@ double kiSlowColorBuffer[];
|
||||
#property indicator_style7 STYLE_SOLID
|
||||
#property indicator_width7 2
|
||||
// #endregion
|
||||
|
||||
// #region KI Super Slow ...
|
||||
//
|
||||
#define kiSuperSlowBufferIndex 10
|
||||
#define kiSuperSlowBufferPlotIndex 7
|
||||
double kiSuperSlowBuffer[];
|
||||
|
||||
//
|
||||
#define kiSuperSlowColorBufferIndex 11
|
||||
double kiSuperSlowColorBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label8 "KI Super Slow"
|
||||
#property indicator_type8 DRAW_COLOR_LINE
|
||||
#property indicator_color8 CLR_NONE, clrAqua, clrMagenta, clrGray
|
||||
#property indicator_style8 STYLE_SOLID
|
||||
#property indicator_width8 2
|
||||
// #endregion
|
||||
|
||||
// #region MA Super Slow ...
|
||||
//
|
||||
#define maSuperSlowBufferIndex 12
|
||||
#define maSuperSlowBufferPlotIndex 8
|
||||
double maSuperSlowBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label9 "MA Super Slow"
|
||||
#property indicator_type9 DRAW_LINE
|
||||
#property indicator_color9 clrMagenta
|
||||
#property indicator_style9 STYLE_DOT
|
||||
#property indicator_width9 1
|
||||
// #endregion
|
||||
|
||||
// #region PV ...
|
||||
//
|
||||
// PEAKS ...
|
||||
|
||||
//
|
||||
#define peakBufferIndex 13
|
||||
#define peakBufferPlotIndex 9
|
||||
double peakBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label10 "PEAK"
|
||||
#property indicator_type10 DRAW_ARROW
|
||||
#property indicator_color10 clrMagenta
|
||||
#property indicator_width10 3
|
||||
|
||||
//
|
||||
// VALES ...
|
||||
|
||||
//
|
||||
#define valeBufferIndex 14
|
||||
#define valeBufferPlotIndex 10
|
||||
double valeBuffer[];
|
||||
|
||||
//
|
||||
#property indicator_label11 "VALE"
|
||||
#property indicator_type11 DRAW_ARROW
|
||||
#property indicator_color11 clrAqua
|
||||
#property indicator_width11 3
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
//
|
||||
#define mLastBufferIndex 9
|
||||
#define mLastBufferIndex 14
|
||||
|
||||
// #region Data Buffers ...
|
||||
//
|
||||
@@ -241,6 +312,10 @@ double kiSlowStateBuffer[];
|
||||
//
|
||||
#define atrSmoothedBufferIndex mLastBufferIndex + 9
|
||||
double atrSmoothedBuffer[];
|
||||
|
||||
//
|
||||
#define kiSuperSlowStateBufferIndex mLastBufferIndex + 10
|
||||
double kiSuperSlowStateBuffer[];
|
||||
// #endregion
|
||||
// #endregion
|
||||
|
||||
@@ -260,6 +335,7 @@ int atrHandler = INVALID_HANDLE;
|
||||
int rsiHandler = INVALID_HANDLE;
|
||||
int maFastHandler = INVALID_HANDLE;
|
||||
int maSlowHandler = INVALID_HANDLE;
|
||||
int maSuperSlowHandler = INVALID_HANDLE;
|
||||
// #endregion
|
||||
|
||||
// #region Event Handlers ...
|
||||
@@ -353,12 +429,20 @@ void OnDeinit(const int reason)
|
||||
{
|
||||
IndicatorRelease(maFastHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// MA Slow ...
|
||||
if (maSlowHandler != INVALID_HANDLE)
|
||||
{
|
||||
IndicatorRelease(maSlowHandler);
|
||||
}
|
||||
|
||||
//
|
||||
// MA Super Slow ...
|
||||
if (maSuperSlowHandler != INVALID_HANDLE)
|
||||
{
|
||||
IndicatorRelease(maSuperSlowHandler);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -416,6 +500,7 @@ int OnCalculate(
|
||||
// MA ...
|
||||
int maFastCalculatedBars = BarsCalculated(maFastHandler);
|
||||
int maSlowCalculatedBars = BarsCalculated(maSlowHandler);
|
||||
int maSuperSlowCalculatedBars = BarsCalculated(maSuperSlowHandler);
|
||||
|
||||
//
|
||||
bool isPassedRequiredCalculatedBars =
|
||||
@@ -428,7 +513,8 @@ int OnCalculate(
|
||||
//
|
||||
// MA ...
|
||||
maFastCalculatedBars >= maxLength &&
|
||||
maSlowCalculatedBars >= maxLength
|
||||
maSlowCalculatedBars >= maxLength &&
|
||||
maSuperSlowCalculatedBars >= maxLength
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCalculatedBars)
|
||||
@@ -456,6 +542,7 @@ int OnCalculate(
|
||||
// MA ...
|
||||
int copiedMAFasts = CopyBuffer(maFastHandler, MAIN_LINE, 0, limit, maFastBuffer);
|
||||
int copiedMASlows = CopyBuffer(maSlowHandler, MAIN_LINE, 0, limit, maSlowBuffer);
|
||||
int copiedMASuperSlows = CopyBuffer(maSuperSlowHandler, MAIN_LINE, 0, limit, maSuperSlowBuffer);
|
||||
|
||||
//
|
||||
// Validate Copied Items ...
|
||||
@@ -469,7 +556,8 @@ int OnCalculate(
|
||||
//
|
||||
// MA ...
|
||||
copiedMAFasts >= limit &&
|
||||
copiedMASlows >= limit
|
||||
copiedMASlows >= limit &&
|
||||
copiedMASuperSlows >= limit
|
||||
//
|
||||
;
|
||||
if (!isPassedRequiredCopiedItems)
|
||||
@@ -527,6 +615,12 @@ bool ValidateInputs()
|
||||
// KI ...
|
||||
kiFastLength >= 5 &&
|
||||
kiSlowLength > kiFastLength &&
|
||||
kiSuperSlowLength > kiSlowLength &&
|
||||
//
|
||||
// MA ...
|
||||
maFastLength >= 2 &&
|
||||
maSlowLength > maFastLength &&
|
||||
maSuperSlowLength > maSlowLength &&
|
||||
//
|
||||
// ATR ...
|
||||
atrLength >= 5 &&
|
||||
@@ -552,8 +646,12 @@ int ExtractMaxLengthOfInputs()
|
||||
|
||||
//
|
||||
result = MathMax(kiFastLength, atrLength);
|
||||
result = MathMax(result, kiSlowLength);
|
||||
result = MathMax(result, rsiLength);
|
||||
result = MathMax(result, kiSlowLength);
|
||||
result = MathMax(result, maFastLength);
|
||||
result = MathMax(result, maSlowLength);
|
||||
result = MathMax(result, maSuperSlowLength);
|
||||
result = MathMax(result, kiSuperSlowLength);
|
||||
|
||||
//
|
||||
if (atrSmoothingLength > 0)
|
||||
@@ -610,6 +708,24 @@ void DefineBuffers()
|
||||
SetIndexBuffer(kiSlowStateBufferIndex, kiSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
// #endregion
|
||||
|
||||
// #region KI Super Slow ...
|
||||
//
|
||||
ArraySetAsSeries(kiSuperSlowBuffer, true);
|
||||
SetIndexBuffer(kiSuperSlowBufferIndex, kiSuperSlowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(kiSuperSlowBufferPlotIndex, PLOT_SHOW_DATA, showKISuperSlow);
|
||||
PlotIndexSetDouble(kiSuperSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kiSuperSlowColorBuffer, true);
|
||||
SetIndexBuffer(kiSuperSlowColorBufferIndex, kiSuperSlowColorBuffer, INDICATOR_COLOR_INDEX);
|
||||
|
||||
//
|
||||
ArraySetAsSeries(kiSuperSlowStateBuffer, true);
|
||||
SetIndexBuffer(kiSuperSlowStateBufferIndex, kiSuperSlowStateBuffer, INDICATOR_CALCULATIONS);
|
||||
// #endregion
|
||||
|
||||
// #region KI Upper ...
|
||||
//
|
||||
ENUM_DRAW_TYPE kiUpperDrawType = showKIUpper ? DRAW_LINE : DRAW_NONE;
|
||||
@@ -666,6 +782,44 @@ void DefineBuffers()
|
||||
SetIndexBuffer(kiWaveStateBufferIndex, kiWaveStateBuffer, INDICATOR_CALCULATIONS);
|
||||
// #endregion
|
||||
|
||||
// #region PV ...
|
||||
//
|
||||
// PEAK / VALE ...
|
||||
|
||||
//
|
||||
ENUM_DRAW_TYPE pvDrawType = showPV ? DRAW_ARROW : DRAW_NONE;
|
||||
|
||||
//
|
||||
// PEAK ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(peakBuffer, true);
|
||||
SetIndexBuffer(peakBufferIndex, peakBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(peakBufferPlotIndex, PLOT_SHOW_DATA, showPV);
|
||||
PlotIndexSetInteger(peakBufferPlotIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(peakBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(peakBufferPlotIndex, PLOT_ARROW, peakArrowCode);
|
||||
|
||||
//
|
||||
// VALE ...
|
||||
|
||||
//
|
||||
ArraySetAsSeries(valeBuffer, true);
|
||||
SetIndexBuffer(valeBufferIndex, valeBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(valeBufferPlotIndex, PLOT_SHOW_DATA, showPV);
|
||||
PlotIndexSetInteger(valeBufferPlotIndex, PLOT_DRAW_TYPE, pvDrawType);
|
||||
|
||||
//
|
||||
PlotIndexSetDouble(valeBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
PlotIndexSetInteger(valeBufferPlotIndex, PLOT_ARROW, valeArrowCode);
|
||||
// #endregion
|
||||
|
||||
// #region ATR ...
|
||||
//
|
||||
ArraySetAsSeries(atrBuffer, true);
|
||||
@@ -714,6 +868,21 @@ void DefineBuffers()
|
||||
PlotIndexSetInteger(maSlowBufferPlotIndex, PLOT_DRAW_TYPE, maSlowDrawType);
|
||||
PlotIndexSetDouble(maSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
// #endregion
|
||||
|
||||
// #region Super Slow ...
|
||||
//
|
||||
ENUM_DRAW_TYPE maSuperSlowDrawType = showMaSuperSlow ? DRAW_LINE : DRAW_NONE;
|
||||
|
||||
//
|
||||
// Slow ...
|
||||
ArraySetAsSeries(maSuperSlowBuffer, true);
|
||||
SetIndexBuffer(maSuperSlowBufferIndex, maSuperSlowBuffer, INDICATOR_DATA);
|
||||
|
||||
//
|
||||
PlotIndexSetInteger(maSuperSlowBufferPlotIndex, PLOT_SHOW_DATA, showMaSuperSlow);
|
||||
PlotIndexSetInteger(maSuperSlowBufferPlotIndex, PLOT_DRAW_TYPE, maSuperSlowDrawType);
|
||||
PlotIndexSetDouble(maSuperSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
|
||||
// #endregion
|
||||
// #endregion
|
||||
}
|
||||
|
||||
@@ -773,6 +942,7 @@ bool InitRequirements()
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// MA Slow ...
|
||||
maSlowHandler = iMA(
|
||||
@@ -789,6 +959,22 @@ bool InitRequirements()
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// MA Super Slow ...
|
||||
maSuperSlowHandler = iMA(
|
||||
_Symbol,
|
||||
_Period,
|
||||
maSuperSlowLength,
|
||||
0,
|
||||
maMethod,
|
||||
maAppliedTo //
|
||||
);
|
||||
result = maSuperSlowHandler != INVALID_HANDLE;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
@@ -904,6 +1090,19 @@ void CalculateValues(
|
||||
//
|
||||
// Common Requirements ...
|
||||
|
||||
// #region PV ...
|
||||
CalculatePV(
|
||||
barIndex,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
// #endregion
|
||||
|
||||
// #region KI ...
|
||||
CalculateKI(
|
||||
barIndex,
|
||||
@@ -930,6 +1129,19 @@ void CalculateValues(
|
||||
);
|
||||
// #endregion
|
||||
|
||||
// #region KI Super Slow ...
|
||||
CalculateKISuperSlow(
|
||||
barIndex,
|
||||
prevCalculated,
|
||||
ratesTotal,
|
||||
open,
|
||||
high,
|
||||
close,
|
||||
low,
|
||||
tickVolume //
|
||||
);
|
||||
// #endregion
|
||||
|
||||
// #region ATR (Ki Upper/Lower) ...
|
||||
CalculateATR(
|
||||
barIndex,
|
||||
@@ -1147,6 +1359,185 @@ void CalculateKISlow(
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate KI Super Slow Bufer ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param prevCalculated: int, Provides Previous Calculated Bars ...
|
||||
* @param ratesTotal: int, Provides All Availabled Bars ...
|
||||
* @param open: double Collection, Provides Open Prices Time Series ...
|
||||
* @param high: double Collection, Provides High Prices Time Series ...
|
||||
* @param close: double Collection, Provides Close Prices Time Series ...
|
||||
* @param low: double Collection, Provides Low Prices Time Series ...
|
||||
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
|
||||
*/
|
||||
void CalculateKISuperSlow(
|
||||
int barIndex,
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int lastBarIndex = barIndex + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? barIndex == startCalculationForLastBars
|
||||
: barIndex == firstBarIndex;
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
bool isInited = iBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
double iClose = close[barIndex];
|
||||
|
||||
//
|
||||
// Calculate KI / Color ...
|
||||
double lastKI =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: kiSuperSlowBuffer[lastBarIndex];
|
||||
double iKI = lastKI;
|
||||
if (isInited)
|
||||
{
|
||||
//
|
||||
double iLLKI = iBar.FindLowest(kiSuperSlowLength, MODE_LOW);
|
||||
double iHHKI = iBar.FindHighest(kiSuperSlowLength, MODE_HIGH);
|
||||
|
||||
//
|
||||
iKI = (iHHKI + iLLKI) / 2;
|
||||
if (iLLKI == 0 || iHHKI == 0)
|
||||
{
|
||||
iKI = lastKI;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
iKI = lastKI;
|
||||
}
|
||||
kiSuperSlowBuffer[barIndex] = iKI;
|
||||
|
||||
//
|
||||
double iKIState = neuturalState;
|
||||
double iKIColor = neuturalColorIDX;
|
||||
if (iClose > iKI)
|
||||
{
|
||||
//
|
||||
iKIState = bullishState;
|
||||
iKIColor =
|
||||
!showKISuperSlow
|
||||
? hideColorIDX
|
||||
: bullishColorIDX;
|
||||
}
|
||||
else if (iClose < iKI)
|
||||
{
|
||||
//
|
||||
iKIState = bearishState;
|
||||
iKIColor =
|
||||
!showKISuperSlow
|
||||
? hideColorIDX
|
||||
: bearishColorIDX;
|
||||
}
|
||||
kiSuperSlowStateBuffer[barIndex] = iKIState;
|
||||
kiSuperSlowColorBuffer[barIndex] = iKIColor;
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate PV Bufer ...
|
||||
*
|
||||
* @param barIndex: int, Specified Bar Index ...
|
||||
* @param prevCalculated: int, Provides Previous Calculated Bars ...
|
||||
* @param ratesTotal: int, Provides All Availabled Bars ...
|
||||
* @param open: double Collection, Provides Open Prices Time Series ...
|
||||
* @param high: double Collection, Provides High Prices Time Series ...
|
||||
* @param close: double Collection, Provides Close Prices Time Series ...
|
||||
* @param low: double Collection, Provides Low Prices Time Series ...
|
||||
* @param tickVolume: long Collection, Provides Ticks Volume Prices Time Series ...
|
||||
*/
|
||||
void CalculatePV(
|
||||
int barIndex,
|
||||
const int prevCalculated,
|
||||
const int ratesTotal,
|
||||
const double &open[],
|
||||
const double &high[],
|
||||
const double &close[],
|
||||
const double &low[],
|
||||
const long &tickVolume[] //
|
||||
)
|
||||
{
|
||||
//
|
||||
int lastBarIndex = barIndex + 1;
|
||||
bool isFirstBar =
|
||||
startCalculationForLastBars > 0
|
||||
? barIndex == startCalculationForLastBars
|
||||
: barIndex == firstBarIndex;
|
||||
|
||||
//
|
||||
XOHCL iBar;
|
||||
bool isInited = iBar.Init(
|
||||
_Symbol,
|
||||
_Period,
|
||||
barIndex //
|
||||
);
|
||||
|
||||
//
|
||||
// Calculate Peak ...
|
||||
double lastPeak =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: peakBuffer[lastBarIndex];
|
||||
double lastVale =
|
||||
isFirstBar
|
||||
? emptyValue
|
||||
: valeBuffer[lastBarIndex];
|
||||
double iPeak = lastPeak;
|
||||
double iVale = lastVale;
|
||||
if (isInited)
|
||||
{
|
||||
//
|
||||
int length = maxLength;
|
||||
|
||||
//
|
||||
double iLL = iBar.FindLowest(length, MODE_LOW);
|
||||
double iHH = iBar.FindHighest(length, MODE_HIGH);
|
||||
|
||||
//
|
||||
double iLL2 = iBar.FindLowest(length / 2, MODE_LOW);
|
||||
double iHH2 = iBar.FindHighest(length / 2, MODE_HIGH);
|
||||
|
||||
//
|
||||
iPeak = iHH == iHH2 ? iHH : lastPeak;
|
||||
iVale = iLL == iLL2 ? iLL : lastVale;
|
||||
|
||||
//
|
||||
lastPeak = iPeak;
|
||||
lastVale = iVale;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
iPeak = lastPeak;
|
||||
iVale = lastVale;
|
||||
}
|
||||
peakBuffer[barIndex] = iPeak;
|
||||
valeBuffer[barIndex] = iVale;
|
||||
|
||||
//
|
||||
iBar.Clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate ATR and Ki Upper/Lower Buffers ...
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user