last works on xki ...

This commit is contained in:
2025-12-30 21:38:58 +03:30
parent 5850164aab
commit b1731af03c
8 changed files with 6662 additions and 66 deletions
+170 -18
View File
@@ -33,7 +33,8 @@
// #region Inputs ...
//
input group "Calculation";
input int kiLength = 26; // KI Length
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 ENUM_MA_METHOD maMethod = MODE_EMA; // MA Mode
@@ -53,7 +54,8 @@ input ENUM_X_PRICE atrLowerPriceType = X_PRICE_LOW; // ATR Lower Price T
//
// Presentation ...
input group "Presentation";
input bool showKI = true; // Show KI
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
@@ -85,8 +87,8 @@ input int startCalculationForLastBars = 1500; // Calculate Last n Bars
#property indicator_chart_window
//
#property indicator_buffers 15
#property indicator_plots 6
#property indicator_buffers 18
#property indicator_plots 7
// #region Plot Buffers ...
// #region KI ...
@@ -100,7 +102,7 @@ double kiBuffer[];
double kiColorBuffer[];
//
#property indicator_label1 "KI"
#property indicator_label1 "KI Fast"
#property indicator_type1 DRAW_COLOR_LINE
#property indicator_color1 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style1 STYLE_SOLID
@@ -110,7 +112,7 @@ double kiColorBuffer[];
// #region KI Wave ...
//
#define kiWaveBufferIndex 2
#define kiWaveBufferPlotIndex 2
#define kiWaveBufferPlotIndex 1
double kiWaveBuffer[];
//
@@ -128,7 +130,7 @@ double kiWaveColorBuffer[];
// #region KI Upper ...
//
#define kiUpperBufferIndex 4
#define kiUpperBufferPlotIndex 4
#define kiUpperBufferPlotIndex 2
double kiUpperBuffer[];
//
@@ -142,7 +144,7 @@ double kiUpperBuffer[];
// #region KI Lower ...
//
#define kiLowerBufferIndex 5
#define kiLowerBufferPlotIndex 5
#define kiLowerBufferPlotIndex 3
double kiLowerBuffer[];
//
@@ -156,7 +158,7 @@ double kiLowerBuffer[];
// #region MA Fast ...
//
#define maFastBufferIndex 6
#define maFastBufferPlotIndex 6
#define maFastBufferPlotIndex 4
double maFastBuffer[];
//
@@ -170,7 +172,7 @@ double maFastBuffer[];
// #region MA Slow ...
//
#define maSlowBufferIndex 7
#define maSlowBufferPlotIndex 7
#define maSlowBufferPlotIndex 5
double maSlowBuffer[];
//
@@ -180,10 +182,28 @@ double maSlowBuffer[];
#property indicator_style6 STYLE_DOT
#property indicator_width6 1
// #endregion
// #region KI Slow ...
//
#define kiSlowBufferIndex 8
#define kiSlowBufferPlotIndex 6
double kiSlowBuffer[];
//
#define kiSlowColorBufferIndex 9
double kiSlowColorBuffer[];
//
#property indicator_label7 "KI Slow"
#property indicator_type7 DRAW_COLOR_LINE
#property indicator_color7 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style7 STYLE_SOLID
#property indicator_width7 2
// #endregion
// #endregion
//
#define mLastBufferIndex 7
#define mLastBufferIndex 9
// #region Data Buffers ...
//
@@ -213,6 +233,10 @@ double kiWaveRawBuffer[];
//
#define kiWaveStateBufferIndex mLastBufferIndex + 7
double kiWaveStateBuffer[];
//
#define kiSlowStateBufferIndex mLastBufferIndex + 8
double kiSlowStateBuffer[];
// #endregion
// #endregion
@@ -497,7 +521,8 @@ bool ValidateInputs()
result =
//
// KI ...
kiLength >= 5 &&
kiFastLength >= 5 &&
kiSlowLength > kiFastLength &&
//
// ATR ...
atrLength >= 5 &&
@@ -522,7 +547,8 @@ int ExtractMaxLengthOfInputs()
int result = 0;
//
result = MathMax(kiLength, atrLength);
result = MathMax(kiFastLength, atrLength);
result = MathMax(result, kiSlowLength);
result = MathMax(result, rsiLength);
//
@@ -550,7 +576,7 @@ void DefineBuffers()
SetIndexBuffer(kiBufferIndex, kiBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKI);
PlotIndexSetInteger(kiBufferPlotIndex, PLOT_SHOW_DATA, showKIFast);
PlotIndexSetDouble(kiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
@@ -562,6 +588,24 @@ void DefineBuffers()
SetIndexBuffer(kiStateBufferIndex, kiStateBuffer, INDICATOR_CALCULATIONS);
// #endregion
// #region KI Slow ...
//
ArraySetAsSeries(kiSlowBuffer, true);
SetIndexBuffer(kiSlowBufferIndex, kiSlowBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(kiSlowBufferPlotIndex, PLOT_SHOW_DATA, showKISlow);
PlotIndexSetDouble(kiSlowBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
ArraySetAsSeries(kiSlowColorBuffer, true);
SetIndexBuffer(kiSlowColorBufferIndex, kiSlowColorBuffer, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(kiSlowStateBuffer, true);
SetIndexBuffer(kiSlowStateBufferIndex, kiSlowStateBuffer, INDICATOR_CALCULATIONS);
// #endregion
// #region KI Upper ...
//
ENUM_DRAW_TYPE kiUpperDrawType = showKIUpper ? DRAW_LINE : DRAW_NONE;
@@ -865,6 +909,19 @@ void CalculateValues(
);
// #endregion
// #region KI Slow ...
CalculateKISlow(
barIndex,
prevCalculated,
ratesTotal,
open,
high,
close,
low,
tickVolume //
);
// #endregion
// #region ATR (Ki Upper/Lower) ...
CalculateATR(
barIndex,
@@ -943,8 +1000,8 @@ void CalculateKI(
if (isInited)
{
//
double iLLKI = iBar.FindLowest(kiLength, MODE_LOW);
double iHHKI = iBar.FindHighest(kiLength, MODE_HIGH);
double iLLKI = iBar.FindLowest(kiFastLength, MODE_LOW);
double iHHKI = iBar.FindHighest(kiFastLength, MODE_HIGH);
//
iKI = (iHHKI + iLLKI) / 2;
@@ -967,7 +1024,7 @@ void CalculateKI(
//
iKIState = bullishState;
iKIColor =
!showKI
!showKIFast
? hideColorIDX
: bullishColorIDX;
}
@@ -976,7 +1033,7 @@ void CalculateKI(
//
iKIState = bearishState;
iKIColor =
!showKI
!showKIFast
? hideColorIDX
: bearishColorIDX;
}
@@ -987,6 +1044,101 @@ void CalculateKI(
iBar.Clean();
}
/**
* Calculate KI 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 CalculateKISlow(
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
: kiSlowBuffer[lastBarIndex];
double iKI = lastKI;
if (isInited)
{
//
double iLLKI = iBar.FindLowest(kiSlowLength, MODE_LOW);
double iHHKI = iBar.FindHighest(kiSlowLength, MODE_HIGH);
//
iKI = (iHHKI + iLLKI) / 2;
if (iLLKI == 0 || iHHKI == 0)
{
iKI = lastKI;
}
}
else
{
iKI = lastKI;
}
kiSlowBuffer[barIndex] = iKI;
//
double iKIState = neuturalState;
double iKIColor = neuturalColorIDX;
if (iClose > iKI)
{
//
iKIState = bullishState;
iKIColor =
!showKISlow
? hideColorIDX
: bullishColorIDX;
}
else if (iClose < iKI)
{
//
iKIState = bearishState;
iKIColor =
!showKISlow
? hideColorIDX
: bearishColorIDX;
}
kiSlowStateBuffer[barIndex] = iKIState;
kiSlowColorBuffer[barIndex] = iKIColor;
//
iBar.Clean();
}
/**
* Calculate ATR and Ki Upper/Lower Buffers ...
*