add ema condition to the lower shadow take profit

This commit is contained in:
c9s 2022-06-30 17:42:23 +08:00
parent 903d773025
commit 6aa6e57d96
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 15 additions and 3 deletions

View File

@ -39,12 +39,13 @@ exchangeStrategies:
# stopEMARange is the price range we allow short.
# Short-allowed price range = [current price] > [EMA] * (1 - [stopEMARange])
stopEMARange: 0%
# Higher the stopEMARange than higher the chance to open a short
stopEMARange: 1%
stopEMA:
interval: 1h
window: 99
bounceShort:
resistanceShort:
enabled: false
interval: 1h
window: 10
@ -86,11 +87,13 @@ exchangeStrategies:
# you can grab a simple stats by the following SQL:
# SELECT ((close - low) / close) AS shadow_ratio FROM binance_klines WHERE symbol = 'ETHUSDT' AND `interval` = '5m' AND start_time > '2022-01-01' ORDER BY shadow_ratio DESC LIMIT 20;
- lowerShadowTakeProfit:
interval: 30m
window: 99
ratio: 3%
# (5) cumulatedVolumeTakeProfit is used to take profit when the cumulated quote volume from the klines exceeded a threshold
- cumulatedVolumeTakeProfit:
minQuoteVolume: 100_000_000
minQuoteVolume: 200_000_000
interval: 5m
window: 2

View File

@ -27,6 +27,10 @@ func (s *LowerShadowTakeProfit) Bind(session *ExchangeSession, orderExecutor *Ge
s.session = session
s.orderExecutor = orderExecutor
stdIndicatorSet, _ := session.StandardIndicatorSet(s.Symbol)
ewma := stdIndicatorSet.EWMA(s.IntervalWindow)
position := orderExecutor.Position()
session.MarketDataStream.OnKLineClosed(func(kline types.KLine) {
if kline.Symbol != position.Symbol || kline.Interval != types.Interval1m {
@ -47,6 +51,11 @@ func (s *LowerShadowTakeProfit) Bind(session *ExchangeSession, orderExecutor *Ge
return
}
// skip close price higher than the ewma
if closePrice.Float64() > ewma.Last() {
return
}
if kline.GetLowerShadowHeight().Div(kline.Close).Compare(s.Ratio) > 0 {
Notify("%s TakeProfit triggered by shadow ratio %f, price = %f",
position.Symbol,