This commit is contained in:
2025-04-17 01:46:46 +03:30
parent d912210e68
commit c6e3c78e06
9 changed files with 3038 additions and 37 deletions
+165 -28
View File
@@ -82,7 +82,7 @@ input int swingLength = 5; // Length
//
input group "Support and Resistance";
input int supResSmoothingLength = 7; // Smoothing Length
input int supResSmoothingLength = 7; // Smoothing Length
input ENUM_X_MA_METHOD supResSmoothingMode = X_MA_MODE_SMA; // Smoothing Method
//
@@ -95,6 +95,7 @@ input int startCalculationForLastBars = 1000; // Calculate Last n Bars
//
input bool showSar = true; // Show Sar
input bool showKI = true; // Show KI
input bool showTKI = true; // Show KI Trend
input bool showTrend = true; // Show Trend
input bool showSwings = true; // Show Swings
input bool showFiboLevel1 = true; // Show Fibo Level 1
@@ -124,6 +125,11 @@ input int swingHighArrowCode = 226; // Swing High Arrow Code
#define bearishColorIDX 2
#define neuturalColorIDX 3
//
#define bullishState 1
#define neuturalState 0
#define bearishState -1
//
#define emptyValue 0.0
@@ -131,8 +137,8 @@ input int swingHighArrowCode = 226; // Swing High Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 28
#property indicator_plots 22
#property indicator_buffers 31
#property indicator_plots 23
//
// Plot Buffers ...
@@ -440,10 +446,29 @@ double swingHighBuffer[];
#property indicator_color22 clrRed
#property indicator_width22 1
//
// TKI ...
//
#define tkiBufferIndex 24
#define tkiBufferPlotIndex 22
double tkiBuffer[];
//
#define tkiColorBufferIndex 25
double tkiColorBuffer[];
//
#property indicator_label23 "TKI"
#property indicator_type23 DRAW_COLOR_LINE
#property indicator_color23 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style23 STYLE_DASHDOTDOT
#property indicator_width23 2
//
// Data Buffers ...
#define mLastBufferIndex 23
#define mLastBufferIndex 25
//
#define trendStateBufferIndex mLastBufferIndex + 1
@@ -461,6 +486,10 @@ double supBuffer[];
#define resBufferIndex mLastBufferIndex + 4
double resBuffer[];
//
#define tkiStateBufferIndex mLastBufferIndex + 5
double tkiStateBuffer[];
//
// Variables, Properties and etc ...
@@ -477,6 +506,7 @@ int sarHandler = INVALID_HANDLE;
//
// TREND Handler ...
int tkiHandler = INVALID_HANDLE;
int trendHandler = INVALID_HANDLE;
//
@@ -539,6 +569,22 @@ int OnInit()
return INIT_FAILED;
}
//
// TKI ...
tkiHandler = iMA(
_Symbol,
_Period,
kiLength,
0,
MODE_SMA,
PRICE_MEDIAN //
);
isInited = tkiHandler != INVALID_HANDLE;
if (!isInited)
{
return INIT_FAILED;
}
//
// TREND ...
trendHandler = iMA(
@@ -646,6 +692,10 @@ int OnCalculate(
// SAR ...
int sarCalculatedBars = BarsCalculated(sarHandler);
//
// TKI ...
int tkiCalculatedBars = BarsCalculated(tkiHandler);
//
// TREND ...
int trendCalculatedBars = BarsCalculated(trendHandler);
@@ -656,6 +706,9 @@ int OnCalculate(
// SAR ...
sarCalculatedBars >= maxLength &&
//
// TKI ...
tkiCalculatedBars >= maxLength &&
//
// TREND ...
trendCalculatedBars >= maxLength
//
@@ -677,6 +730,10 @@ int OnCalculate(
// SAR ...
int copiedSars = CopyBuffer(sarHandler, 0, 0, limit, sarBuffer);
//
// TKI ...
int copiedTKIs = CopyBuffer(tkiHandler, 0, 0, limit, tkiBuffer);
//
// TREND ...
int copiedTrends = CopyBuffer(trendHandler, MAIN_LINE, 0, limit + 1, trendBuffer);
@@ -688,6 +745,9 @@ int OnCalculate(
// SAR ...
copiedSars >= limit &&
//
// TKI ...
copiedTKIs >= limit &&
//
// TREND ...
copiedTrends >= limit
//
@@ -1130,6 +1190,27 @@ void DefineBuffers()
ArraySetAsSeries(kiColorBuffer, true);
SetIndexBuffer(kiColorBufferIndex, kiColorBuffer, INDICATOR_COLOR_INDEX);
//
// TKI ...
//
ENUM_DRAW_TYPE tkiDrawType = showTKI ? DRAW_COLOR_LINE : DRAW_NONE;
//
ArraySetAsSeries(tkiBuffer, true);
SetIndexBuffer(tkiBufferIndex, tkiBuffer, INDICATOR_DATA);
//
PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_SHOW_DATA, showKI);
// PlotIndexSetInteger(tkiBufferPlotIndex, PLOT_DRAW_TYPE, kiDrawType);
//
PlotIndexSetDouble(tkiBufferPlotIndex, PLOT_EMPTY_VALUE, emptyValue);
//
ArraySetAsSeries(tkiColorBuffer, true);
SetIndexBuffer(tkiColorBufferIndex, tkiColorBuffer, INDICATOR_COLOR_INDEX);
//
// SWINGS ...
@@ -1185,6 +1266,10 @@ void DefineBuffers()
ArraySetAsSeries(resBuffer, true);
SetIndexBuffer(resBufferIndex, resBuffer, INDICATOR_CALCULATIONS);
//
ArraySetAsSeries(tkiStateBuffer, true);
SetIndexBuffer(tkiStateBufferIndex, tkiStateBuffer, INDICATOR_CALCULATIONS);
//
}
@@ -1456,11 +1541,19 @@ void FillBuffersZero(int barIndex)
// TREND ...
trendBuffer[barIndex] = emptyValue;
trendColorBuffer[barIndex] = hideColorIDX;
trendStateBuffer[barIndex] = hideColorIDX;
//
// KI ...
kiBuffer[barIndex] = emptyValue;
kiColorBuffer[barIndex] = hideColorIDX;
kiStateBuffer[barIndex] = hideColorIDX;
//
// TKI ...
tkiBuffer[barIndex] = emptyValue;
tkiColorBuffer[barIndex] = hideColorIDX;
tkiStateBuffer[barIndex] = hideColorIDX;
//
// SWINGS ...
@@ -1786,19 +1879,25 @@ void CalculateValues(
double iTrend = trendBuffer[bar_index];
//
double iTrendState =
iClose > iTrend
? bullishColorIDX
: iClose < iTrend
? bearishColorIDX
: neuturalColorIDX;
double iTrendState = neuturalState;
double iTrendColor = neuturalColorIDX;
if (iClose > iTrend)
{
//
iTrendState = bullishState;
iTrendColor = !showTrend
? hideColorIDX
: bullishColorIDX;
}
else if (iClose < iTrend)
{
//
iTrendState = bearishState;
iTrendColor = !showTrend
? hideColorIDX
: bearishColorIDX;
}
trendStateBuffer[bar_index] = iTrendState;
//
double iTrendColor =
showTrend
? iTrendState
: hideColorIDX;
trendColorBuffer[bar_index] = iTrendColor;
//
@@ -1814,19 +1913,27 @@ void CalculateValues(
kiBuffer[bar_index] = iKI;
//
double iKIState =
iClose > iKI
? bullishColorIDX
: iClose < iKI
? bearishColorIDX
: neuturalColorIDX;
double iKIState = neuturalState;
double iKIColor = neuturalColorIDX;
if (iClose > iKI)
{
//
iKIState = bullishState;
iKIColor =
!showKI
? hideColorIDX
: bullishColorIDX;
}
else if (iClose < iKI)
{
//
iKIState = bearishState;
iKIColor =
!showKI
? hideColorIDX
: bearishColorIDX;
}
kiStateBuffer[bar_index] = iKIState;
//
double iKIColor =
showKI
? iKIState
: hideColorIDX;
kiColorBuffer[bar_index] = iKIColor;
}
@@ -1880,6 +1987,36 @@ void CalculateValues(
: lastSwingHigh;
swingHighBuffer[bar_index] = iSwingHigh;
//
// TKI State and Color ...
//
double iTKI = tkiBuffer[bar_index];
//
double iTKIState = neuturalState;
double iTKIColor = neuturalColorIDX;
if (iClose > iTKI)
{
//
iTKIState = bullishState;
iTKIColor =
!showTKI
? hideColorIDX
: bullishColorIDX;
}
else if (iClose < iTKI)
{
//
iTKIState = bearishState;
iTKIColor =
!showTKI
? hideColorIDX
: bearishColorIDX;
}
tkiStateBuffer[bar_index] = iTKIState;
tkiColorBuffer[bar_index] = iTKIColor;
//
// Cleanup Resources ...