Skip to content

Commit

Permalink
Merge pull request #772 from nseam/v3.009-dev-new--get-lowest-highest…
Browse files Browse the repository at this point in the history
…-checks

Fixes for GetLowest(), GetHighest() for Indicator/IndicatorData with data export fixes
  • Loading branch information
kenorb authored Sep 18, 2024
2 parents 3fc6cad + 8844e84 commit feee6c2
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 133 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- MarketTest
- SummaryReportTest
- TradeTest
year: [2022, 2024]
version: [5]
max-parallel: 4
steps:
Expand All @@ -72,6 +73,7 @@ jobs:
# yamllint disable-line rule:line-length
UrlExpert: file://${{ github.workspace }}/${{ env.TEST_PATH }}/${{ matrix.test }}.ex${{ matrix.version }}
Version: 5
RunnerTimeout: 1200
- if: ${{ failure() && runner.debug == '1' }}
uses: mxschmitt/action-tmate@v3
timeout-minutes: 20
Expand Down
57 changes: 49 additions & 8 deletions Indicator/Indicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ struct IndicatorParams;
#include "Indicator.enum.h"
#include "Indicator.struct.h"
#include "Indicator.struct.serialize.h"
#include "IndicatorCandle.enum.h"
#include "IndicatorData.h"

// Includes.
#include "../Indicators/DrawIndicator.mqh"
#include "../Math/Math.h"
#include "../Platform/Chart/Chart.define.h"
#include "../Refs.mqh"
#include "../Serializer/Serializer.h"
#include "../Serializer/SerializerCsv.h"
Expand Down Expand Up @@ -160,15 +162,20 @@ class Indicator : public IndicatorData {
/**
* Returns the highest bar's index (shift).
*/
template <typename T>
int GetHighest(int count = WHOLE_ARRAY, int start_bar = 0) {
int GetHighest(int mode, int count = WHOLE_ARRAY, int start_bar = 0) override {
if (GetCandle() != THIS_PTR) {
Alert("You can only use ", __FUNCTION__, " on the Candle-based indicator! ", GetFullName(),
" is not a Candle indicator.");
DebugBreak();
return -1;
}

int max_idx = -1;
double max = -DBL_MAX;
int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1);

for (int shift = start_bar; shift <= last_bar; ++shift) {
IndicatorDataEntry _entry = GetEntry(shift);
double value = _entry.GetMax<T>(GetModeCount());
double value = GetValue<double>((int)GetCandleIndicatorMode(mode), shift);
if (value > max) {
max = value;
max_idx = shift;
Expand All @@ -181,15 +188,20 @@ class Indicator : public IndicatorData {
/**
* Returns the lowest bar's index (shift).
*/
template <typename T>
int GetLowest(int count = WHOLE_ARRAY, int start_bar = 0) {
int GetLowest(int mode, int count = WHOLE_ARRAY, int start_bar = 0) override {
if (GetCandle() != THIS_PTR) {
Alert("You can only use ", __FUNCTION__, " on the Candle-based indicator! ", GetFullName(),
" is not a Candle indicator.");
DebugBreak();
return -1;
}

int min_idx = -1;
double min = DBL_MAX;
int last_bar = count == WHOLE_ARRAY ? (int)(GetBarShift(GetLastBarTime())) : (start_bar + count - 1);

for (int shift = start_bar; shift <= last_bar; ++shift) {
IndicatorDataEntry _entry = GetEntry(shift);
double value = _entry.GetMin<T>(GetModeCount());
double value = GetValue<double>((int)GetCandleIndicatorMode(mode), shift);
if (value < min) {
min = value;
min_idx = shift;
Expand All @@ -199,6 +211,35 @@ class Indicator : public IndicatorData {
return min_idx;
}

/**
* Converts Series Array Indentifier into mode index to be retrieved from Candle indicator.
*
* Possible values:
* MODE_OPEN, MODE_LOW, MODE_HIGH, MODE_CLOSE, MODE_VOLUME, MODE_TIME.
*/
ENUM_INDI_CANDLE_MODE GetCandleIndicatorMode(int _series_array_id) {
switch (_series_array_id) {
case MODE_OPEN:
return INDI_CANDLE_MODE_PRICE_OPEN;
case MODE_LOW:
return INDI_CANDLE_MODE_PRICE_LOW;
case MODE_HIGH:
return INDI_CANDLE_MODE_PRICE_HIGH;
case MODE_CLOSE:
return INDI_CANDLE_MODE_PRICE_CLOSE;
case MODE_VOLUME:
case MODE_REAL_VOLUME:
return INDI_CANDLE_MODE_VOLUME;
case MODE_TIME:
return INDI_CANDLE_MODE_TIME;
default:
Alert("Unsupported mode ", IntegerToString(_series_array_id), ", for ", __FUNCTION__, "");
DebugBreak();
}

return (ENUM_INDI_CANDLE_MODE)0;
}

/* Setters */

/**
Expand Down
48 changes: 48 additions & 0 deletions Indicator/IndicatorCandle.enum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2024, EA31337 Ltd |
//| https://ea31337.github.io |
//+------------------------------------------------------------------+

/*
* This file is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* @file
* Includes IndicatorCandle's enums.
*/

#ifndef __MQL__
// Allows the preprocessor to include a header file when it is needed.
#pragma once
#endif

// Indicator modes.
enum ENUM_INDI_CANDLE_MODE {
INDI_CANDLE_MODE_PRICE_OPEN,
INDI_CANDLE_MODE_PRICE_HIGH,
INDI_CANDLE_MODE_PRICE_LOW,
INDI_CANDLE_MODE_PRICE_CLOSE,
INDI_CANDLE_MODE_SPREAD,
INDI_CANDLE_MODE_TICK_VOLUME,
INDI_CANDLE_MODE_TIME,
INDI_CANDLE_MODE_VOLUME,
FINAL_INDI_CANDLE_MODE_ENTRY,
// Following modes are dynamically calculated.
INDI_CANDLE_MODE_PRICE_MEDIAN,
INDI_CANDLE_MODE_PRICE_TYPICAL,
INDI_CANDLE_MODE_PRICE_WEIGHTED,
};
18 changes: 1 addition & 17 deletions Indicator/IndicatorCandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "../Storage/ValueStorage.time.h"
#include "../Storage/ValueStorage.volume.h"
#include "Indicator.h"
#include "IndicatorCandle.enum.h"
#include "IndicatorCandle.provider.h"
#include "IndicatorData.h"
#include "TickBarCounter.h"
Expand All @@ -44,23 +45,6 @@
#define INDI_CANDLE_HISTORY_SIZE 86400
#endif

// Indicator modes.
enum ENUM_INDI_CANDLE_MODE {
INDI_CANDLE_MODE_PRICE_OPEN,
INDI_CANDLE_MODE_PRICE_HIGH,
INDI_CANDLE_MODE_PRICE_LOW,
INDI_CANDLE_MODE_PRICE_CLOSE,
INDI_CANDLE_MODE_SPREAD,
INDI_CANDLE_MODE_TICK_VOLUME,
INDI_CANDLE_MODE_TIME,
INDI_CANDLE_MODE_VOLUME,
FINAL_INDI_CANDLE_MODE_ENTRY,
// Following modes are dynamically calculated.
INDI_CANDLE_MODE_PRICE_MEDIAN,
INDI_CANDLE_MODE_PRICE_TYPICAL,
INDI_CANDLE_MODE_PRICE_WEIGHTED,
};

/**
* Class to deal with candle indicators.
*/
Expand Down
Loading

0 comments on commit feee6c2

Please sign in to comment.