complete some sort of new indicators helpers classes ...

This commit is contained in:
2024-05-18 16:55:28 +03:30
parent fb4445c1d7
commit e69dc85eea
11 changed files with 4874 additions and 187 deletions
+170 -177
View File
@@ -17,57 +17,44 @@
#property copyright "Copyright 2023, SaherElm IT Center"
#property link "https://saherelm.ir"
#property version "1.00"
#property description "SaherElm X121_XHK Indicator"
#property description "SaherElm XHK Indicator"
#property strict
//
// START Constants ...
//
// Constants ...
//
// Indicator Short Name ...
#define ShortName "X121_XHK"
#define ShortName "XHK"
//
// END Constants ...
//
//
// START Inputs ...
//
//
input group "Presentation";
input bool drawCandles = true; // Draw Hiken Ashi Candle
input bool drawCandleLines = false; // Show HikenAshi Lines
//
// END Inputs ...
//
//
// START Includes and Imports ...
//
//
// Includes Common Library ...
// Imports ...
#include <MovingAverages.mqh>
#include "../Libraries/x-saherelm.common.lib.mq5"
//
// END Includes and Imports ...
//
// Inputs ...
//
// START Buffers ...
input group "Market";
input int smoothingLength = 17; // Smoothing Length
//
input group "Presentation";
input bool drawHikenAshi = true; // Draw Hiken Ashi
input bool drawSmoothedHikenAshi = true; // Draw Smoothed Hiken Ashi
//
// Buffers ...
//
#property indicator_chart_window
//
#property indicator_buffers 13
#property indicator_plots 5
#property indicator_buffers 10
#property indicator_plots 10
//
// PLOTTED Buffers ...
// Buffers ...
//
// Open ...
@@ -98,84 +85,54 @@ double candleColorBuffer[];
#define candlesBufferIndex 0
//
#property indicator_label1 "X121_XHK Open;X121_XHK High;X121_XHK Low;X121_XHK Close"
#property indicator_label1 "XHK Open;XHK High;XHK Low;XHK Close"
#property indicator_type1 DRAW_COLOR_CANDLES
#property indicator_color1 clrAqua, clrMagenta, CLR_NONE
#property indicator_color1 CLR_NONE, clrAqua, clrMagenta
//
#define openHKBufferIndex 5
#define openHKColorBufferIndex 6
double openHKBuffer[];
double openHKColorBuffer[];
// SM Open ...
#define openSMBufferIndex 5
double openSMBuffer[];
//
#define openHKBufferPlotIndex 1
#property indicator_label2 "X121_XHK O"
#property indicator_type2 DRAW_COLOR_LINE
#property indicator_color2 clrAqua, clrMagenta, clrLightGray
#property indicator_style2 STYLE_DOT
#property indicator_width2 1
// SM High ...
#define highSMBufferIndex 6
double highSMBuffer[];
//
#define highHKBufferIndex 7
#define highHKColorBufferIndex 8
double highHKBuffer[];
double highHKColorBuffer[];
// SM Low ...
#define lowSMBufferIndex 7
double lowSMBuffer[];
//
#define highHKBufferPlotIndex 2
#property indicator_label3 "X121_XHK H"
#property indicator_type3 DRAW_COLOR_LINE
#property indicator_color3 clrAqua, clrMagenta, clrLightGray
#property indicator_style3 STYLE_DOT
#property indicator_width3 1
// SM Close ...
#define closeSMBufferIndex 8
double closeSMBuffer[];
//
#define lowHKBufferIndex 9
#define lowHKColorBufferIndex 10
double lowHKBuffer[];
double lowHKColorBuffer[];
// SM Candle Color ...
#define candleColorSMBufferIndex 9
double candleColorSMBuffer[];
//
#define lowHKBufferPlotIndex 3
#property indicator_label4 "X121_XHK L"
#property indicator_type4 DRAW_COLOR_LINE
#property indicator_color4 clrAqua, clrMagenta, clrLightGray
#property indicator_style4 STYLE_DOT
#property indicator_width4 1
#define candlesSMBufferIndex 1
//
#define closeHKBufferIndex 11
#define closeHKColorBufferIndex 12
double closeHKBuffer[];
double closeHKColorBuffer[];
#property indicator_label2 "XSMHK Open;XSMHK High;XSMHK Low;XSMHK Close"
#property indicator_type2 DRAW_COLOR_CANDLES
#property indicator_color2 CLR_NONE, clrDarkGreen, clrDarkRed
//
#define closeHKBufferPlotIndex 4
#property indicator_label5 "X121_XHK C"
#property indicator_type5 DRAW_COLOR_LINE
#property indicator_color5 clrAqua, clrMagenta, clrLightGray
#property indicator_style5 STYLE_DOT
#property indicator_width5 1
//
// END Buffers ...
//
//
// START Global Definitions: Variables, Properties and etc ...
//
// Variables, Properties and etc ...
//
int maxLength;
//
// END Global Definitions: Variables, Properties and etc ...
//
double mHideColorIDX = 0;
//
// START Event Handlers ...
//
// Event Handlers ...
//
// Initialization ...
@@ -228,36 +185,17 @@ void OnDeinit(const int reason)
//
// Calculating what we want ...
int OnCalculate(
//
// total Candles on chart ...
const int rates_total,
//
// total calculated Candles on charts ...
const int prev_calculated,
//
// history of Candles Open Time ...
const datetime &time[],
//
// history of Candles Open Price ...
const double &open[],
//
// history of Candles High Price ...
const double &high[],
//
// history of Candles Low Price ...
const double &low[],
//
// history of Candles Close Price ...
const double &close[],
//
// history of Tick Volumes on Candle ...
const long &tick_volume[],
//
// history of Trade Volumes ...
const long &volume[],
//
// history of Candles Spread Price ...
const int &spread[])
const int rates_total, // Total Bars on Chart ...
const int prev_calculated, // Total Calculated Bars on Charts ...
const datetime &time[], // History of Open Time ...
const double &open[], // History of Open Price ...
const double &high[], // History of High Price ...
const double &low[], // History of Low Price ...
const double &close[], // History of Close Price ...
const long &tick_volume[], // History of Tick Volumes on Bar ...
const long &volume[], // History of Trade Volumes ...
const int &spread[] // History of Spread Price ...
)
{
//
// Prepare Buffers ...
@@ -284,17 +222,15 @@ int OnCalculate(
CalculateBuffers(i, prev_calculated, rates_total, open, high, close, low);
}
//
CalculateSM(rates_total, prev_calculated);
//
return rates_total;
}
//
// END Event Handlers ...
//
//
// START Functions ...
//
// Functions ...
//
// Validate Input Args for Initialization ...
@@ -361,52 +297,41 @@ void DefineBuffers()
PlotIndexSetInteger(lowBufferIndex, PLOT_SHOW_DATA, false);
//
// Open HK ...
ENUM_DRAW_TYPE openDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(openHKBuffer, true);
SetIndexBuffer(openHKBufferIndex, openHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(openHKBufferPlotIndex, PLOT_DRAW_TYPE, openDrawType);
// Candles Color ...
ArraySetAsSeries(candleColorSMBuffer, true);
SetIndexBuffer(candleColorSMBufferIndex, candleColorSMBuffer, INDICATOR_COLOR_INDEX);
//
ArraySetAsSeries(openHKColorBuffer, true);
SetIndexBuffer(openHKColorBufferIndex, openHKColorBuffer, INDICATOR_COLOR_INDEX);
// Set EMPTY_VALUE on Candles Buffer ...
PlotIndexSetDouble(candlesSMBufferIndex, PLOT_EMPTY_VALUE, 0.0);
//
// High HK ...
ENUM_DRAW_TYPE highDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(highHKBuffer, true);
SetIndexBuffer(highHKBufferIndex, highHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(highHKBufferPlotIndex, PLOT_DRAW_TYPE, highDrawType);
PlotIndexSetInteger(candlesSMBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(candleColorSMBufferIndex, PLOT_SHOW_DATA, false);
//
ArraySetAsSeries(highHKColorBuffer, true);
SetIndexBuffer(highHKColorBufferIndex, highHKColorBuffer, INDICATOR_COLOR_INDEX);
// Open ...
ArraySetAsSeries(openSMBuffer, true);
PlotIndexSetInteger(openSMBufferIndex, PLOT_SHOW_DATA, false);
SetIndexBuffer(openSMBufferIndex, openSMBuffer, INDICATOR_DATA);
//
// Low HK ...
ENUM_DRAW_TYPE lowDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(lowHKBuffer, true);
SetIndexBuffer(lowHKBufferIndex, lowHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(lowHKBufferPlotIndex, PLOT_DRAW_TYPE, lowDrawType);
// High ...
ArraySetAsSeries(highSMBuffer, true);
SetIndexBuffer(highSMBufferIndex, highSMBuffer, INDICATOR_DATA);
PlotIndexSetInteger(highSMBufferIndex, PLOT_SHOW_DATA, false);
//
ArraySetAsSeries(lowHKColorBuffer, true);
SetIndexBuffer(lowHKColorBufferIndex, lowHKColorBuffer, INDICATOR_COLOR_INDEX);
// Close ...
ArraySetAsSeries(closeSMBuffer, true);
SetIndexBuffer(closeSMBufferIndex, closeSMBuffer, INDICATOR_DATA);
PlotIndexSetInteger(closeSMBufferIndex, PLOT_SHOW_DATA, false);
//
// Close HK ...
ENUM_DRAW_TYPE closeDrawType = drawCandleLines ? DRAW_COLOR_LINE : DRAW_NONE;
ArraySetAsSeries(closeHKBuffer, true);
SetIndexBuffer(closeHKBufferIndex, closeHKBuffer, INDICATOR_DATA);
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_SHOW_DATA, drawCandleLines);
PlotIndexSetInteger(closeHKBufferPlotIndex, PLOT_DRAW_TYPE, closeDrawType);
//
ArraySetAsSeries(closeHKColorBuffer, true);
SetIndexBuffer(closeHKColorBufferIndex, closeHKColorBuffer, INDICATOR_COLOR_INDEX);
// Low ...
ArraySetAsSeries(lowSMBuffer, true);
SetIndexBuffer(lowSMBufferIndex, lowSMBuffer, INDICATOR_DATA);
PlotIndexSetInteger(lowSMBufferIndex, PLOT_SHOW_DATA, false);
}
//
@@ -425,7 +350,8 @@ void CalculateBuffers(
const double &open[],
const double &high[],
const double &close[],
const double &low[])
const double &low[] //
)
{
//
double mPrevHKOpenValue;
@@ -458,29 +384,96 @@ void CalculateBuffers(
closeBuffer[bar_index] = mHKCloseValue;
//
double candleColorValue =
mHKOpenValue < mHKCloseValue ? 0 : 1;
bool isBearish =
//
candleColorBuffer[bar_index] = drawCandles ? candleColorValue : 2;
openBuffer[bar_index] > closeBuffer[bar_index]
//
;
//
openHKBuffer[bar_index] = mHKOpenValue;
openHKColorBuffer[bar_index] = candleColorValue;
//
highHKBuffer[bar_index] = mHKHighValue;
highHKColorBuffer[bar_index] = candleColorValue;
//
lowHKBuffer[bar_index] = mHKLowValue;
lowHKColorBuffer[bar_index] = candleColorValue;
//
closeHKBuffer[bar_index] = mHKCloseValue;
closeHKColorBuffer[bar_index] = candleColorValue;
candleColorBuffer[bar_index] = !drawHikenAshi
? mHideColorIDX
: isBearish
? 2
: 1;
}
//
// END Functions ...
//
// Calculate Smoothed HikenAshi ...
void CalculateSM(
int ratesTotal, // Total Bars
int prevCalculated // Calculated Bars
)
{
//
// Open ...
int calculatedSMHKOpens = ExponentialMAOnBuffer(
ratesTotal,
prevCalculated,
0,
smoothingLength,
openBuffer,
openSMBuffer);
//
// High ...
int calculatedSMHKHighs = ExponentialMAOnBuffer(
ratesTotal,
prevCalculated,
0,
smoothingLength,
highBuffer,
highSMBuffer);
//
// Low ...
int calculatedSMHKLows = ExponentialMAOnBuffer(
ratesTotal,
prevCalculated,
0,
smoothingLength,
lowBuffer,
lowSMBuffer);
//
// Close ...
int calculatedSMHKCloses = ExponentialMAOnBuffer(
ratesTotal,
prevCalculated,
0,
smoothingLength,
closeBuffer,
closeSMBuffer);
//
// Find Calculated Items for Colors ...
int mNumberOfItems = MathMin(calculatedSMHKOpens, calculatedSMHKHighs);
mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKLows);
mNumberOfItems = MathMin(mNumberOfItems, calculatedSMHKCloses);
//
// Create a Loop for Color of Candles ...
for (int i = 0; i < mNumberOfItems; i++)
{
//
bool isBearish =
//
openSMBuffer[i] > closeSMBuffer[i]
//
;
//
if (drawSmoothedHikenAshi)
{
//
candleColorSMBuffer[i] = isBearish
? 2
: 1;
}
else
{
//
candleColorSMBuffer[i] = mHideColorIDX;
}
}
}
+1
View File
@@ -906,6 +906,7 @@ void CalculateCycle(
double &llColorBuffer[] //
)
{
//
cycle.Update(barIndex);
//
+9 -6
View File
@@ -348,10 +348,9 @@ void DefineBuffers()
//
ENUM_DRAW_TYPE upDrawType = showUp ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(upBuffer, true);
SetIndexBuffer(upBufferIndex, upBuffer, INDICATOR_DATA);
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, false);
PlotIndexSetInteger(upBufferIndex, PLOT_SHOW_DATA, showUp);
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_BEGIN, maxLength);
PlotIndexSetInteger(upBufferIndex, PLOT_DRAW_TYPE, upDrawType);
@@ -361,7 +360,6 @@ void DefineBuffers()
//
ENUM_DRAW_TYPE downDrawType = showDown ? DRAW_LINE : DRAW_NONE;
ArraySetAsSeries(downBuffer, true);
SetIndexBuffer(downBufferIndex, downBuffer, INDICATOR_DATA);
PlotIndexSetInteger(downBufferIndex, PLOT_SHOW_DATA, showDown);
@@ -412,11 +410,16 @@ void CalculateBuffers(
//
double kpiValue;
if (closeValue > upMaValue) {
if (closeValue > upMaValue)
{
kpiValue = 1;
} else if (closeValue < downMaValue) {
}
else if (closeValue < downMaValue)
{
kpiValue = -1;
} else {
}
else
{
kpiValue = kpiBuffer[bar_index + 1];
}