Skip to main content

策略參數

系統預留參數

請勿將系統預留參數用於其他用途

VariableDescriptionTypeDefault Value
exchange_fee設定回測及模擬的交易手續費,預設為 0.1%Number0.001
spread設定回測及模擬的滑價比例Number0
leverage設定實單交易的槓桿倍數Number1
IS_DEBUG設定 True 以開啟回測的除錯模式Booleanfalse

自定義參數

透過 self['OPTION_NAME'] 存取策略參數

You can add some extra arguments for the strategy and change these arguments for every live trade, backtest or simulation. For example, if you have the following configuration for a strategy

警告

All arguments are actually stored and parsed as String type in your strategy code. So you have to parse it by your self!

Type

  • Boolean

    A STRING that indicates either true or false

  • Number

    A STRING that represents a float value.

  • String

    A STRING that holds a ASCII string

  • Select

    A STRING that holds a list of ASCII string. Separated by the symbol vertical bar |.

Example

Suppose you use the following configuration

VariableDescriptionTypeDefault Value
MyArgAtrue/falseBooleantrue
MyArgBa float numNumber10.9
MyArgCa ASCII StrStringHello World!
MyArgDa ASCII listSelectOptionA|OptionB|OptionC
備註

Only ASCII string is supported currently

Then you're allowed to tweak these variables to be used in your strategy before trading. MyArgD will appear as a list consisting of OptionA, OptionB and OptionC.

image

備註

You can access these arguments by self['argName']

def trade(self, information):
CA.log(self['MyArgA']) # true
CA.log(self['MyArgB']) # 10.9
CA.log(self['MyArgC']) # Hello World!
CA.log(self['MyArgD']) # OptionC

CA.log(str(self['MyArgA'].__class__)) # <class 'str'>
CA.log(str(self['MyArgB'].__class__)) # <class 'str'>
CA.log(str(self['MyArgC'].__class__)) # <class 'str'>
CA.log(str(self['MyArgD'].__class__)) # <class 'str'>
All of the types are string in python

So if you want to check MyArgA is true or not, you have to use it like if self['MyArgA'] == 'true' instead of if self['MyArgA].