Click here to Login




Update Chart Layout based on Active Ticker Symbol

Updated on 2013-04-15





You probably do not trade stocks like your trade futures or Forex currencies. It is also unlikely that you use the same indicators and rules for all assets.

If you agree with that then you will find the following article very interesting. This post describes a script that is implemented in QuantShare. This script will run on background and it will automatically update the chart layout based on the active symbol and a predefined list of symbols/layouts.

If you are still wondering what I am talking about, here is an example:

Let us say that when displaying stock charts, you often want to display the RSI indicator and two moving averages on the main pane. This is our default pane.
When displaying Forex charts, you want to display the number of stock tweets per day as well the correlation with another currency.
Our script will automatically choose the right layout for you when you select an asset. If you choose a stock then the first layout (RSI + Moving averages) is displayed and when you choose a currency such as the EURUSD, the second layout (Tweets + Correlation) is displayed.


What is Layout?

A chart layout is a file that contains information about how to display a chart.
How many panes it contains? What are the different formulas of each pane? What is the template of each pane? What is the chart's period?...

How to create a new layout:
To save the current chart's layout, right click on the chart, select "Layout" then "Save Layout As".

How to set a new layout to a chart:
Right click on a chart, select "Layout" then select an existing layout from the list.

How to set a default layout:
Right click on a chart, select "Layout" then "Set current layout as default". This layout will be used for example when you open a new chart using "View -> New chart".


How to Install the Script

- To open the script editor, select "Tools" then "Script Editor".
- Click on "File" then "New" to create a new script
- Type the script name then click on "OK"
- Paste the script (Click here to get the complete script)
- Click on "Execute" to run the script

It is preferable to add the script to the bookmark panel. This allows you to run it quickly from the main window. Here is how to accomplish this:
- In the "Script Editor"
- Select "Settings" then "Add current script to bookmark panel"

You may also instruct QuantShare to run this script when QuantShare trading software starts by creating a task using the task manager (Tools -> Task Manager).


How the Script Works?

The script contains several functions, which will be described later.

First, it loops indefinitely. In the loop, it gets the active chart and check if there is a layout associated with the chart's symbol.
If it does not find any layout, it uses the default layout as specified in the variable "defaultLayout", which of course you can change anytime by updating the script.
If it finds a layout, it checks if the current chart has a different layout and updates that chart with the layout associated with the active symbol (The symbol selected for the active chart).

The different functions created by the script are:

AddSymbol(string symbol, string layout)

Associates a symbol with a specific layout.

AddSymbol(string[] symbols, string layout)

Associates a list of symbols with a specific layout. Instead of calling the first function several times, you can create a list of symbols and then associate all these symbols to a single layout.

AddSymbol(Symbol[] symbols, string layout)

Associates a list of symbols (represented by "Symbol" class) with a specific layout.

GetLayoutFromSymbol(string symbol)

Returns the layout that was associated with the provided symbol. Returns "NULL" if the symbol is not associated with any layout.

RegisterChart(long id, string layout)

Informs QuantShare that the chart with the specified ID is associated with the specific layout. This prevents the script from updating the chart if its layout is already the right one.

IsUpdate(long id, string layout)

Gets whether to update the chart or not (changing its layout).




Update Layout based on Watchlists

Did you know that you could associate a watchlist to a layout?

For example, let us say that you have a watchlist that displays stocks that have a PER (Price earnings ratio) higher than 15.
You can create a layout that displays historical PER data as well as other fundamental and instructs the watchlist to use that layout anytime you choose a symbol from that watchlist.

To associate a layout to a watchlist:
- Right click on the watchlist
- Select "Settings"
- Type the "Layout" name
- Click on "OK"


Second Part












9 comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1233 days ago

Profile Graphs
Posted 1338 days ago

QuantShare
Previous Posts

More Posts

Back







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.