|
crfaldu
2017-02-05 12:54:52
|
|
Hello Sir,
I am writing a custom function which returns rate of change from first visible date on the chart but am having error in calculation. I would appreciate if you can point where my mistake is.
This is the srcipt which sets global variable of visible date
while(true)
{
Chart chart = Charts.GetSelectedChart();
DateTime startdate = chart.VisibleStartDate;
Global.SetVariable("Date",startdate);
App.Main.Sleep(1000);
chart.Update();
}
Function is below
VectorDate vDate = cFunctions.Date;
String temp = Global.GetVariable("Date").ToString();
//DateTime date = DateTime.Parse(temp);
DateTime date = DateTime.Parse(temp, System.Globalization.CultureInfo.InvariantCulture);
double tt = 0;
int i = 0;
for(i=0; i<result.Length; i++)
{
if(vDate[i] == date){
tt = a[i];
}
result[i] = 0;
}
for(i=0; i < result.Length; i++)
{
if(vDate[i] >= date){
result[i] = ((a[i] - tt)/a[i])*100;
}
}
cFunctions.SetForwardAndBackwardBars(0, 0);
I tested this on symbol GDXJ for with start date feb 1 2017 (close = 38.07) and end date feb 3 2017 (close = 39.26)
so the performance on feb 3 is 3.125 but
my function returns 3.03
I can't figure out why I am seeing this discrepancy
Thank you
|
|