forked from PopovMP/FSB_Pro_Indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPriceMove.cs
More file actions
165 lines (141 loc) · 6.64 KB
/
PriceMove.cs
File metadata and controls
165 lines (141 loc) · 6.64 KB
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
//==============================================================
// 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 ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class PriceMove : Indicator
{
public PriceMove()
{
IndicatorName = "Price Move";
PossibleSlots = SlotTypes.Open;
IndicatorAuthor = "Miroslav Popov";
IndicatorVersion = "2.0";
IndicatorDescription = "Bundled in FSB distribution.";
}
public override void Initialize(SlotTypes slotType)
{
SlotType = slotType;
// Setting up the indicator parameters
IndParam.IndicatorType = TypeOfIndicator.Additional;
IndParam.IsAllowLTF = false;
// The ComboBox parameters
IndParam.ListParam[0].Caption = "Logic";
IndParam.ListParam[0].ItemList = new[]
{
"Enter long after an upward move",
"Enter long after a downward move"
};
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.";
IndParam.ListParam[1].Caption = "Base price";
IndParam.ListParam[1].ItemList = Enum.GetNames(typeof (BasePrice));
IndParam.ListParam[1].Index = (int) BasePrice.Open;
IndParam.ListParam[1].Text = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index];
IndParam.ListParam[1].Enabled = true;
IndParam.ListParam[1].ToolTip = "The price where the move starts from.";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "Price move";
IndParam.NumParam[0].Value = 20;
IndParam.NumParam[0].Min = 0;
IndParam.NumParam[0].Max = 2000;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The price move in points.";
// The CheckBox parameters
IndParam.CheckParam[0].Caption = "Use previous bar value";
IndParam.CheckParam[0].Checked = false;
IndParam.CheckParam[0].Enabled = true;
IndParam.CheckParam[0].ToolTip = "Use the indicator value from the previous bar.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
// Reading the parameters
var price = (BasePrice) IndParam.ListParam[1].Index;
double margin = IndParam.NumParam[0].Value*Point;
int prvs = IndParam.CheckParam[0].Checked ? 1 : 0;
// TimeExecution
if (price == BasePrice.Open && Math.Abs(margin - 0) < Epsilon)
IndParam.ExecutionTime = ExecutionTime.AtBarOpening;
else if (price == BasePrice.Close && Math.Abs(margin - 0) < Epsilon)
IndParam.ExecutionTime = ExecutionTime.AtBarClosing;
// Calculation
double[] adBasePr = Price(price);
var adUpBand = new double[Bars];
var adDnBand = new double[Bars];
int firstBar = 1 + prvs;
for (int iBar = firstBar; iBar < Bars; iBar++)
{
adUpBand[iBar] = adBasePr[iBar - prvs] + margin;
adDnBand[iBar] = adBasePr[iBar - prvs] - margin;
}
// Saving the components
Component = new IndicatorComp[2];
Component[0] = new IndicatorComp
{
CompName = "Up Price",
ChartType = IndChartType.NoChart,
FirstBar = firstBar,
Value = adUpBand
};
Component[1] = new IndicatorComp
{
CompName = "Down Price",
ChartType = IndChartType.NoChart,
FirstBar = firstBar,
Value = adDnBand
};
switch (IndParam.ListParam[0].Text)
{
case "Enter long after an upward move":
Component[0].DataType = IndComponentType.OpenLongPrice;
Component[1].DataType = IndComponentType.OpenShortPrice;
break;
case "Enter long after a downward move":
Component[0].DataType = IndComponentType.OpenShortPrice;
Component[1].DataType = IndComponentType.OpenLongPrice;
break;
}
}
public override void SetDescription()
{
var iMargin = (int) IndParam.NumParam[0].Value;
string sBasePrice = IndParam.ListParam[1].ItemList[IndParam.ListParam[1].Index].ToLower();
string sPrevious = (IndParam.CheckParam[0].Checked ? " previous" : "");
switch (IndParam.ListParam[0].Text)
{
case "Enter long after an upward move":
EntryPointLongDescription = iMargin + " points above the" + sPrevious + " bar " + sBasePrice +
" price";
EntryPointShortDescription = iMargin + " points below the" + sPrevious + " bar " + sBasePrice +
" price";
break;
case "Enter long after a downward move":
EntryPointLongDescription = iMargin + " points below the" + sPrevious + " bar " + sBasePrice +
" price";
EntryPointShortDescription = iMargin + " points above the" + sPrevious + " bar " + sBasePrice +
" price";
break;
}
}
public override string ToString()
{
return IndicatorName +
(IndParam.CheckParam[0].Checked ? "* (" : " (") +
IndParam.ListParam[1].Text + ", " + // Base Price
IndParam.NumParam[0].ValueToString + ")"; // Margin in points
}
}
}