forked from EA31337/EA31337-classes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndi_Demo.mqh
83 lines (76 loc) · 2.75 KB
/
Indi_Demo.mqh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//+------------------------------------------------------------------+
//| EA31337 framework |
//| Copyright 2016-2023, EA31337 Ltd |
//| https://github.com/EA31337 |
//+------------------------------------------------------------------+
/*
* 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/>.
*
*/
// Includes.
#include "../BufferStruct.mqh"
#include "../Indicator/IndicatorTickOrCandleSource.h"
#include "Price/Indi_Price.mqh"
/**
* @file
* Demo indicator for testing purposes.
*/
// Structs.
struct IndiDemoParams : IndicatorParams {
// Struct constructors.
IndiDemoParams(int _shift = 0) : IndicatorParams(INDI_DEMO) {
SetShift(_shift);
if (custom_indi_name == "") {
SetCustomIndicatorName("Examples\\Demo");
}
};
IndiDemoParams(IndiDemoParams &_params, ENUM_TIMEFRAMES _tf) {
THIS_REF = _params;
tf = _tf;
};
};
/**
* Demo/Dummy Indicator.
*/
class Indi_Demo : public IndicatorTickOrCandleSource<IndiDemoParams> {
public:
/**
* Class constructor.
*/
Indi_Demo(IndiDemoParams &_p, ENUM_IDATA_SOURCE_TYPE _idstype = IDATA_BUILTIN, IndicatorData *_indi_src = NULL,
int _indi_src_mode = 0)
: IndicatorTickOrCandleSource(
_p, IndicatorDataParams::GetInstance(1, TYPE_DOUBLE, _idstype, IDATA_RANGE_MIXED, _indi_src_mode),
_indi_src){};
Indi_Demo(ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0)
: IndicatorTickOrCandleSource(INDI_DEMO, _tf, _shift){};
/**
* Returns the indicator value.
*/
static double iDemo(string _symbol = NULL, ENUM_TIMEFRAMES _tf = PERIOD_CURRENT, int _shift = 0,
IndicatorData *_obj = NULL) {
return 0.1 + (0.1 * _obj.GetBarIndex());
}
/**
* Returns the indicator's value.
*/
virtual IndicatorDataEntryValue GetEntryValue(int _mode = 0, int _shift = 0) {
int _ishift = _shift >= 0 ? _shift : iparams.GetShift();
double _value = Indi_Demo::iDemo(GetSymbol(), GetTf(), _ishift, THIS_PTR);
if (iparams.is_draw) {
draw.DrawLineTo(GetName(), GetBarTime(_ishift), _value);
}
return _value;
}
};