|
|
# Variable system
|
|
|
| command | description |
|
|
|
| ------------- | ---------- |
|
|
|
| | If a variable is assigned in multiple places, precedence as follows: |
|
|
|
| | 1st. Current context |
|
|
|
| | 2nd. Current instrument |
|
|
|
| | 3rd. Global instrument |
|
|
|
| *........................//////* | If a variable is assigned in multiple places, precedence as follows: |
|
|
|
| *........................//////* | 1st. Current context |
|
|
|
| *........................//////* | 2nd. Current instrument |
|
|
|
| *........................//////* | 3rd. Global instrument |
|
|
|
| `set` | set assigns the value globally for the current instrument and to the current context. `set p 5000, set h 11000` - sets `p` to have a value of `5000` and `h` to have a value of`11000`. I can now use p or h instead of typing 5000 and 11000. |
|
|
|
| `let` | let assigns only to the current context. ie it disappears/no longer exists after the command has finished executing. `let k 500, check value k` - it will tell me that k has a value of 500, then it'll immediately erase the variable "k", since the command has finished executing. Think of it as a "disposable" version of `set`. |
|
|
|
| `check value` | prints the value of the current variable including any comparison operators (math). It's good practice to check the value of anything you are about to put into an alias. If you plan on using 50% of your free collateral for example, you can just `check value 50%freecollateral` - to make sure it outputs the **actual number** you are requiring for the particular use. You can "check value" pretty much anything. `check value askprice-bidprice` to give you the current spread for example. |
|
|
|
| `%variable` | you could use a variable like `set h 250, buy 50%h` - meaning buy 125 |
|
|
|
| `variable-%` |`x-1%` |
|
|
|
| `variable+/-` | variable + or - like `h-50` - And many other arithmetic and comparison operators as listed below: |
|
|
|
| | **Arithmetic** to be used **without** spaces. `a+b` - no spaces in the math. |
|
|
|
| *........................//////* | **Arithmetic** to be used **without** spaces. `a+b` - no spaces in the math. |
|
|
|
| `+` | Plus. |
|
|
|
| `/` | Divide by. |
|
|
|
| `-` | Minus. |
|
|
|
| `*` | Multiplied by. |
|
|
|
| | **Comparison Operators** to be used **with** spaces. `wait price > 100` - spaces between the commands, unlike the math example. |
|
|
|
| *........................//////* | **Comparison Operators** to be used **with** spaces. `wait price > 100` - spaces between the commands, unlike the math example. |
|
|
|
| `<` | Less than. |
|
|
|
| `>` | Greater than. |
|
|
|
| `<=` | Equal to or less than. |
|
... | ... | @@ -24,14 +24,14 @@ |
|
|
| `==` | Equal to. |
|
|
|
| `!=` | Is NOT equal to. |
|
|
|
| `random` | Variable that generates a random number between 0 - 1. Can use this in arithmetic to create randomness to your ordersizes for eg - `let avg_size 10, let r random*0.1, let m 0.95+r, let sz avg_size*m, buy sz 31000` - will buy a random size between 9.5 and 10.5 units. |
|
|
|
| | **Market, trading and account variables:** |
|
|
|
| *........................//////* | **Market, trading and account variables:** |
|
|
|
| `account` | Will return a result in the value of the token you're currently in (since buy amounts are in coins not USD) - `buy 50%account` |
|
|
|
| `accountvalueusd` | `let x 150%accountvalueusd, wait pnl > x, close all` - that would wait until your account was up 50% before automatically closing your position, as an example. |
|
|
|
| `collateral` |`buy 50%collateral` |
|
|
|
| `collateralusd` | Outputs the same value but in USD. **Don't use the USD outputs for position sizing** |
|
|
|
| `freecollateral` |`buy 200%freecollateral` (x2 leverage) |
|
|
|
| `freecollateralusd` | Outputs the same but in USD. |
|
|
|
| *........................//////* | **EXAMPLE** |
|
|
|
| *........................//////* | **EXAMPLE** |
|
|
|
| *........................//////* | So say you have an account balance of $10,000 |
|
|
|
| *........................//////* | **Made up of:** |
|
|
|
| *........................//////* | $5,000 USD |
|
... | ... | |