Backtest result page

Hide/Show all

Settings

Strategy: HeikinCosi Init. capital: $10,000.00 From: 2017-01-01 03:59:00 Untill: 2017-08-31 21:41:00
Timeframe: 4hod Tickers: BTCUSD

Result

Initial capital: $10,000.00 Ending capital: $29,494.85 Profit: $19,494.85 Profit %: 194.95%
Total: 38 Winning: 20 | 52.63% Losing: 18 | 47.37% Consecutive win/loss: 4 / 4
Avg trade: $513.02 Avg profit: $1,396.62 Avg loss: -$468.75 Max loss/profit: -$1,284.98 / $5,043.69
Max DD: 16.53% Max DD recovery #: 37

Capital

Entries

Months/Years

Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Yr%
2017 -13.66% 9.32% -10.41% 10.82% 52.43% 11.81% 33.30% 38.54% 0.00% 0.00% 0.00% 0.00% 194.95%
Avg: -13.66% 9.32% -10.41% 10.82% 52.43% 11.81% 33.30% 38.54% 0.00% 0.00% 0.00% 0.00%

Orders

# Pos Ticker Amnt (pieces) Open date O. Price Close date C. Price Profit/Loss Ending capital
1 L BTCUSD 9.65116683 2017-01-04 00:22:00 $1,035.11 ($9,990.00) 2017-01-05 16:28:00 $979.01 ($9,448.61) -$541.39 | -5.42% $9,458.61
2 L BTCUSD 10.28210469 2017-01-08 04:31:00 $918.99 ($9,449.15) 2017-01-11 13:21:00 $810.00 ($8,328.50) -$1,120.65 | -11.86% $8,337.96
3 L BTCUSD 9.98756838 2017-01-16 05:51:00 $834.00 ($8,329.62) 2017-01-18 18:18:00 $869.70 ($8,686.19) $356.57 | 4.28% $8,694.53
4 L BTCUSD 9.45942745 2017-01-21 06:26:00 $918.22 ($8,685.84) 2017-01-22 14:32:00 $906.84 ($8,578.21) -$107.63 | -1.24% $8,586.90
5 L BTCUSD 9.40141652 2017-01-26 15:30:00 $912.45 ($8,578.31) 2017-01-29 21:53:00 $917.46 ($8,625.41) $47.10 | 0.55% $8,634.00
6 L BTCUSD 9.32480065 2017-01-30 22:16:00 $924.99 ($8,625.37) 2017-02-05 18:38:00 $1,009.66 ($9,414.88) $789.51 | 9.15% $9,423.51
7 L BTCUSD 9.08817543 2017-02-07 06:48:00 $1,035.86 ($9,414.09) 2017-02-08 10:56:00 $1,029.31 ($9,354.55) -$59.54 | -0.63% $9,363.97
8 L BTCUSD 8.74262246 2017-02-09 07:06:00 $1,070.00 ($9,354.61) 2017-02-09 15:16:00 $979.94 ($8,567.24) -$787.37 | -8.42% $8,576.60
9 L BTCUSD 8.47906109 2017-02-11 07:31:00 $1,010.49 ($8,568.02) 2017-02-12 19:49:00 $1,001.10 ($8,488.39) -$79.64 | -0.93% $8,496.96
10 L BTCUSD 8.33698992 2017-02-14 12:07:00 $1,018.17 ($8,488.47) 2017-02-25 17:44:00 $1,131.14 ($9,430.26) $941.79 | 11.09% $9,438.75
11 L BTCUSD 7.89079066 2017-02-27 18:09:00 $1,194.98 ($9,429.32) 2017-03-04 18:32:00 $1,248.19 ($9,849.24) $419.92 | 4.45% $9,858.67
12 L BTCUSD 7.83516758 2017-03-10 15:10:00 $1,257.00 ($9,848.82) 2017-03-10 23:10:00 $1,093.00 ($8,563.85) -$1,284.98 | -13.05% $8,573.69
13 L BTCUSD 7.07853728 2017-03-12 19:17:00 $1,210.02 ($8,565.14) 2017-03-16 07:27:00 $1,216.01 ($8,607.58) $42.44 | 0.50% $8,616.13
14 L BTCUSD 8.2291572 2017-03-21 03:37:00 $1,045.98 ($8,607.53) 2017-03-22 15:41:00 $998.90 ($8,220.13) -$387.40 | -4.50% $8,228.73
15 L BTCUSD 8.36439725 2017-03-26 17:08:00 $982.80 ($8,220.52) 2017-03-29 05:19:00 $1,009.99 ($8,447.93) $227.41 | 2.77% $8,456.14
16 L BTCUSD 7.95033861 2017-03-31 17:27:00 $1,062.56 ($8,447.70) 2017-04-08 21:48:00 $1,179.99 ($9,381.34) $933.63 | 11.05% $9,389.77
17 L BTCUSD 7.81094851 2017-04-09 17:49:00 $1,200.93 ($9,380.41) 2017-04-13 10:04:00 $1,196.23 ($9,343.70) -$36.71 | -0.39% $9,353.06
18 L BTCUSD 7.7720691 2017-04-17 18:48:00 $1,202.22 ($9,343.74) 2017-04-19 10:53:00 $1,197.52 ($9,307.21) -$36.53 | -0.39% $9,316.53
19 L BTCUSD 7.62888807 2017-04-20 11:08:00 $1,220.00 ($9,307.24) 2017-04-22 15:25:00 $1,227.17 ($9,361.94) $54.70 | 0.59% $9,371.23
20 L BTCUSD 7.51348804 2017-04-24 07:45:00 $1,246.01 ($9,361.89) 2017-05-07 16:22:00 $1,522.74 ($11,441.10) $2,079.21 | 22.21% $11,450.44
21 L BTCUSD 7.26173072 2017-05-08 04:22:00 $1,575.25 ($11,439.02) 2017-05-13 00:22:00 $1,703.70 ($12,371.80) $932.78 | 8.15% $12,383.22
22 L BTCUSD 6.88417738 2017-05-14 04:22:00 $1,797.00 ($12,370.87) 2017-05-27 00:32:00 $2,150.00 ($14,800.99) $2,430.12 | 19.64% $14,813.34
23 L BTCUSD 6.6064985 2017-05-28 12:32:00 $2,240.00 ($14,798.56) 2017-05-31 00:32:00 $2,160.00 ($14,270.04) -$528.51 | -3.57% $14,284.83
24 L BTCUSD 6.15094924 2017-05-31 20:32:00 $2,320.06 ($14,270.57) 2017-06-08 00:32:00 $2,672.81 ($16,440.34) $2,169.77 | 15.20% $16,454.60
25 L BTCUSD 5.8020399 2017-06-09 04:32:00 $2,833.17 ($16,438.17) 2017-06-12 12:35:00 $2,800.00 ($16,245.71) -$192.46 | -1.17% $16,262.14
26 L BTCUSD 6.44819732 2017-06-16 12:35:00 $2,519.45 ($16,245.90) 2017-06-19 00:38:00 $2,482.00 ($16,004.43) -$241.47 | -1.49% $16,020.67
27 L BTCUSD 6.14860662 2017-06-20 04:39:00 $2,602.98 ($16,004.67) 2017-06-22 00:39:00 $2,594.99 ($15,955.57) -$49.10 | -0.31% $15,971.57
28 L BTCUSD 6.42796304 2017-06-28 00:41:00 $2,482.22 ($15,955.62) 2017-07-01 00:41:00 $2,460.12 ($15,813.56) -$142.06 | -0.89% $15,829.51
29 L BTCUSD 6.37649213 2017-07-02 20:41:00 $2,480.00 ($15,813.70) 2017-07-07 16:41:00 $2,514.00 ($16,030.50) $216.80 | 1.37% $16,046.31
30 L BTCUSD 6.69310892 2017-07-12 20:41:00 $2,395.04 ($16,030.28) 2017-07-14 04:41:00 $2,304.94 ($15,427.24) -$603.04 | -3.76% $15,443.27
31 L BTCUSD 7.57363688 2017-07-17 12:41:00 $2,037.05 ($15,427.85) 2017-07-23 12:42:00 $2,703.00 ($20,471.54) $5,043.69 | 32.69% $20,486.96
32 L BTCUSD 7.88992346 2017-07-27 12:42:00 $2,594.00 ($20,466.49) 2017-07-29 16:42:00 $2,695.70 ($21,268.87) $802.37 | 3.92% $21,289.33
33 L BTCUSD 7.50675763 2017-07-31 20:42:00 $2,833.19 ($21,268.07) 2017-08-01 16:42:00 $2,701.00 ($20,275.75) -$992.32 | -4.67% $20,297.01
34 L BTCUSD 7.33805303 2017-08-03 20:43:00 $2,763.23 ($20,276.74) 2017-08-09 12:43:00 $3,270.10 ($23,996.17) $3,719.42 | 18.34% $24,016.43
35 L BTCUSD 7.01993925 2017-08-10 12:58:00 $3,417.76 ($23,992.45) 2017-08-15 16:58:00 $3,900.00 ($27,377.76) $3,385.31 | 14.11% $27,401.74
36 L BTCUSD 6.34168212 2017-08-16 20:58:00 $4,316.58 ($27,374.38) 2017-08-18 20:58:00 $4,120.00 ($26,127.73) -$1,246.65 | -4.55% $26,155.09
37 L BTCUSD 6.33429694 2017-08-22 21:05:00 $4,125.00 ($26,128.97) 2017-08-28 05:41:00 $4,296.10 ($27,212.77) $1,083.80 | 4.15% $27,238.89
38 L BTCUSD 6.21116915 2017-08-29 01:41:00 $4,381.09 ($27,211.69) 2017-08-31 21:41:00 $4,744.30 ($29,467.65) $2,255.96 | 8.29% $29,494.85

Code

const Promise = require('bluebird')
const moment = require('moment')
const _ = require('lodash')
const Abstract = require('./Abstract')

module.exports = class Heikin extends Abstract {
  init () {
    this.inPosition = false
    // work only with one ticker
    this.ticker = this.tickers[0]

    // for how long will we calculate support and resistance
    this.PERIOD = 20
  }

  _getSizeByScale () {
    const tickerPrice = this.orderManager.getPrice(this.ticker)
    const capital = this.orderManager.getFreeCapital()

    // some magic stuff here
    return capital / tickerPrice * 0.999
  }

  _buy () {
    this.orderManager.buy(this.ticker, this._getSizeByScale())
    this.inPosition = true
  }

  _sell () {
    this.orderManager.sell(this.ticker, this._getSizeByScale())
    this.inPosition = true
  }

  _closeTrade () {
    this.orderManager.closeAll()
    this.inPosition = false
  }

  async step (time, data) {
    // work only with data for one ticker
    const tickerData = _.cloneDeep(data[this.ticker])
    // get latest close price from ticker
    const price = this._getCurrentPrice(tickerData)
    // remove last ticker from list
    tickerData.pop()
    // turn data to heikinAshi
    const heikin = this._getHeikinAshi(tickerData)
    // get support and resistance
    const res = this._getResistance(heikin.high, this.PERIOD)
    const sup = this._getSupport(heikin.low, this.PERIOD)

    // if we are in position
    if (this.inPosition) {
      const position = this.orderManager.getOpenPositions()[this.ticker]
      if(!position)
        return this.inPosition = false

      const positionIsLong = position.amount > 0

      if (positionIsLong && price < sup) {
        this._closeTrade()
        // this._sell()
      }

      // if (!positionIsLong && price > res) {
      //   this._closeTrade()
      //   this._buy()
      // }

    } else {

      // buy when price crosses resistance
      if (price > res)
        this._buy()

      // else if (price < sup)
      //   this._sell()

    }
  }
}