/
TrixMAOscillator.mqh
139 lines (123 loc) · 6.27 KB
/
TrixMAOscillator.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//+--------------------------------------------------------------------+
//| Copyright: (C) 2016 Forex Software Ltd. |
//| Website: http://forexsb.com/ |
//| Support: http://forexsb.com/forum/ |
//| License: Proprietary under the following circumstances: |
//| |
//| This code is a part of Forex Strategy Builder. It is free for |
//| use as an integral part of Forex Strategy Builder. |
//| One can modify it in order to improve the code or to fit it for |
//| personal use. This code or any part of it cannot be used in |
//| other applications without a permission. |
//| The contact information cannot be changed. |
//| |
//| NO LIABILITY FOR CONSEQUENTIAL DAMAGES |
//| |
//| In no event shall the author be liable for any damages whatsoever |
//| (including, without limitation, incidental, direct, indirect and |
//| consequential damages, damages for loss of business profits, |
//| business interruption, loss of business information, or other |
//| pecuniary loss) arising out of the use or inability to use this |
//| product, even if advised of the possibility of such damages. |
//+--------------------------------------------------------------------+
#property copyright "Copyright (C) 2016 Forex Software Ltd."
#property link "http://forexsb.com"
#property version "2.1"
#property strict
#include <Forexsb.com/Indicator.mqh>
#include <Forexsb.com/Enumerations.mqh>
#include <Forexsb.com/Indicators/TrixIndex.mqh>
//## Requires TrixIndex.mqh
class TrixMAOscillator : public Indicator
{
public:
TrixMAOscillator(SlotTypes slotType);
virtual void Calculate(DataSet &dataSet);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void TrixMAOscillator::TrixMAOscillator(SlotTypes slotType)
{
SlotType = slotType;
IndicatorName = "Trix MA Oscillator";
WarningMessage = "";
IsAllowLTF = true;
ExecTime = ExecutionTime_DuringTheBar;
IsSeparateChart = true;
IsDiscreteValues = false;
IsDefaultGroupAll = false;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void TrixMAOscillator::Calculate(DataSet &dataSet)
{
Data=GetPointer(dataSet);
MAMethod signalMAMethod=(MAMethod) ListParam[2].Index;
int period1 = (int) NumParam[0].Value;
int period2 = (int) NumParam[1].Value;
int previous=CheckParam[0].Checked ? 1 : 0;
int firstBar=MathMax(period1,period2)+previous+2;
double oscillator[]; ArrayResize(oscillator,Data.Bars); ArrayInitialize(oscillator,0);
// ----------------------------------------------------
TrixIndex *trixIndex=new TrixIndex(SlotType);
trixIndex.ListParam[1].Index = ListParam[1].Index;
trixIndex.ListParam[2].Index = ListParam[3].Index;
trixIndex.NumParam[0].Value=NumParam[0].Value;
trixIndex.CheckParam[0].Checked=CheckParam[0].Checked;
trixIndex.Calculate(dataSet);
double indicator1[];
ArrayResize(indicator1,Data.Bars);
ArrayCopy(indicator1,trixIndex.Component[0].Value);
delete trixIndex;
double indicator2[];
MovingAverage(period2,0,signalMAMethod,indicator1,indicator2);
// -----------------------------------------------------
for(int bar=firstBar; bar<Data.Bars; bar++)
{
oscillator[bar]=indicator1[bar]-indicator2[bar];
}
ArrayResize(Component[0].Value,Data.Bars);
Component[0].CompName = "Histogram";
Component[0].DataType = IndComponentType_IndicatorValue;
Component[0].FirstBar = firstBar;
ArrayCopy(Component[0].Value,oscillator);
ArrayResize(Component[1].Value,Data.Bars);
Component[1].FirstBar=firstBar;
ArrayResize(Component[2].Value,Data.Bars);
Component[2].FirstBar=firstBar;
if(SlotType==SlotTypes_OpenFilter)
{
Component[1].DataType = IndComponentType_AllowOpenLong;
Component[1].CompName = "Is long entry allowed";
Component[2].DataType = IndComponentType_AllowOpenShort;
Component[2].CompName = "Is short entry allowed";
}
else if(SlotType==SlotTypes_CloseFilter)
{
Component[1].DataType = IndComponentType_ForceCloseLong;
Component[1].CompName = "Close out long position";
Component[2].DataType = IndComponentType_ForceCloseShort;
Component[2].CompName = "Close out short position";
}
IndicatorLogic indLogic=IndicatorLogic_It_does_not_act_as_a_filter;
if(ListParam[0].Text=="Trix MA Oscillator rises")
indLogic=IndicatorLogic_The_indicator_rises;
else if(ListParam[0].Text=="Trix MA Oscillator falls")
indLogic=IndicatorLogic_The_indicator_falls;
else if(ListParam[0].Text=="Trix MA Oscillator is higher than the zero line")
indLogic=IndicatorLogic_The_indicator_is_higher_than_the_level_line;
else if(ListParam[0].Text=="Trix MA Oscillator is lower than the zero line")
indLogic=IndicatorLogic_The_indicator_is_lower_than_the_level_line;
else if(ListParam[0].Text=="Trix MA Oscillator crosses the zero line upward")
indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_upward;
else if(ListParam[0].Text=="Trix MA Oscillator crosses the zero line downward")
indLogic=IndicatorLogic_The_indicator_crosses_the_level_line_downward;
else if(ListParam[0].Text=="Trix MA Oscillator changes its direction upward")
indLogic=IndicatorLogic_The_indicator_changes_its_direction_upward;
else if(ListParam[0].Text=="Trix MA Oscillator changes its direction downward")
indLogic=IndicatorLogic_The_indicator_changes_its_direction_downward;
OscillatorLogic(firstBar,previous,oscillator,0,0,Component[1],Component[2],indLogic);
}
//+------------------------------------------------------------------+