forked from PopovMP/FSB_Pro_Indicators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NBarsExit.cs
98 lines (83 loc) · 3.48 KB
/
NBarsExit.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
//==============================================================
// 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.Globalization;
using ForexStrategyBuilder.Infrastructure.Entities;
using ForexStrategyBuilder.Infrastructure.Enums;
using ForexStrategyBuilder.Infrastructure.Interfaces;
namespace ForexStrategyBuilder.Indicators.Store
{
public class NBarsExit : Indicator
{
public NBarsExit()
{
IndicatorName = "N Bars Exit";
PossibleSlots = SlotTypes.CloseFilter;
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[]
{
"Exit N Bars after entry"
};
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.";
// The NumericUpDown parameters
IndParam.NumParam[0].Caption = "N Bars";
IndParam.NumParam[0].Value = 10;
IndParam.NumParam[0].Min = 1;
IndParam.NumParam[0].Max = 10000;
IndParam.NumParam[0].Enabled = true;
IndParam.NumParam[0].ToolTip = "The number of bars after entry to exit the position.";
}
public override void Calculate(IDataSet dataSet)
{
DataSet = dataSet;
if (!IsBacktester)
{
// FST sends the N bars for exit to the expert. Expert watches the position and closes it.
return;
}
var nExit = (int) IndParam.NumParam[0].Value;
// Saving the components
Component = new IndicatorComp[1];
Component[0] = new IndicatorComp
{
CompName = "N Bars Exit (" + nExit.ToString(CultureInfo.InvariantCulture) + ")",
DataType = IndComponentType.ForceClose,
ChartType = IndChartType.NoChart,
ShowInDynInfo = true,
FirstBar = 1,
Value = new double[Bars]
};
}
public override void SetDescription()
{
var nExit = (int) IndParam.NumParam[0].Value;
ExitFilterLongDescription = nExit + " bars passed after the entry";
ExitFilterShortDescription = nExit + " bars passed after the entry";
}
public override string ToString()
{
return IndicatorName + " (" +
IndParam.NumParam[0].ValueToString + ")"; // Number of Bars
}
}
}