Click here to Login




Update Chart Layout based on Active Ticker Symbol - Part 2

Updated on 2013-04-24





In the previous post, we created a script that runs on the background. The script function was to change the chart's layout depending on the active symbol.

You can show different indicators depending on whether you are displaying on the chart a stock, a future, a small cap...

Let us go further with this script and add the ability to associate a list of symbols to a specific layout. You will no longer have to type symbols one by one to associate them to a specific layout. You will be able to create a list of symbols and with one line of code associate all the symbols in this list to a specific layout.


Symbols List

First, let us show you what is the list of symbols we are referring to.
Select "Symbol" then "Symbols View" to open a control that displays list of symbols (Also called Symbols Filter). Each list is based on one or several conditions. The securities that meet these conditions are included in the list.
Example:
- Securities whose ticker name starts with "A"
- Stocks that belong to a specific industry
- Stocks that are part of the S&P 500 Index
- Securities that increased by more than 1% in the previous day

To create a new list of symbols, right click on the control then select "Create a new symbols filter".

Associate a list to a layout

Now that you have created one or several lists, let me show you how to use these lists and associate them with a particular layout, so that each time you select one of the securities that belong to a list, its corresponding layout is automatically reflected on the chart.

- Select "Tools -> Script Editor"
- Click on "File -> New" then enter a new name for our script
- Paste the script code (download it here)
- Click on "Execute" to run the script (Here is how to add the script to the bookmark panel: Click here)

Compared to the previous script we have uploaded few weeks ago, the current one has one additional method, which is:

AddSymbol(string listName, string listCategory, string layout)

The function takes the category and name of a symbols list, retrieves all symbols in the list then associates each one of them to the layout you specified in the same function.

Example of usage:

At the beginning of the script, you can type the following line to associate stocks from "Gold List" to a layout named "gold".

AddSymbol("Gold List", "", "gold");




How to keep the same time frame when changing layout

Besides all the visual settings, a layout also stores important data such as the ticker symbol, the number of bars to display and the chart's period. This means that each time you change a layout; the chart will be updated with the new layout's period. If you are using an EOD chart and the layout you are going to load was saved under a one-minute chart then the new chart will show one-minute data too.

Many traders wouldn't want the period or time frame to change when switching layouts. This can be accomplished by following these steps:

In the formula script, there are two calls to the following function:
"App.Main.UpdateChartLayout"

- Before each call, type the following lines:

int currentTimeframe = chart.TimeFrame;
bool isHistorical = chart.IsHistorical;


[This is to save the current time frame]


- After each call, type the following lines:

chart.TimeFrame = currentTimeframe;
chart.IsHistorical = isHistorical;


[This is to restore the old time frame and update the chart]

You can find the complete code here.












2 comments (Log in)

QuantShare Blog
QuantShare
Search Posts




QuantShare
Recent Posts

Create Graphs using the Grid Tool
Posted 1262 days ago

Profile Graphs
Posted 1367 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.