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

Indicator logic refactor #642

Merged
merged 97 commits into from
Jul 2, 2022
Merged
Changes from 1 commit
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
dbf7af0
Indicator: Adds IndicatorTick
kenorb Oct 28, 2021
6cc1f53
Merge tag 'v2.009' into dev-indicatortick
kenorb Nov 8, 2021
d829961
Indicator: Fixes compilation errors
kenorb Nov 9, 2021
b05cd01
Merge remote-tracking branch 'nseam/dev-getvalue-refactor' into dev-i…
kenorb Nov 9, 2021
e8554a1
IndicatorTick: Fixes compilation errors
kenorb Nov 9, 2021
53310b4
Indicators: Adds Indi_TickMt
kenorb Oct 31, 2021
ad83367
Tick/Indi_TickMt: Renames GetValue() to GetMixedValue()
kenorb Nov 9, 2021
28ff4d4
IndicatorTick: Implements tick fetching logic
kenorb Nov 9, 2021
565e493
Indicator: Renames GetMixedValue to GetEntryValue
kenorb Nov 8, 2021
42a6879
Indicator/IndicatorTick: Fixes return type
kenorb Nov 8, 2021
16385fd
Indicator: Moving some methods from base class to main
kenorb Nov 9, 2021
cbfb318
Merge remote-tracking branch 'origin/master' into dev-indicatortick
kenorb Nov 9, 2021
9f9c620
IndicatorTick: Adds SetTick()
kenorb Nov 9, 2021
4115a08
IndicatorTick: Implements test
kenorb Nov 9, 2021
ef95f6f
Indicator: Adds IndicatorCandle class
kenorb Nov 9, 2021
cc38869
Indicator: Adds IndicatorTf class
kenorb Nov 10, 2021
4fbbc91
Indicator: Adds README.md with info about indicators
kenorb Nov 11, 2021
1c9a5eb
Adds CandleOHLC and CandleTOHLC structs
kenorb Nov 11, 2021
b7b85d6
Buffer: Adds BufferCandle
kenorb Nov 11, 2021
e80fd94
Indicator/IndicatorCandle: Adds BufferCandle
kenorb Nov 11, 2021
88e4c71
Renames MqlTick.h to MqlTick.struct.h
kenorb Nov 11, 2021
e0632a6
Renames MqlTick.struct.h to Tick.struct.h
kenorb Nov 11, 2021
f47bd09
Adds TickAB and TickTAB structs
kenorb Nov 11, 2021
cb7ba0d
Buffer: Adds BufferTick
kenorb Nov 11, 2021
11dd812
Chart: ChartTf: Adds SecsToTf()
kenorb Oct 28, 2021
0b2e66f
Indicator/IndicatorTf: Improves constructors
kenorb Nov 11, 2021
112a998
Just some WIP.
nseam Nov 19, 2021
7696319
WIP. Added idea of event listeners for indicators and emitting a hist…
nseam Nov 22, 2021
1d2427a
WIP. Added candle grouping when receiving ticks via OnDataSourceEntry().
nseam Nov 23, 2021
e625d6f
Working simulation of real ticking indicator.
nseam Nov 25, 2021
04378bd
Moved example indicator classes into separate files. Added OnIndicato…
nseam Nov 26, 2021
f7b99ec
Added support for MT4.
nseam Nov 26, 2021
3537a04
WIP. Trying to make "AMA on Candle indicator on Tick indicator" to pr…
nseam Nov 30, 2021
f92dda0
Probably working scenario of AMA <- IndicatorTfDummy(IndicatorCandle)…
nseam Dec 3, 2021
6f3b99a
Fixed Util::ArrayRemove() method.
nseam Dec 3, 2021
83676b6
Merge pull request #619 from nseam/dev-indicator-refactor
kenorb Dec 5, 2021
28bc1e9
Account/SymbolInfo: Adds copy constructors
kenorb Dec 5, 2021
3871dd8
Adds Exchange class and tests
kenorb Dec 5, 2021
3f09d09
Exchange: Adds Trade
kenorb Dec 5, 2021
92bb334
SymbolInfo: Adds class constructor with symbol properties
kenorb Dec 5, 2021
78323e0
Exchange: Adds methods to add/remove account and symbol
kenorb Dec 5, 2021
9603dc3
WIP. i*OnIndicator versions of all indicators (except MA).
nseam Dec 7, 2021
a94b5c4
SymbolInfo: SymbolInfoEntry: Fixes struct copy constructor
kenorb Dec 8, 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
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
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
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
35af70c
Merge pull request #621 from EA31337/dev-exchange
kenorb Jan 15, 2022
af586ee
Moves Deal enums to Deal.enum.h
kenorb Jan 17, 2022
f6fb496
Moves enums and structs from Std and MQL5 to appropriate files
kenorb Jan 17, 2022
19a1a84
Adds .extern.h files
kenorb Jan 18, 2022
79e542c
Adds code page defines
kenorb Jan 18, 2022
df9180d
Adds Common and File defines
kenorb Jan 18, 2022
a70c358
Integrates extern includes
kenorb Jan 18, 2022
c3bb151
Refs: Uses PTR_ATTRIB syntax
kenorb Jan 18, 2022
871cc70
Fixed order of mode and shift when calling Indicator::GetValue<T>(). …
nseam Jan 18, 2022
fde05e4
Adds .extern.h file for DateTime
kenorb Jan 18, 2022
471e417
Adds StringSplit() as extern
kenorb Jan 18, 2022
f2142ea
Adds Compile workflow for CPP
kenorb Jan 18, 2022
8e39201
Fixed order of mode and shift when calling Indicator::GetValue<T>(). …
nseam Jan 18, 2022
9afdefb
Merge pull request #632 from nseam/dev-indicator-refactor
kenorb 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
e17381a
GHA: Compiles based on the file list
kenorb Jan 18, 2022
0b8be3b
Adds TradeSignal and TradeSignalManager C++ compilation tests
kenorb Jan 18, 2022
6ee889c
Fixes EOL characters
kenorb Jan 18, 2022
8826b3d
Trade: Fixes C++ compilation errors
kenorb Jan 18, 2022
74eb036
IndicatorsTest was set to test only AMA or Pattern indicator. Now it …
nseam Jan 19, 2022
1dc8803
Making MQL code to compile in C++. Especially the TradeSignalManager.…
nseam Jan 19, 2022
57af000
Merge pull request #634 from nseam/dev-indicator-refactor
kenorb Jan 19, 2022
1c8a2ed
State in the art of MQL/C++ compatibility.
nseam Jan 20, 2022
98f7b4e
Working compilation via GCC for TradeSignal.test.cpp and TradeSignalM…
nseam Jan 21, 2022
abf3b60
Merge pull request #636 from EA31337/dev-indicator-refactor
kenorb Jan 23, 2022
8d1e4a5
Should fix all GCC warnings.
nseam Jan 24, 2022
e76c4e5
Merge pull request #637 from nseam/dev-cpp
kenorb Jan 24, 2022
208de59
Merge remote-tracking branch 'origin/dev-cpp' into dev-v2011
kenorb Jan 25, 2022
afb673c
Should fix new issues with C++ compatibility.
nseam Jan 26, 2022
4355ade
Merge pull request #640 from nseam/dev-cpp
kenorb Jan 26, 2022
dc609ad
Merge branch 'dev-account' into dev-v2011
kenorb Jan 30, 2022
118347d
Merge tag 'v2.010' into dev-v2011
kenorb Mar 24, 2022
e61fe6c
CPP: Removes EnumToString
kenorb Mar 24, 2022
66f4342
Refactors IndicatorData class to be inherited by Indicator class
kenorb May 29, 2022
cb29a33
Splits IndicatorParams struct into IndicatorDataParams
kenorb Jun 19, 2022
2e47d5c
Indicator: Moves GetValuePrice() to IndicatorData
kenorb Jun 19, 2022
17373a5
Moves indicator data related methods to IndicatorData
kenorb Jun 26, 2022
b010f5d
Indicators: Adds Indicator source type and mode to constructor's argu…
kenorb Jun 26, 2022
b26dfa5
Fixes timeframe handling
kenorb Jun 27, 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
Prev Previous commit
Next Next commit
WIP. AMA now requires refactor back to be parent of Indicator or some…
…thing similar.
nseam committed Dec 11, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit f4c946d6c07bc7bf324a7a8690eac23019fa57e0
11 changes: 11 additions & 0 deletions Indicator/IndicatorCandle.h
Original file line number Diff line number Diff line change
@@ -92,9 +92,13 @@ class IndicatorCandle : public IndicatorBase {
CandleOCTOHLC<TV> _candle = icdata.GetByKey(_candle_time);

if (!_candle.IsValid()) {
#ifdef __debug__
Print(GetFullName(), ": Missing candle at shift ", _index, " (", TimeToString(_candle_time), ")");
#endif
} else {
#ifdef __debug__verbose_
Print(GetFullName(), ": Retrieving candle at shift ", _index, " (", TimeToString(_candle_time), ")");
#endif
}

return CandleToEntry(_candle_time, _candle);
@@ -169,8 +173,10 @@ class IndicatorCandle : public IndicatorBase {
void UpdateCandle(long _tick_timestamp, double _price) {
long _candle_timestamp = CalcCandleTimestamp(_tick_timestamp);

#ifdef __debug_verbose__
Print("Updating candle for ", GetFullName(), " at candle ", TimeToString(_candle_timestamp), " from tick at ",
TimeToString(_tick_timestamp));
#endif

CandleOCTOHLC<double> _candle(_price, _price, _price, _price, _tick_timestamp, _tick_timestamp);
if (icdata.KeyExists(_candle_timestamp)) {
@@ -307,6 +313,11 @@ class IndicatorCandle : public IndicatorBase {

return _result;
}

/**
* Get indicator type.
*/
ENUM_INDICATOR_TYPE GetType() override { return icparams.itype; }
};

#endif
7 changes: 7 additions & 0 deletions Indicator/tests/classes/IndicatorTickReal.h
Original file line number Diff line number Diff line change
@@ -50,13 +50,17 @@ class IndicatorTickReal : public IndicatorTick<IndicatorTickRealParams, double>

void OnBecomeDataSourceFor(IndicatorBase* _base_indi) override {
// Feeding base indicator with historic entries of this indicator.
#ifdef __debug__
Print(GetFullName(), " became a data source for ", _base_indi.GetFullName());
#endif

#ifndef __MQL4__
int _ticks_to_emit = 1000;

#ifdef __debug_verbose__
Print(_base_indi.GetFullName(), " will be now filled with ", _ticks_to_emit,
" historical entries generated by " + GetFullName());
#endif

static MqlTick _ticks[];
ArrayResize(_ticks, 0);
@@ -97,7 +101,10 @@ class IndicatorTickReal : public IndicatorTick<IndicatorTickRealParams, double>
// Copying only the last tick.
int _num_copied = CopyTicks(GetSymbol(), _ticks, COPY_TICKS_INFO, 0, 1);

#ifdef __debug_verbose__
Print("TickReal: ", TimeToString(_ticks[0].time), " = ", _ticks[0].bid);
#endif

double _ask = _ticks[0].ask;
double _bid = _ticks[0].bid;
long _time = _ticks[0].time;
29 changes: 28 additions & 1 deletion IndicatorBase.h
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ class IndicatorBase : public Chart {
int indi_src_mode; // Mode of source indicator
IndicatorCalculateCache<double> cache;
ARRAY(WeakRef<IndicatorBase>, listeners); // List of indicators that listens for events from this one.
long last_tick_time; // Time of the last Tick() call.

public:
/* Indicator enumerations */
@@ -94,6 +95,7 @@ class IndicatorBase : public Chart {
calc_start_bar = 0;
is_fed = false;
indi_src = NULL;
last_tick_time = 0;
}

/**
@@ -103,6 +105,7 @@ class IndicatorBase : public Chart {
calc_start_bar = 0;
is_fed = false;
indi_src = NULL;
last_tick_time = 0;
}

/**
@@ -351,7 +354,7 @@ class IndicatorBase : public Chart {
/**
* Get name of the indicator.
*/
virtual string GetName() { return "<Unknown>"; }
virtual string GetName() { return EnumToString(GetType()); }

/**
* Get full name of the indicator (with "over ..." part).
@@ -498,6 +501,30 @@ class IndicatorBase : public Chart {
return _result;
}

void Tick() {
long _current_time = TimeCurrent();

if (last_tick_time == _current_time) {
// We've already ticked.
return;
}

last_tick_time = _current_time;

// Overridable OnTick() method.
OnTick();

if (HasDataSource()) {
// Ticking data source if not yet ticked.s
GetDataSource().Tick();
}

// Also ticking all used indicators if they've not yet ticked.
for (DictStructIterator<int, Ref<IndicatorBase>> iter = indicators.Begin(); iter.IsValid(); ++iter) {
iter.Value().Ptr().Tick();
}
}

virtual void OnTick() {}

/* Data representation methods */
3 changes: 2 additions & 1 deletion Indicators/Indi_AMA.mqh
Original file line number Diff line number Diff line change
@@ -56,7 +56,8 @@ struct IndiAMAParams : IndicatorTfParams {
IndiAMAParams(IndiAMAParams &_params, ENUM_TIMEFRAMES _tf) {
THIS_REF = _params;
tf = _tf;
};
}
5;
};

/**
11 changes: 9 additions & 2 deletions tests/IndicatorsTest.mq5
Original file line number Diff line number Diff line change
@@ -78,14 +78,14 @@ int OnInit() {
}

/**
* Implements Tick event handler.
* Implements Tick event handler .
*/
void OnTick() {
chart.OnTick();

// All indicators should execute its OnTick() method for every platform tick.
for (DictStructIterator<long, Ref<IndicatorBase>> iter = indis.Begin(); iter.IsValid(); ++iter) {
iter.Value().Ptr().OnTick();
iter.Value().Ptr().Tick();
}

if (chart.IsNewBar()) {
@@ -109,6 +109,13 @@ void OnTick() {
IndicatorBase* _indi = iter.Value().Ptr();
_indi.OnTick();
IndicatorDataEntry _entry(_indi.GetEntry());

if (_indi.GetType() == INDI_AMA) {
PrintFormat("%s: bar %d: %s", _indi.GetFullName(), bar_processed, _indi.ToString());
} else {
continue;
}

if (_indi.Get<bool>(STRUCT_ENUM(IndicatorState, INDICATOR_STATE_PROP_IS_READY))) {
if (_entry.IsValid()) {
PrintFormat("%s: bar %d: %s", _indi.GetFullName(), bar_processed, _indi.ToString());