Được tạo bởi Blogger.

tutorials on how to create strategy

Zenbot load a strategy by finding the file extensions/strategies/<strategy-name>/strategy.js. A strategy module export an object with optional methods that will be called at the right time. The important methods are:
  • onCalculate: called each time there is a new trade. it's the right place to update indicators.
  • onPeriod: called at the end of each period. It the right place to send 'buy' or 'sell' signals.
  • onReport: called each time the console is refreshed. It must return an array, and each item in this array will be displayed in the console (after the RSI and before the balance).
Each one of these methods take a parameter s, who is a global object containing everything.
s = {
  options: {  // general options are all here
 paper: true,
 order_type: 'taker',
 mode: 'paper',
 period_length: '1m',
 avg_slippage_pct: 0.045,
            // ...

  // Info about the balance
  product_id: 'XRP-BTC',
  asset: 'XRP',
  currency: 'BTC',
  asset_capital: 2.3,
  currency_capital: 123,

  // The current period
  period: {
 period_id: 'm25703679'
 size: '1m',
 time: 1542220740000,
 open: 0.00007813,
 high: 0.00007813,
 low: 0.00007813,
 close: 0.00007813,
 volume: 224996,

  // Previous periods
  lookback: []
Each time the period change, the current period is put at the beginning of s.lookback and s.period is reset. So you can check the last period in s.lookback[0], the one before in s.lookback[1], and so on.
The indicators available use an easy way to store data: they add them to the period object. By example, to get the RSI:
var rsi = require('../../../lib/rsi')


rsi(s, 'custom_key', 7)
// RSI is stored in 's.period.custom_key'
Edit: it doesn't respond to all your questions, but it should help you. I discovered everything by testing and reading the code and I encourage you to do the same.
    Blogger Comment
    Facebook Comment