Skip to content

Instantly share code, notes, and snippets.

@abelardojarab
Last active January 29, 2023 18:20
Show Gist options
  • Star 22 You must be signed in to star a gist
  • Fork 12 You must be signed in to fork a gist
  • Save abelardojarab/540e5fb0a807bf551e50ffbff10fefd6 to your computer and use it in GitHub Desktop.
Save abelardojarab/540e5fb0a807bf551e50ffbff10fefd6 to your computer and use it in GitHub Desktop.
zenbot strategy

Current strategy

$  ./zenbot.sh trade gdax.eth-USD --trend_ema 20 -period 7m --max_slippage_pct 0.48 --poll_trades 6000 --order_poll_time 6000 --order_adjust_time 6000 --oversold_rsi_periods=1000 --oversold_rsi=1000 --rsi_periods=1100 --neutral_rate=0.1 --max_sell_loss_pct=0.85 --max_buy_loss_pct=5 --buy_pct=100 --sell_pct=100 --selector gdax.eth-usd  --markup_sell_pct 0.25  --markdown_buy_pct 0.00  --reset-profit

The role of buy & sell percentages (PCT)

The meaning of buy_pct=x is that if that "x" is set to say "50" then the bot uses 50% of your currency balance to buy at a certain point. If that point is followed by a down-trend, and it buys once more with 50% of the remaining balance, then the bot takes that recent price into consideration when max_sell_loss_pct is concerned.

That means, originally you bought for 2.00, then once more at 1.80. the bot will sell at 1.82, even if that is unfavorable because he bought at 1.80 last. Even if you would like the bot to hold till say 2.10.

In a market with predictable price surges and corrections, --profit_stop_enable_pct=10 will try to sell when the last buy hits 10% profit and then drops to 9% (the drop % is set with --profit_stop_pct). However in strong, long uptrends this option may end up causing a sell too early.

The role of markdown buy or sell percentages

For example :

markdown_buy_pct 0.48 is buying at the current market price - (0.48% of current market price )
markup_sell_pct 0.48 is selling at the current market price + (0.48% of current market price )

This enable a strategy with early signal (like trend_ema or neural) to not get executed on the first signal and follow the trend until execution.

This also allow to get price surge (down or up) and also means that you will buy or sell at 0,48% of the market, since most exchange fees are between 0% and 0,50% you are pretty sure that you will earn a profit on most trades.

Default strategy (trend_ema)

Description: Buys when (EMA - last(EMA) > 0) and sells when (EMA - last(EMA) < 0). Optional buy on low RSI.

Options:
--period= period length, same as --period_length (default: 2m=2 minutes)
--period_length= period length, same as --period (default: 2m)
--min_periods= min. number of history periods (default: 52)
--rsi_periods number of periods to calculate RSI at (default 12)?
--trend_ema= number of periods for trend EMA (default: 26)
--neutral_rate= avoid trades if abs(trend_ema) under this float (0 to disable, "auto" for a variable filter) (default: auto)
--oversold_rsi_periods= number of periods for oversold RSI (default: 14)
--oversold_rsi= buy when RSI reaches this value (default: 10)

Trade frequency is adjusted with a combination of --period and --trend_ema. For example, if you want more frequent trading, try --period=1m or --trend_ema=20 or both. If you get too many ping-pong trades or losses from fees, try increasing period or trend_ema.

If the period is set too high, you could miss the value by a lot. For example, a --period=10m can leave you exposed for 10 minutes while the loss grows bigger than the c.sell_stop_pct.

Neural strategy

This is a fragment of the neural strategy module (zenbot/extensions/strategies/neural/strategy.js):

return {
name: 'neural',
description: 'Use neural learning to predict future price. Buy = mean(last 3 real prices) < mean(current & last prediction)',
getOptions: function () {
this.option('period', 'period length - make sure to lower your poll trades time to lower than this value', String, '1m')
this.option('activation_1_type', "Neuron Activation Type: sigmoid, tanh, relu", String, 'sigmoid')
this.option('neurons_1', "Neurons in layer 1 Shoot for atleast 100", Number, 1)
this.option('depth', "Rows of data to predict ahead for matches/learning", Number, 5)
this.option('selector', "Selector", String, 'Gdax.BTC-USD')
this.option('min_periods', "Periods to calculate learn from", Number, 300)
this.option('min_predict', "Periods to predict next number from", Number, 100)
this.option('momentum', "momentum of prediction", Number, 0.9)
this.option('decay', "decay of prediction, use teeny tiny increments", Number, 0)
this.option('threads', "Number of processing threads you'd like to run (best for sim)", Number, 1)
this.option('learns', "Number of times to 'learn' the neural network with past data", Number, 10)
this.option('markup_pct', "Defaulting a markup percent", Number, 0.05)
},

A neural network example

The model consists of four hidden layers. The first layer contains 1024 neurons, slightly more than double the size of the inputs. Subsequent hidden layers are always half the size of the previous layer, which means 512, 256 and finally 128 neurons. A reduction of the number of neurons for each subsequent layer compresses the information the network identifies in the previous layers. Of course, other network architectures and neuron configurations are possible but are out of scope for this introduction level article.

Command:

$ ./zenbot.sh trade gdax.eth-USD --trend_ema 22 -period 3m --max_slippage_pct 0.2 --poll_trades 5000 --order_poll_time 3000 --order_adjust_time 3000 --oversold_rsi_periods=1000 --oversold_rsi=1000 --rsi_periods=1100 --neutral_rate=0.017 --max_sell_loss_pct=0.001 --max_buy_loss_pct=5 --buy_pct=100 --sell_pct=100 --selector gdax.eth-usd  --markup_sell_pct 0.001  --markdown_buy_pct 0.001  --reset-profit
@trinq
Copy link

trinq commented May 2, 2021

thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment