-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAVWAP.cs
181 lines (157 loc) · 5.65 KB
/
AVWAP.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
175
176
177
178
179
180
181
#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
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class AVWAP : Indicator
{
private DateTime anchorDate;
double iCumVolume = 0;
double iCumTypicalVolume = 0;
double curVWAP = 0;
double deviation = 0;
double v2Sum = 0;
double hl3 = 0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Anchored Volume Weighted Average Price";
Name = "AVWAP";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AnchorYear = 2024;
AnchorMonth = 4;
AnchorDay = 1;
AnchorTime = DateTime.Parse("08:30", System.Globalization.CultureInfo.InvariantCulture);
AddPlot(new Stroke(Brushes.Purple, DashStyleHelper.Solid, 2), PlotStyle.Line, "PlotVWAP");
}
}
protected override void OnBarUpdate()
{
DateTime anchorDate = new DateTime(AnchorYear, AnchorMonth, AnchorDay, AnchorTime.Hour, AnchorTime.Minute, 0);
hl3 = ((High[0] + Low[0] + Close[0]) / 3);
if (Time[0] >= anchorDate) {
if (CurrentBar - Bars.GetBar(anchorDate) == 0)
{
iCumVolume = VOL()[0];
iCumTypicalVolume = VOL()[0] * hl3;
v2Sum = VOL()[0] * hl3 * hl3;
}
else
{
iCumVolume = iCumVolume + VOL()[0];
iCumTypicalVolume = iCumTypicalVolume + ( VOL()[0] * hl3 );
v2Sum = v2Sum + VOL()[0] * hl3 * hl3;
}
Value[0] = (iCumTypicalVolume / iCumVolume);
}
}
#region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="AnchorYear", Order=1, GroupName="Parameters")]
public int AnchorYear
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="AnchorMonth", Order=2, GroupName="Parameters")]
public int AnchorMonth
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="AnchorDay", Order=3, GroupName="Parameters")]
public int AnchorDay
{ get; set; }
[NinjaScriptProperty]
[PropertyEditor("NinjaTrader.Gui.Tools.TimeEditorKey")]
[Display(Name="AnchorTime", Order=4, GroupName="Parameters")]
public DateTime AnchorTime
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> AVWAPLine
{
get { return Values[0]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private AVWAP[] cacheAVWAP;
public AVWAP AVWAP(int anchorYear, int anchorMonth, int anchorDay, DateTime anchorTime)
{
return AVWAP(Input, anchorYear, anchorMonth, anchorDay, anchorTime);
}
public AVWAP AVWAP(ISeries<double> input, int anchorYear, int anchorMonth, int anchorDay, DateTime anchorTime)
{
if (cacheAVWAP != null)
for (int idx = 0; idx < cacheAVWAP.Length; idx++)
if (cacheAVWAP[idx] != null && cacheAVWAP[idx].AnchorYear == anchorYear && cacheAVWAP[idx].AnchorMonth == anchorMonth && cacheAVWAP[idx].AnchorDay == anchorDay && cacheAVWAP[idx].AnchorTime == anchorTime && cacheAVWAP[idx].EqualsInput(input))
return cacheAVWAP[idx];
return CacheIndicator<AVWAP>(new AVWAP(){ AnchorYear = anchorYear, AnchorMonth = anchorMonth, AnchorDay = anchorDay, AnchorTime = anchorTime }, input, ref cacheAVWAP);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.AVWAP AVWAP(int anchorYear, int anchorMonth, int anchorDay, DateTime anchorTime)
{
return indicator.AVWAP(Input, anchorYear, anchorMonth, anchorDay, anchorTime);
}
public Indicators.AVWAP AVWAP(ISeries<double> input , int anchorYear, int anchorMonth, int anchorDay, DateTime anchorTime)
{
return indicator.AVWAP(input, anchorYear, anchorMonth, anchorDay, anchorTime);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.AVWAP AVWAP(int anchorYear, int anchorMonth, int anchorDay, DateTime anchorTime)
{
return indicator.AVWAP(Input, anchorYear, anchorMonth, anchorDay, anchorTime);
}
public Indicators.AVWAP AVWAP(ISeries<double> input , int anchorYear, int anchorMonth, int anchorDay, DateTime anchorTime)
{
return indicator.AVWAP(input, anchorYear, anchorMonth, anchorDay, anchorTime);
}
}
}
#endregion