-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathPaperArms.cs
More file actions
176 lines (154 loc) · 5.51 KB
/
PaperArms.cs
File metadata and controls
176 lines (154 loc) · 5.51 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
166
167
168
169
170
171
172
173
174
175
176
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
namespace NinjaTrader.NinjaScript.Indicators
{
public class PaperArms : Indicator
{
private bool colorRegion = true;
private int regionOpacity = 20;
private Brush regionUpColor = Brushes.Green;
private Brush regionDownColor = Brushes.Red;
private int StartIndex = 1;
private int PriorIndex = 0;
private Series<bool> upTrend = null;
private bool previousTrend = false;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"PaperArms.";
Name = "PaperArms";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
IsSuspendedWhileInactive = true;
ArePlotsConfigurable = false;
AddPlot(Brushes.Transparent, "MGD");
AddPlot(Brushes.Transparent, "FVMA");
upTrend = new Series<bool>(this);
}
else if (State == State.DataLoaded)
{
}
}
protected override void OnBarUpdate()
{
Values[0][0] = EMA(Close, 9)[0];
Values[1][0] = EMA(Close, 21)[0];
bool isUpTrend = Values[1][0] < Values[0][0];
bool isDownTrend = Values[1][0] > Values[0][0];
if (colorRegion && regionOpacity != 0)
{
if (IsFirstTickOfBar)
PriorIndex = StartIndex;
int CountBars = CurrentBar - PriorIndex + 1 - Displacement;
if (isUpTrend)
{
if (StartIndex == CurrentBar)
RemoveDrawObject("Region" + CurrentBar);
if (CountBars <= CurrentBar)
Draw.Region(this, "Region" + PriorIndex, CountBars, -Displacement, Values[1], Values[0], null, regionUpColor, regionOpacity);
}
else if (isDownTrend)
{
if (StartIndex == CurrentBar)
RemoveDrawObject("Region" + CurrentBar);
if (CountBars <= CurrentBar)
Draw.Region(this, "Region" + PriorIndex, CountBars, -Displacement, Values[1], Values[0], null, regionDownColor, regionOpacity);
}
StartIndex = CurrentBar;
}
if (isUpTrend)
upTrend[0] = true;
else if (isDownTrend)
upTrend[0] = false;
previousTrend = isUpTrend;
}
#region Properties
[NinjaScriptProperty]
[Display(Name = "Color Region", GroupName = "Options", Order = 4)]
public bool ColorRegion
{
get { return colorRegion; }
set { colorRegion = value; }
}
[NinjaScriptProperty]
[Display(Name = "Region Opacity", GroupName = "Options", Order = 7)]
public int RegionOpacity
{
get { return regionOpacity; }
set { regionOpacity = Math.Min(100, Math.Max(0, value)); }
}
[XmlIgnore()]
[NinjaScriptProperty]
[Display(Name = "RegionUpColor", GroupName = "Options", Order = 8)]
public Brush RegionUpColor
{
get { return regionUpColor; }
set { regionUpColor = value; }
}
[Browsable(false)]
public string RegionUpColorSerialize
{
get { return Serialize.BrushToString(regionUpColor); }
set { regionUpColor = Serialize.StringToBrush(value); }
}
[XmlIgnore()]
[NinjaScriptProperty]
[Display(Name = "RegionDownColor", GroupName = "Options", Order = 9)]
public Brush RegionDownColor
{
get { return regionDownColor; }
set { regionDownColor = value; }
}
[Browsable(false)]
public string RegionDownColorSerialize
{
get { return Serialize.BrushToString(regionDownColor); }
set { regionDownColor = Serialize.StringToBrush(value); }
}
[Browsable(false)]
[XmlIgnore()]
public Series<bool> UpTrend
{
get { return upTrend; }
}
[Browsable(false)]
public Series<double> MGD
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> FVMA
{
get { return Values[1]; }
}
#endregion
}
}