Click here to Login





                                                   Problem with performance calculation in custom function

  0

0
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



crfaldu
2017-02-05 14:58:19

  0

Found the problem !!

result[i] = ((a[i] - tt)/tt)*100; instead of

result[i] = ((a[i] - tt)/a[i])*100;



No more messages
0




Reply:

No html code. URLs turn into links automatically.

Type in the trading objects you want to include: - Add Objects
    To add a trading object in your message, type in the object name, select it and then click on "Add Objects"










    QuantShare

    Trading Items
    Advanced Quotes and Custom Databases Function
    Relative Performance Chart - Dynamic assets and index
    Average Stock Performance for each U.S Exchange
    Top 20 stocks with the highest 10 day rate of change - Current an...
    Choose function

    How-to Lessons
    How to improve the performance of QuantShare databases?
    How to plot the relative performance of several stocks/indices
    How to create a custom trendline
    How to screen for stocks having a high correlation with the Dow J...
    How to use a custom drawing tool

    Related Forum Threads
    Performance of parsing a QS language function in AMM
    Passing date variable from custom drawing tools to custom functio...
    Problem with "Save Trading System" in Optimizer
    Custom Drawing tool Trendline does not end with second click
    Custom Fitness Function

    Blog Posts
    Chart Layouts Explained - With Custom Scripts
    Custom Indicator: Accumulation Distribution Line
    Long Term Trading with Technical Analysis
    Trading System Analysis: Backtesting report and custom measures
    Custom Indicator: Relative Strength









    QuantShare
    Product
    QuantShare
    Features
    Create an account
    Affiliate Program
    Support
    Contact Us
    Trading Forum
    How-to Lessons
    Manual
    Company
    About Us
    Privacy
    Terms of Use

    Copyright © 2025 QuantShare.com
    Social Media
    Follow us on Facebook
    Twitter Follow us on Twitter
    Google+
    Follow us on Google+
    RSS Trading Items



    Trading financial instruments, including foreign exchange on margin, carries a high level of risk and is not suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to invest in financial instruments or foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with trading and seek advice from an independent financial advisor if you have any doubts.