Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indicators refactor (part 3) #634

Merged
merged 41 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
6b147ae
Adds TickManager
kenorb Oct 28, 2021
95f05ac
Tick/TickManager: Adds TickManagerOverflowListener()
kenorb Oct 29, 2021
484bd82
Fixed Dicts to take into consideration overflow listeners.
nseam Nov 8, 2021
1f2902c
GHA: Adds Tick tests
kenorb Nov 8, 2021
5a9836c
Merge tag 'v2.009' into dev-tickmanager
kenorb Nov 9, 2021
3b2045d
Chart: ChartTf: Adds SecsToTf()
kenorb Oct 28, 2021
182f79f
Indi_AC: Sets 2 modes when using iCustom()
kenorb Nov 9, 2021
f60a9fc
Indicator: Moves Init() to protected section
kenorb Nov 9, 2021
c508d52
Fixes problem with non-visual mode 4086 errors due to BarsCalculated(…
nseam Nov 12, 2021
b85e815
GHA: Uses 4.0.0.1349 to run main tests
kenorb Dec 5, 2021
fee7085
GHA: Uses 4.0.0.1349 to compile main tests
kenorb Dec 5, 2021
43829c3
GHA: Removes init-platform due to hang
kenorb Dec 5, 2021
61b6c16
Merge pull request #617 from EA31337/dev-tickmanager
kenorb Dec 5, 2021
9603dc3
WIP. i*OnIndicator versions of all indicators (except MA).
nseam Dec 7, 2021
1aa8db9
Fixed Dicts to take into consideration overflow listeners.
nseam Nov 8, 2021
66d435a
Merge pull request #622 from EA31337/dev
kenorb Dec 9, 2021
a493f36
WIP. Finished i*OnIndicator mode for all indicators except MA. Change…
nseam Dec 9, 2021
f4c946d
WIP. AMA now requires refactor back to be parent of Indicator or some…
nseam Dec 11, 2021
761face
WIP. Introduces IndicatorCandleSource and IndicatorTickSource indicat…
nseam Dec 15, 2021
fea144a
WIP. Almost working AMA indicator (still varies to much with original…
nseam Dec 16, 2021
0e14527
WIP. Partially working Tick/Candle/TickOrCandle indicators differenti…
nseam Dec 22, 2021
c5be80f
WIP. Closer to the end. Now we need to find a way to feed indicator w…
nseam Dec 29, 2021
08c6062
Indi_MA: Renames InpMAPeriod to _ma_period to avoid global variable c…
kenorb Dec 29, 2021
506d08e
Indi_MA: Renames InpMAMethod to _ma_method to avoid global variable c…
kenorb Dec 29, 2021
88d0a7c
WIP. Now we need to find a way to make BufferTick to provide continuo…
nseam Dec 30, 2021
c2a87cd
AS-IS.
nseam Jan 4, 2022
435f1d1
WIP. IndicatorsTest ready for testing!
nseam Jan 5, 2022
a7f3334
Adds Indi_Custom indicator
kenorb Jan 5, 2022
c6bc378
Merge branch 'dev' of https://github.com/EA31337/EA31337-classes into…
nseam Jan 6, 2022
58f94f9
Fixed bug with IndicatorBase::GetValue() which called GetEntryValue()…
nseam Jan 7, 2022
d1c927b
EA: Adds enum's comment
kenorb Jan 8, 2022
a47681b
Merge branch 'dev-indi-custom' into dev
kenorb Jan 8, 2022
d93deb8
Improves tasks return logic
kenorb Jan 8, 2022
2640ceb
Merge branch 'dev' of https://github.com/EA31337/EA31337-classes into…
nseam Jan 12, 2022
e950493
State of the art
nseam Jan 12, 2022
078af3a
Looks like there is nothing more to do with AMA. Differences are marg…
nseam Jan 13, 2022
8e39201
Fixed order of mode and shift when calling Indicator::GetValue<T>(). …
nseam Jan 18, 2022
71108dc
Fixed typo in auxiliary indicator fetching by ID.
nseam Jan 18, 2022
a469c5e
Merge branch 'dev-indicator-refactor' of https://github.com/EA31337/E…
nseam Jan 18, 2022
6ee889c
Fixes EOL characters
kenorb Jan 18, 2022
74eb036
IndicatorsTest was set to test only AMA or Pattern indicator. Now it …
nseam Jan 19, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/test-indicators-special.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
name: Test Indicators (Special)

# yamllint disable-line rule:truthy
on:
pull_request:
paths:
- 'Indicator**'
- 'Indicators/Special/**'
- '.github/workflows/test-indicators-special.yml'
push:
paths:
- 'Indicator**'
- 'Indicators/Special/**'
- '.github/workflows/test-indicators-special.yml'

jobs:

Compile:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Compile
uses: fx31337/mql-compile-action@master
with:
init-platform: true
path: 'Indicators/Special/tests'
verbose: true
- name: Print compiled files
run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname'
shell: powershell
- name: Upload artifacts (MQL4)
uses: actions/upload-artifact@v2
with:
name: files-ex4
path: '**/*.ex4'
- name: Upload artifacts (MQL5)
uses: actions/upload-artifact@v2
with:
name: files-ex5
path: '**/*.ex5'

Indicators-Tests-MQL4:
defaults:
run:
shell: bash
working-directory: Indicators/tests
needs: Compile
runs-on: ubuntu-latest
strategy:
matrix:
test:
- Indi_Custom.test
steps:
- uses: actions/download-artifact@v2
with:
name: files-ex4
- name: Run ${{ matrix.test }}
uses: fx31337/mql-tester-action@master
with:
BtDays: 4-8
BtMonths: 1
BtYears: 2020
TestExpert: ${{ matrix.test }}
timeout-minutes: 10
58 changes: 58 additions & 0 deletions .github/workflows/test-tick.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
name: Test Tick

# yamllint disable-line rule:truthy
on:
pull_request:
paths:
- 'Tick/**.h'
- '.github/workflows/test-tick.yml'
push:
paths:
- 'Tick/**.h'
- '.github/workflows/test-tick.yml'

jobs:

Compile:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Compile
uses: fx31337/mql-compile-action@master
with:
path: 'Tick/tests'
verbose: true
- name: Print compiled files
run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname'
shell: powershell
- name: Upload artifacts (MQL4)
uses: actions/upload-artifact@v2
with:
name: files-ex4
path: '**/*.ex4'
- name: Upload artifacts (MQL5)
uses: actions/upload-artifact@v2
with:
name: files-ex5
path: '**/*.ex5'

Tick-Tests-MQL4:
defaults:
run:
shell: bash
working-directory: Tick/tests
needs: Compile
runs-on: ubuntu-latest
strategy:
matrix:
test:
- TickManager.test
steps:
- uses: actions/download-artifact@v2
with:
name: files-ex4
- name: Run ${{ matrix.test }}
uses: fx31337/mql-tester-action@master
with:
Script: ${{ matrix.test }}
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: Compile
uses: fx31337/mql-compile-action@master
with:
init-platform: true
mt-version: 4.0.0.1349
verbose: true
- name: Print compiled files
run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname'
Expand Down Expand Up @@ -89,6 +89,7 @@ jobs:
BtDays: 1-8
BtMonths: 1
BtYears: 2020
MtVersion: 4.0.0.1349
TestExpert: ${{ matrix.test }}
timeout-minutes: 10

Expand Down
8 changes: 5 additions & 3 deletions Action.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ class Action {
* Returns true when the condition is met.
*/
bool CheckCondition(ENUM_ACTION_CONDITION _cond, DataParamEntry &_args[]) {
bool _result = false;
switch (_cond) {
case ACTION_COND_IS_ACTIVE:
// Is active;
Expand All @@ -321,8 +322,9 @@ class Action {
return IsInvalid();
default:
logger.Ptr().Error(StringFormat("Invalid Action condition: %s!", EnumToString(_cond), __FUNCTION_LINE__));
return false;
break;
}
return _result;
}
bool CheckCondition(ENUM_ACTION_CONDITION _cond) {
ARRAY(DataParamEntry, _args);
Expand All @@ -338,7 +340,7 @@ class Action {
* Returns true when the action has been executed successfully.
*/
bool ExecuteAction(ENUM_ACTION_ACTION _action, DataParamEntry &_args[]) {
bool _result = true;
bool _result = false;
switch (_action) {
case ACTION_ACTION_DISABLE:
// Disable action.
Expand All @@ -360,7 +362,7 @@ class Action {
return SetFlags(ACTION_ENTRY_FLAG_IS_INVALID);
default:
logger.Ptr().Error(StringFormat("Invalid action of action: %s!", EnumToString(_action), __FUNCTION_LINE__));
return false;
break;
}
return _result;
}
Expand Down
78 changes: 76 additions & 2 deletions Buffer/BufferTick.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,52 @@

// Includes.
#include "../BufferStruct.mqh"
#include "../Chart.enum.h"
#include "../Storage/IValueStorage.h"
#include "../Tick.struct.h"

template <typename TV>
class BufferTickValueStorage : ValueStorage<TV> {
// Poiner to buffer to take tick from.
BufferTick<TV> *buffer_tick;

// PRICE_ASK or PRICE_BID.
int applied_price;

public:
/**
* Constructor.
*/
BufferTickValueStorage(BufferTick<TV> *_buffer_tick, int _applied_price)
: buffer_tick(_buffer_tick), applied_price(_applied_price) {}

/**
* Fetches value from a given shift. Takes into consideration as-series flag.
*/
TV Fetch(int _shift) override {
Print("BufferTickValueStorage: Fetching " + (applied_price == PRICE_ASK ? "Ask" : "Bid") + " price from shift ",
_shift);
return 0;
}

/**
* Returns number of values available to fetch (size of the values buffer).
*/
int Size() const override { return (int)buffer_tick.Size(); }
};

/**
* Class to store struct data.
*/
template <typename TV>
class BufferTick : public BufferStruct<TickAB<TV>> {
protected:
// Ask prices ValueStorage proxy.
BufferTickValueStorage<TV> *_vs_ask;

// Bid prices ValueStorage proxy.
BufferTickValueStorage<TV> *_vs_bid;

protected:
/* Protected methods */

Expand All @@ -42,7 +80,11 @@ class BufferTick : public BufferStruct<TickAB<TV>> {
*
* Called on constructor.
*/
void Init() { SetOverflowListener(BufferTickOverflowListener, 10); }
void Init() {
_vs_ask = NULL;
_vs_bid = NULL;
SetOverflowListener(BufferTickOverflowListener, 10);
}

public:
/* Constructors */
Expand All @@ -51,11 +93,43 @@ class BufferTick : public BufferStruct<TickAB<TV>> {
* Constructor.
*/
BufferTick() { Init(); }
BufferTick(BufferTick& _right) {
BufferTick(BufferTick &_right) {
THIS_REF = _right;
Init();
}

/**
* Destructor.
*/
~BufferTick() {
if (_vs_ask != NULL) {
delete _vs_ask;
}
if (_vs_bid != NULL) {
delete _vs_bid;
}
}

/**
* Returns Ask prices ValueStorage proxy.
*/
BufferTickValueStorage<TV> *GetAskValueStorage() {
if (_vs_ask == NULL) {
_vs_ask = new BufferTickValueStorage<TV>(THIS_PTR, PRICE_ASK);
}
return _vs_ask;
}

/**
* Returns Bid prices ValueStorage proxy.
*/
BufferTickValueStorage<TV> *GetBidValueStorage() {
if (_vs_bid == NULL) {
_vs_bid = new BufferTickValueStorage<TV>(THIS_PTR, PRICE_BID);
}
return _vs_bid;
}

/* Grouping methods */

/**
Expand Down
5 changes: 5 additions & 0 deletions Chart.enum.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,14 @@ enum ENUM_APPLIED_PRICE {
PRICE_MEDIAN, // Median price (H+L)/2
PRICE_TYPICAL, // Typical price, (H+L+C)/3
PRICE_WEIGHTED, // Weighted close price (H+L+C+C)/4
FINAL_APPLIED_PRICE_ENTRY
};
#endif

// Additional modes for applied price.
#define PRICE_ASK ((ENUM_APPLIED_PRICE)128)
#define PRICE_BID ((ENUM_APPLIED_PRICE)129)

// Defines enumeration for chart parameters.
enum ENUM_CHART_PARAM {
CHART_PARAM_NONE = 0, // None
Expand Down
2 changes: 1 addition & 1 deletion Chart.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class Chart : public Market {
* @return
* Returns ChartEntry struct.
*/
ChartEntry GetEntry(unsigned int _shift = 0) {
ChartEntry GetEntry(int _shift = 0) {
ChartEntry _chart_entry;
BarOHLC _ohlc = GetOHLC(_shift);
if (_ohlc.open > 0) {
Expand Down
22 changes: 14 additions & 8 deletions Dict.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -205,24 +205,30 @@ class Dict : public DictBase<K, V> {
* Inserts value into given array of DictSlots.
*/
bool InsertInto(DictSlotsRef<K, V>& dictSlotsRef, const K key, V value, bool allow_resize) {
// Will resize dict if there were performance problems before.
if (allow_resize && !dictSlotsRef.IsPerformant()) {
if (!GrowUp()) {
return false;
}
}

if (_mode == DictModeUnknown)
_mode = DictModeDict;
else if (_mode != DictModeDict) {
Alert("Warning: Dict already operates as a list, not a dictionary!");
DebugBreak();
return false;
}

unsigned int position;
DictSlot<K, V>* keySlot = GetSlotByKey(dictSlotsRef, key, position);

if (keySlot == NULL && !IsGrowUpAllowed()) {
// Resize is prohibited.
return false;
}

// Will resize dict if there were performance problems before.
if (allow_resize && IsGrowUpAllowed() && !dictSlotsRef.IsPerformant()) {
if (!GrowUp()) {
return false;
}
// We now have new positions of slots, so we have to take the corrent slot again.
keySlot = GetSlotByKey(dictSlotsRef, key, position);
}

if (keySlot == NULL && dictSlotsRef._num_used == ArraySize(dictSlotsRef.DictSlots)) {
// No DictSlotsRef.DictSlots available.
if (overflow_listener != NULL) {
Expand Down
17 changes: 17 additions & 0 deletions DictBase.mqh
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,18 @@ class DictBase {
// No key found.
}

/**
* Checks whether overflow listener allows dict to grow up.
*/
bool IsGrowUpAllowed() {
if (overflow_listener == NULL) {
return true;
}

// Checking if overflow listener allows resize from current to higher number of slots.
return overflow_listener(DICT_OVERFLOW_REASON_FULL, Size(), 0);
}

/**
* Moves last slot to given one to fill the hole after removing the value.
*/
Expand All @@ -280,6 +292,11 @@ class DictBase {
*/
const unsigned int Size() { return _DictSlots_ref._num_used; }

/**
* Returns number of all (reserved) DictSlots.
*/
const unsigned int ReservedSize() { return ArraySize(_DictSlots_ref.DictSlots); }

/**
* Checks whether given key exists in the dictionary.
*/
Expand Down
Loading