An error message about ChartPoint  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Morgan
Posts: 17
Joined: 29 Oct 2014
Has thanked: 1 time
Been thanked: 1 time

An error message about ChartPoint

Postby Morgan » 02 Dec 2014

Hello, I've an indicators could work successfully on other computers but displays an error message
on my computer as attached image.

It seems to happen when new a ChartPoint object.
My environment is Win7 32bit
I've tried MC.NET 8.8 & 9.0 release, all the same.
Do anyone know where is the problem?

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
public class Test2 : IndicatorObject
{
[Input]
public int WPRSIperiod { get; set; }

[Input]
public int Waytoway { get; set; }

[Input]
public int filterUP { get; set; }

[Input]
public int filterDN { get; set; }

[Input]
public bool UseSound { get; set; }

[Input]
public string SoundFile { get; set; }

private RSI m_RSI;

//Morgan
private VariableObject<IArrowObject> m_arrw;

public Test2(object _ctx)
: base(_ctx)
{
WPRSIperiod = 27;
Waytoway = 27;
filterUP = 10;
filterDN = 10;
UseSound = false;
SoundFile = "Alert.wav";
}

private int iLowest(ISeries<double> series, int count, int start)
{
int index = start;
for (int i = 1; i < count; i++)
{
if (series[start + i] < series[index])
index = start + i;
}
return index;
}

private int iHighest(ISeries<double> series, int count, int start)
{
int index = start;
for (int i = 1; i < count; i++)
{
if (series[start + i] > series[index])
index = start + i;
}
return index;
}

private double iWPR(int count, int start)
{
return (Bars.High[iHighest(Bars.High, count, start)] - Bars.Close[start]) / (Bars.High[iHighest(Bars.High, count, start)] - Bars.Low[iLowest(Bars.Low, count, start)]) * -100;
}

private double iRSI(int count, int start)
{
double A = 0, B = 0, RSI;
for (int i = start; i < start + count; i++)
{
double mid_i = (Bars.High[i] + Bars.Low[i]) / 2;
double mid_i2 = (Bars.High[i + 1] + Bars.Low[i + 1]) / 2;

if (mid_i > mid_i2)
A += mid_i - mid_i2;
else
B += mid_i2 - mid_i;
}
RSI = 100.0 - (100.0 / (1.0 + A / B));
//RSI = 100 * A / (A + B);
return RSI;
}

private double logic(double cinyan)
{
return ((Math.Exp(cinyan) - Math.Exp(-cinyan)) / (Math.Exp(cinyan) + Math.Exp(-cinyan)));
}

private double ff_upsum(int i)
{
double ret = 0;
for (int up1 = 0; up1 <= Waytoway; up1++)
{
ret = (Bars.Close[i + up1] - Bars.Open[i + up1]) / (Bars.High[i + up1] - Bars.Low[i + up1]) + ret;
}
return ret;
}

private IPlotObject[] plot;
protected override void Create()
{
// create variable objects, function objects, plot objects etc.
plot = new IPlotObject[3];
plot[0] = AddPlot(new PlotAttributes("", EPlotShapes.Histogram, Color.Gray));
plot[1] = AddPlot(new PlotAttributes("", EPlotShapes.Histogram, Color.Blue));
plot[2] = AddPlot(new PlotAttributes("", EPlotShapes.Histogram, Color.Red));

//Morgan
m_arrw = new VariableObject<IArrowObject>(this);
}
protected override void StartCalc()
{
// assign inputs
}

long alert = 0;

int Limit = 300;//不清楚为何大了以后一直在计算中
protected override void CalcBar()
{
// indicator logic
if (Bars.LastBarOnChart)
{
//----
if (Limit > Bars.FullSymbolData.Count - WPRSIperiod)
Limit = Bars.FullSymbolData.Count - WPRSIperiod;

//Output.Clear();
//Output.WriteLine("from {0} to {1},Limit:{2}", 1, Bars.FullSymbolData.Count, Limit);
for (int i = 1; i <= Limit; i++)
{
//Output.WriteLine("i={0}", i);
//---
double upsum = ff_upsum(i);
//iWPR - Larry Williams' Percent Range(0~-100)
//iRSI - Relative Strength Index indicator
double WPR = iWPR(WPRSIperiod, i);
double RSI = iRSI(WPRSIperiod, i);
//Output.WriteLine("WPR:{0},RSI:{1}", WPR, RSI);

if (((WPR > -50) && (RSI < 50)) || ((WPR < -50) && (RSI > 50)))
{
plot[0].Set(i, logic(upsum));
}
//----
if ((WPR > -50) && (RSI > 50))
{
plot[1].Set(i, logic(upsum));
}
//----
if (WPR > -20 && iWPR(WPRSIperiod, i + 1) < -20 && RSI > 50)
{
double z = 0;
for (int k = 2; k <= filterUP + 2; k++)
{
if (iWPR(WPRSIperiod, k + i) > -20) { z = 1; }
}
if (z == 0)
{
//Output.WriteLine("Arrow Up:{0},{1}", Bars.Time[i], logic(upsum));
//Morgan
m_arrw.Value =DrwArrow.Create(new ChartPoint(Bars.Time[i], logic(upsum)), false, true);
//.Locked = true;

if (i == 1 && (alert != Bars.Time[1].Ticks))
{
if (UseSound)
{
new System.Media.SoundPlayer(SoundFile).Play();
Alerts.Alert("Start Long");
}
}
alert = Bars.Time[1].Ticks;
}
}
//----
if (WPR < -50 && RSI < 50)
{
plot[2].Set(i, logic(upsum));
}
//----
if (iWPR(WPRSIperiod, i + 1) > -80 && WPR < -80 && RSI < 50)
{
double h = 0;
for (int c = 2; c <= filterDN + 2; c++)
{
if (iWPR(WPRSIperiod, c + i) < -80) { h = 1; }
}
if (h == 0)
{
//Output.WriteLine("Arrow Down:{0},{1}", Bars.Time[i], logic(upsum));
//Morgan
m_arrw.Value =DrwArrow.Create(new ChartPoint(Bars.TimeValue, logic(upsum)), true);
//.Locked = true;

if (i == 1 && (alert != Bars.Time[1].Ticks))
{
if (UseSound)
{
new System.Media.SoundPlayer(SoundFile).Play();
Alerts.Alert("Start Short");
}
}
//alert = Bars.Time[1].Ticks;
}
}
}
}
}
}
}
Attachments
error2.JPG
(39.71 KiB) Downloaded 393 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: An error message about ChartPoint  [SOLVED]

Postby Henry MultiСharts » 02 Dec 2014

Hello Morgan,

This issue has been already resolved in the new builds of MultiCharts .NET 9.0 Release.
Please update to builds 10361/10362 to get the fix.


Return to “MultiCharts .NET”