6.5.1000.14
[Brief summary of the problem encounterd]
I am learning Ninja script and trying to use the update() method in a indicator. I have successfully compiled it but the application was clashed when I applied it to a chart.
[Discribe in steps how to reproduce this issue]
1. Create a daily chart.
2. Add the attached indicator to the chart.
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Dot, "trade"));
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Dot, "position"));
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = true;
PaintPriceMarkers = false;
HorizontalGridLines = false;
VerticalGridLines = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < 50 )
return;
if(FirstTickOfBar)
{
Plot0.Set(Plot0[1]);
Plot1.Set(0);
// Condition set 1
if (Plot0[0] <= 0 && Close[0] > EMA(50)[0]
&& CrossAbove(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
{
Plot0.Set(1);
Plot1.Set(1);
}
// Condition set 2
if (Plot0[0] >= 0 && Close[0] < EMA(50)[0]
&& CrossBelow(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
{
Plot0.Set(-1);
Plot1.Set(-1);
}
// Condition set 3
if (Plot0[0] == 1 && Close[0] > EMA(50)[0]
&& CrossBelow(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
{
Plot0.Set(0);
Plot1.Set(2);
}
// Condition set 4
if (Plot0[0] == -1 && Close[0] < EMA(50)[0]
&& CrossAbove(MACD(fast, slow, smooth).Avg, MACD(fast, slow, smooth), 1))
{
Plot0.Set(0);
Plot1.Set(-2);
}
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
}
else
{
Plot0.Set(Plot0[1]);
Plot1.Set(Plot1[1]);
}
Print(ToDay(Time[0]));Print(Plot0[0]);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get {
Update();
return Plot0; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot1
{
get {
Update();
return Plot1; }
}
[Description("Fast period for MACD")]
[Category("Parameters")]
public int Fast
{
get { return fast; }
set { fast = Math.Max(1, value); }
}
[Description("Slow period for MACD")]
[Category("Parameters")]
public int Slow
{
get { return slow; }
set { slow = Math.Max(1, value); }
}
[Description("Smoothing period for MACD")]
[Category("Parameters")]
public int Smooth
{
get { return smooth; }
set { smooth = Math.Max(1, value); }
}
#endregion

Comment