I would like to update the reference/index date for this formula dynamically each time the chart scroll bar is moved, so that index date corresponds to first visible on the chart:
a = CompareAssets("ILF;EPP;SHY", "01/06/2003");
Currently have a script that does this based on "selected chart changed", but it crashes frequently.
Chart chart = Charts.GetSelectedChart();
DateTime startdate = chart.VisibleStartDate;
Global.SetVariable("Date",startdate);
int curbar = chart.ScrollBarIndex;
Global.SetVariable("Bars",curbar);
chart.Update();
Is there a function/property to catch the first visible bar/date within a chart? like a = CompareAssets("ILF;EPP;SHY", Chart.VisibleStartDate());
You cannot do that within the function. The script is the best solution. What is exactly the code you are using? It is crashing probably because it is running too many times within a very short period.
Function sniplet which catches global vars:
string Assets = Global.GetVariable("Symbols").ToString();
string[] assets = Assets.Split(';');
string Date = Global.GetVariable("Date").ToString();
int curbar = (int) Global.GetVariable("Bars");
Works perfectly, thanks! Will upload chart setting if of use to others.
One f/up question: In the following I extract the assets to get timeseries, but how can I get fullname and other symbol data?
string Assets = Global.GetVariable("Symbols").ToString();
string[] assets = Assets.Split(';');
VectorD closes = cFunctions.GetTimeframeData(assets[1], (int)cFunctions.Timeframe, "close").ToVectorD();
something like cFunctions.SymbolInfo(assets[1]).FullName.. but SymbolInfo does not have parameter.
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.