This is a trading item or a component that was created using QuantShare by one of our members.
This item can be downloaded and used by QuantShare Trading Software.
Trading items are of different types. There are data downloaders, trading indicators, trading systems, watchlists, composites/indices...
You can use this item and hundreds of others for free by downloading QuantShare.
Top Reasons Why You Should Use QuantShare:
Works with US and international markets (stock, forex, options, futures, ETF...)
Offers you the tools that will help you become a profitable trader
Allows you to implement any trading ideas
Exchange items and ideas with other QuantShare users
Our support team is very responsive and will answer any of your questions
We will implement any features you suggest
Very low price and much more features than the majority of other trading software
By default, users are unable to take advantage of global variables inside of charts and other features. This function reads the specified global variable and returns its value as a string (not a number). If the global variable does not exist, this function will return a blank string.
By itself, GetVariable is unlikely to be very useful. When combined with other features such as Scripts and Keyboard Shortcuts, this function can provide unlimited possibilities which may be of interest to advanced users.
If you need to work with numbers instead of strings, you might download ToNumeric which performs that conversion. If you've downloaded ToNumeric, be aware that if a variable is a string or if a variable does not exist, ToNumeric will represent both of these conditions with the number zero.
a=GetVariable("NumberOfUnits"); // Returns a string
a=ToNumeric(GetVariable("NumberOfUnits")); // Returns a number (requires ToNumeric)
Figured out a good use for GetVariable? Do you use it to casually toggle your SMA plots between 20, 50, and 200 day periods? Or perhaps you compare the current symbol against a pre-defined list of symbols that you advance one at a time? Add a review below (with some code too, if you're willing) and let others know how you've put this to use!
=============================================================
EXAMPLE USE: SUMMON AND DISMISS AN INFOBOX OFF/ON WITH A KEYPRESS
=============================================================
The instructions below will show you how to create an infobox in the lower-left hander corner of an existing chart that contains the full name, industry, sector, and market associated with your currently active symbol. Using this function, the infobox can shown or hidden at any time by holding down [SHIFT] and [CONTROL] and tapping the letter [I].
======================================
FIRST: Add the following lines to your chart's formula:
======================================
ShowSymbolInfo=StringEqual(GetVariable("ShowSymbolInfo"),"1"); // 1=Show, 0=Hide
newline=" / "; // For a vertical infobox, make this string equal two characters: a BACKSLASH and a LOWERCASE N
text=FullName().newline.Industry().newline.Sector().newline.Market();
PrintChart(text, "", BottomLeft, colorBlack, colorwhiteSmoke, colorwhitesmoke, 255*ShowSymbolInfo, 1);
The first line retreives the value of a global variable called ShowSymbolInfo. If the variable exists and its value is equal to "1" (a string, not a number), then the numeric variable ShowSymbolInfoVal will equal the number 1. Otherwise, ShowSymbolInfoVal will equal the number 0.
The second line determine how we separate our fields. If you'd like each piece of information to be on its own line, follow the instructions in the comments. (This is preferred, but the QuantShare website does not allow us to directly share that character sequence, so it must be described.)
The third line establishes the text we're going to display inside of the infobox.
The fourth line displays the box and its contents. The seventh parameter contains the "alpha" or the transparency of the box. With an alpha of 255, the box is solid. With an alpha of 0, the box is invisible. So we hide and unhide the box by multiplying 255 by the ShowSymbolsInfoVal variable (which is either 1 or 0).
===================================================
SECOND: Create a script to toggle ShowSymbolInfo between "0" and "1".
===================================================
Go into the script editor [Tools] -> [Script Editor].
Select [File] --> [New] and select the name "Toggle-ShowSymbolInfo".
Cut and paste the script below:
string keyword="ShowSymbolInfo";
Chart[] charts = Charts.GetAllCharts();
string res = (string)Global.GetVariable(keyword);
if (res == "1") Global.SetVariable(keyword, "0");
else Global.SetVariable(keyword, "1");
for(int i=0;i < charts.Length;i++) charts[i].Update();
//DEBUGGING: Uncomment the next line to display the keyword/value pair in an Output window.
//App.Main.Sleep(1500); Global.Trace("Global variable "+keyword+" = "+Global.GetVariable(keyword));
This script retrieves a single global variable named "ShowSymbolInfo". The name of the variable to be modified must be hard-coded into the script. If the variable equals the string "1", then it sets it to the string "0". Otherwise, it sets the variable back to "1" again.
Once you've pasted the script, select [File] --> [Save]. And then hit the [Execute] button along the top of the Script Editor. Wait a couple of seconds. Hit it again. And again. The Symbol Info Box that you created earler should appear and then disappear each time to execute the script. If not, you'll need to do some debugging.
===================================================
THIRD: We want to be able to call our script with a keypress.
===================================================
At the bottom of the QuantShare window, go to [Divers] -> [List of Shortcuts]. This is where tell QuantShare to launch a script when certain keys are pressed. Click [Add Shortcut] in the lower-right corner of the screen.
Fill in the Add Shortcut window as follows:
NAME: Toggle-ShowSymbolInfo
DESCRIPTION: Toggles the ShowSymbolInfo variable between "0" and "1"
Put a checkmark next to Control and Shift.
KEY: I (just the letter I, uppercase, all by itself)
PATH: Scripts\Toggle-ShowSymbolInfo.azf
Double-check your work and then press the [Save] button.
===================================================
FOURTH: Try it out!
===================================================
Every time you hold down the [SHIFT] and [CONTROL] keys and tap the letter [I], it will execute the Toggle-ShowSymbolInfo.azf script which will change the value of the global variable ShowSymbolInfo and refresh your charts. Your chart's formula will read the changes to the ShowSymbolInfoVar variable which it will use to hide and unhide the infobox you just created.
Enjoy! And let us know how you've put this to good use.
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.