Click here to Login





                                                   Function/property to catch the first visible bar/date within a chart

  0

0
Alexander Horn
2014-06-04 19:23:58


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());



QuantShare
2014-06-05 08:01:38

  0

Hi Alexander,

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.



Alexander Horn
2014-06-05 08:14:01

  0

Here the script, which triggers on "selected chart changed". Indeed it crashes when I change too quick, but can live with it. Thanks anyway, Alex

Script:
string[] assets = new String[20];
assets = Watchlist.GetSymbols("TAA_Basic_Selection_Static");
string Assets = "";

for(int j=0;j<assets.Length;j++)
{
Assets = Assets + ";" + assets[j].ToString();
}
Global.SetVariable("Symbols",Assets);

Chart chart = Charts.GetSelectedChart();
DateTime startdate = chart.VisibleStartDate;
Global.SetVariable("Date",startdate);
int curbar = chart.ScrollBarIndex;
Global.SetVariable("Bars",curbar);
chart.Update();

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");



QuantShare
2014-06-05 08:50:11

  0

Alex, please try this script.

string id = "";
while(true)
{
Chart chart = Charts.GetSelectedChart();
DateTime startdate = chart.VisibleStartDate;
string newID = chart.SymbolName + " - " + startdate.ToString();
if(id != newID)
{
string[] assets = new String[20];
assets = Watchlist.GetSymbols("TAA_Basic_Selection_Static");
string Assets = "";

for(int j=0;j<assets.Length;j++)
{
Assets = Assets + ";" + assets[j].ToString();
}
Global.SetVariable("Symbols",Assets);

Global.SetVariable("Date",startdate);
int curbar = chart.ScrollBarIndex;
Global.SetVariable("Bars",curbar);
chart.Update();
}
App.Main.Sleep(500);
}




Alexander Horn
2014-06-05 20:07:15

  0

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.







QuantShare
2014-06-06 07:52:25

  0

Best Answer
Hi Alex,

There is an undocumented way to get this:

Symbols symbols = new Symbols();
Symbol symbol = symbols.GetSymbol("A");
Global.Trace2(symbol.FullName);





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
Set the First Trading Bar Values to Not a Number
Number of Times an Event Occurred in the First N-Minutes of a Tra...
Time-series Sum for the first Minutes/Hours of a Trading Day
Trading Indicator: True between the first and last signal
Relative Performance/Return Chart - Compare Several Assets/Stocks...

How-to Lessons
How to display two stocks on the same chart
How to plot a stock using different periods in the same chart
How to plot a time-series that do not update the chart scale
How to display the bar index of a stock on a chart
How to scale and move the chart Y-axis

Related Forum Threads
Visible Date of first and last bar on chart
How do I reduce a position size from within the Money Management
Locks up when market is open while using the *daily* chart with I...
Horizontal line on the intraday chart with the day's opening pric...
Multiple symbols on the same chart

Blog Posts
Detect chart patterns using the auto support/resistance indicator
Backtesting chart patterns using the auto support and resistance ...
How to Calculate and Display the Bid/Ask Spread on a Chart
Custom Shortcuts - Move a Chart to Display the Last Quotes/Data
How to Use the Percentage Scale









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 © 2024 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.