/
RossHook.cs
174 lines (155 loc) · 6.36 KB
/
RossHook.cs
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//==============================================================
// Forex Strategy Builder
// Copyright © Miroslav Popov. All rights reserved.
//==============================================================
// THIS CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE.
//==============================================================
using System;
using System.Drawing;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class RossHook : Indicator
{
public RossHook()
{
IndicatorName = "Ross Hook";
PossibleSlots = SlotTypes.Open | SlotTypes.Close;
IndicatorAuthor = "Miroslav Popov";
IndicatorVersion = "2.1";
IndicatorDescription = "Bundled in FSB distribution.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
if (SlotType == SlotTypes.Open)
IndParam.ListParam[0].ItemList = new[]
{
"Enter long at Up Ross hook",
"Enter long at Down Ross hook"
};
else if (SlotType == SlotTypes.Close)
IndParam.ListParam[0].ItemList = new[]
{
"Exit long at Up Ross hook",
"Exit long at Down Ross hook"
};
else
IndParam.ListParam[0].ItemList = new[]
{
"Not Defined"
};
IndParam.ListParam[0].Index = 0;
IndParam.ListParam[0].Text = IndParam.ListParam[0].ItemList[IndParam.ListParam[0].Index];
IndParam.ListParam[0].Enabled = true;
IndParam.ListParam[0].ToolTip = "Logic of application of the indicator.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
var upHook = new double[Bars];
var downHook = new double[Bars];
for (int bar = 5; bar < Bars - 1; bar++)
{
if (High[bar] < High[bar - 1])
{
if (High[bar - 3] < High[bar - 1] && High[bar - 2] < High[bar - 1])
upHook[bar + 1] = High[bar - 1];
}
if (Low[bar] > Low[bar - 1])
{
if (Low[bar - 3] > Low[bar - 1] && Low[bar - 2] > Low[bar - 1])
downHook[bar + 1] = Low[bar - 1];
}
}
// Is visible
for (int bar = 5; bar < Bars; bar++)
{
if (upHook[bar - 1] > 0 && Math.Abs(upHook[bar] - 0) < Epsilon && High[bar - 1] < upHook[bar - 1])
upHook[bar] = upHook[bar - 1];
if (downHook[bar - 1] > 0 && Math.Abs(downHook[bar] - 0) < Epsilon && Low[bar - 1] > downHook[bar - 1])
downHook[bar] = downHook[bar - 1];
}
// Saving the components
Component = new IndicatorComp[2];
Component[0] = new IndicatorComp
{
ChartType = IndChartType.Level,
ChartColor = Color.SpringGreen,
FirstBar = 5,
Value = upHook
};
Component[1] = new IndicatorComp
{
ChartType = IndChartType.Level,
ChartColor = Color.DarkRed,
FirstBar = 5,
Value = downHook
};
// Sets the Component's type
if (SlotType == SlotTypes.Open)
{
if (IndParam.ListParam[0].Text == "Enter long at Up Ross hook")
{
Component[0].DataType = IndComponentType.OpenLongPrice;
Component[1].DataType = IndComponentType.OpenShortPrice;
}
else
{
Component[0].DataType = IndComponentType.OpenShortPrice;
Component[1].DataType = IndComponentType.OpenLongPrice;
}
Component[0].CompName = "Up Ross hook";
Component[1].CompName = "Down Ross hook";
}
else if (SlotType == SlotTypes.Close)
{
if (IndParam.ListParam[0].Text == "Exit long at Up Ross hook")
{
Component[0].DataType = IndComponentType.CloseLongPrice;
Component[1].DataType = IndComponentType.CloseShortPrice;
}
else
{
Component[0].DataType = IndComponentType.CloseShortPrice;
Component[1].DataType = IndComponentType.CloseLongPrice;
}
Component[0].CompName = "Up Ross hook";
Component[1].CompName = "Down Ross hook";
}
}
public override void SetDescription()
{
switch (IndParam.ListParam[0].Text)
{
case "Enter long at Up Ross hook":
EntryPointLongDescription = "at the peak of a Up Ross hook";
EntryPointShortDescription = "at the bottom of a Down Ross hook";
break;
case "Enter long at Down Ross hook":
EntryPointLongDescription = "at the bottom of a Down Ross hook";
EntryPointShortDescription = "at the peak of a Up Ross hook";
break;
case "Exit long at Up Ross hook":
ExitPointLongDescription = "at the peak of a Up Ross hook";
ExitPointShortDescription = "at the bottom of a Down Ross hook";
break;
case "Exit long at Down Ross hook":
ExitPointLongDescription = "at the bottom of a Down Ross hook";
ExitPointShortDescription = "at the peak of a Up Ross hook";
break;
}
}
public override string ToString()
{
return IndicatorName;
}
}
}