The currently supported indicators are:
ma
,ema
,rsi
,kc(keltner channels)
,boll
,atr
The name must be unique in a coin (required when writing strategies)
kline_interval
other params
Only indicators that have been enabled can be used in the strategy
!!! The logic of strategy must ultimately be
true
或false
!!!
Give a name to the strategy
Customize policy logic, we will explain how to write it later
long or short
Only when there is a choice to activate, can it truly be used
If we define 2 rows of data under the column of EMA as follows:
name | kline_interval | period | enable |
---|---|---|---|
ema_4h_3 | 4h | 4 | true |
ema_4h_7 | 4h | 7 | true |
The program will create 150 element length variables representing
ema_4h_3
andema_4h_7
, details:
ema_4h_3.KlineInterval // 4h
ema_4h_3.Period // 4
ema_4h_3.Data = [30.2, 30.3, ..] // 150 count, the sorting method is from the latest to the oldest in terms of time dimension (`ema["ema_4h_3"][0]` is the `ema` data at the current time)
ema_4h_7.KlineInterval // 4h
ema_4h_7.Period // 7
ema_4h_7.Data = [33.2, 35.3, ..]
Based on the
ema
technology demo above, let's write a simple strategy as follows:
ema_4h_3.Data[0] > ema_4h_7.Data[0] && ema_4h_3.Data[1] < ema_4h_7.Data[1]
Let's explain that
ema_4h_3
is a short line ofema
, andema_4h_7
is a long line ofema
(relative toema_4h_3
). Therefore, the meaning of the above strategy is that theshort line
at the previous moment is below thelong line
, and theshort line
at the current moment is above thelong line
. In terms of terminology, this is a golden cross and a trend strategy oflong
code definition,detail: https://expr-lang.org/docs/language-definition#now
https://expr-lang.org/docs/language-definition#array-functions
/**
* Has there only been one golden cross (short-term crossing over long-term once, without repeated crossing)
* @param ma1 short-term
* @param ma2 long-term
* @param num num
* @returns Boolean
*/
func Kdj(ma1 []float64, ma2[]float64, num int) bool
// Is it a descending array
func IsDesc(arr []float64) bool
// Is it an ascending array
func IsAsc(arr []float64) bool
name | kline_interval | period | enable |
---|---|---|---|
ma1 | 4h | 14 | true |
ma1.KlineInterval // 4h
ma1.Period // 14
ma1.Data = [30.2, 30.3, ..] // 150 count
name | kline_interval | period | enable |
---|---|---|---|
ema1 | 4h | 14 | true |
ema1.KlineInterval // 4h
ema1.Period // 14
ema1.Data = [30.2, 30.3, ..] // 150 count
name | kline_interval | period | enable |
---|---|---|---|
rsi1 | 4h | 14 | true |
rsi1.KlineInterval // 4h
rsi1.Period // 14
rsi1.Data = [67.2, 70.3, ..] // < 150 count
name | KlineInterval | Period | Multiplier | enable |
---|---|---|---|---|
kc_1 | 4h | 50 | 2.75 | true |
kc_1.KlineInterval // 4h
kc_1.Period // 50
kc_1.Multiplier // 2.75
kc_1.High = [67.2, 70.3, ..]
kc_1.Mid = [57.2, 50.3, ..]
kc_1.Low = [37.2, 40.3, ..]
name | KlineInterval | Period | StdDevMultiplier | enable |
---|---|---|---|---|
boll_1 | 4h | 21 | 2 | true |
boll_1.KlineInterval // 4h
boll_1.Period // 21
boll_1.StdDevMultiplier // 2
boll_1.High = [67.2, 70.3, ..]
boll_1.Mid = [57.2, 50.3, ..]
boll_1.Low = [37.2, 40.3, ..]
name | kline_interval | period | enable |
---|---|---|---|
atr1 | 4h | 14 | true |
atr1.KlineInterval // 4h
atr1.Period // 14
atr1.Data = [67.2, 70.3, ..] // 150 count
whenever you define an indicator of any kline type, additional variables corresponding to the candlestick data will be generated as
kline_{xx}
name | kline_interval | period | enable |
---|---|---|---|
xxx | 4h | xxx | true |
kline_4h.High = [67.2, 70.3, ..] // 150 count
kline_4h.Low = [27.2, 20.3, ..] // 150 count
kline_4h.Open = [37.2, 30.3, ..] // 150 count
kline_4h.Close = [47.2, 34.3, ..] // 150 count
kline_4h.Amount = [100.1, 100.2..] // 150 count
kline_4h.Qps = [10.31, 10.32..] // 150 count
BTCUSDT.PercentChange = 1.1
BTCUSDT.Close = 70000.2
BTCUSDT.Open = 71000.4
BTCUSDT.Low = 65000.4
BTCUSDT.High = 75000.2
ETHUSDT.PercentChange = -1.1 // 涨跌幅
ETHUSDT.Close = 2500.2 // 当前价格
ETHUSDT.Open = 2400.45 // 开盘价
ETHUSDT.Low = 2456.2 // 最低价
ETHUSDT.High = 2840.3 // 最高价
SOLUSDT.PercentChange = -1.1
SOLUSDT.Close = 200.2
SOLUSDT.Open = 230.45
SOLUSDT.Low = 143.2
SOLUSDT.High = 244.3
BNBUSDT.PercentChange = -1.1
BNBUSDT.Close = 600.2
BNBUSDT.Open = 580.45
BNBUSDT.Low = 578.2
BNBUSDT.High = 640.3
NowSymbolPercentChange = -1.1
NowSymbolClose = 2500.2
NowSymbolOpen = 2400.45
NowSymbolLow = 2456.2
NowSymbolHigh = 2840.3
string -> float: float(Position.xxx)
ORI = 10.2 // profit %
Position.Symbol = "ETHUSDT"
Position.EntryPrice = 2500.2
Position.MarkPrice = 2400.2
Position.Amount = 1.2
Position.UnrealizedProfit = 32.2
Position.Leverage = 3
Position.Side = "LONG"
Position.Mock = false // is mock data
btc * 0.6 + eth * 0.3 + sol * 0.05 + bnb * 0.05
BasicTrend = 0.3