FUTU HK Help Center-How to Use Global Variables
English
Back
Open Account
Clear
All
Quotes
News
Learn
Help
All
HK
US
CN
SG
AU
JP
CA
MY
All
News
Announcements
Reports

How to Use Global Variables

1. What is a global variable?

A global variable is a custom variable that can be created in multiples.

There are two types of global variables: 

1. Numeric global variables: This kind of global variable can be used to record integers or decimals. When setting parameters in conditions/operations, numeric global variables can be used to assign values. For example, create a numeric global variable "a" and set it to "Buy 'a' shares of Apple (AAPL.US)" in the Order Conditions.

2. Symbol global variables: You can directly select the symbol in other conditions/operations without repeatedly searching symbols. For example, if you create a symbol global variable "a" and designate it as Tesla (TSLA.US), it will be set directly to "Buy one share of 'a'" in the Order Conditions.

 

2. How to create a global variable in a strategy?

Create a variable A in the "Start" properties, with an initial value of the stock's latest price. Please note that global variables are only assigned an initial value when the strategy starts, which is the current stock price.

(Images provided are not current and any securities or strategies are shown for illustrative purposes only and are not recommendation.)

You can assign the value A to the global variable A with the "Value Assignment" card and then print the value of the global variable in the Running Log on the Backtest page. 

(Images provided are not current and any securities or strategies are shown for illustrative purposes only and are not recommendation.)

The value of the global variable A is displayed in the running log, and it will always be a constant value (see below).

(Images provided are not current and any securities or strategies are shown for illustrative purposes only and are not recommendation.)

 

3. How to keep a global variable always at the latest stock price when a strategy is running?

Suppose you want to keep the value of the global variable A to be the latest stock price when the strategy is running. In that case, you can assign the latest stock price to variable A with the "Value Assignment".

(Images provided are not current and any securities or strategies are shown for illustrative purposes only and are not recommendation.)

This way, the global variable A will hold the updated latest price value.

(Images provided are not current and any securities or strategies are shown for illustrative purposes only and are not recommendation.)

Market Insights

Discussing

關稅風暴暫離高壓區!市場能否迎來反彈?
當地時間4月22日,美國總統特朗普公開承認美國目前對中國出口商品的關稅過高,預計稅率將大幅降低;美國財政部長貝森特也表示中美雙方關稅戰將很快降溫。4月25日,特朗普表示將爲不同國家設定「公平的」關稅稅率。特朗普此次對華關稅態度的轉變,能否平息市場恐慌情緒?關稅拉鋸戰最終結局如何? Show More
特朗普對華態度緩和!近期你會如何操作?
67%
33%
做多
做空
13K votes