Skip to content

Instantly share code, notes, and snippets.

/*
Create a trading strategy using the Choppiness Index and the Detrended Price Oscillator for entry and exit signals. Console log every indicator and trading conditions. Do not buy when there is a bag, do not sell when there is no bag.
*/
// Initialize customStratStore in pairLedger
gb.data.pairLedger.customStratStore ||= {};
// Choppiness Index calculation (not provided by default, so we calculate manually)
const calculateChoppinessIndex = (period = 14) => {
const high = gb.data.candlesHigh.slice(-period);
"builder": {
"ADX_ENABLED": false,
"ADX_LEVEL": 25,
"ATRX": 0.5,
"ATR_PERIOD": 14,
"BTC_MONEY_FLOW": 35,
"BTC_PND_PERIOD": 14,
"BTC_PND_PROTECTION": false,
"BUYLVL": 1,
"BUYLVL1": 0.6,
//require ./ctx-wrapper.js
let ctxWrapper = require('./ctx-wrapper');
//then wrap the following promise in a function
new ctxWrapper(exchange, exchangeConfig)
.ohlc(parseFloat(CANDLES_LENGTH), parseFloat(PERIOD), pair)
.then((candles) => {
//do your own things with candles
})
.catch((e) => {
getITB() {
const quoteBalance = parseFloat(this.getLedger().quoteBalance) || 0
const keepQuote = parseFloat(this.strategy_config.KEEP_QUOTE) || 0
let boughtAmount = 0
let detectedITB = 0
var orders = this.getLedger().orders;
// try if we can establish a useful ITB value with order history data, only for usage in abp
// iterate through most recent orders, sum amounts and stop when a sell happens after the previous order history cumulated a similar amount to currentQty
for (let i = 0; i < orders.length; i++) {
if (orders[i].type === 'buy') {
function loadConfig() {
return new Promise((resolve, reject) => {
try {
if (config_file.substring(0, 5) == 'https' || config_file.substring(0, 4) == 'http') {
console.log(sprintf('Loading remote config... [%s]'.GOOD_NEWS_COLOR, config_file));
rp(config_file).then((response) => {
resolve(JSON.parse(response));
});
} else {
StatusCodeError: 520 - "<html>\n<head><title>520 Origin Error</title></head>\n<body bgcolor=\"white\">\n<center><h1>520 Origin Error</h1></center>\n<hr><center>cloudflare-nginx</center>\n</body>\n</html>\n"
at new StatusCodeError (/Users/enricoranucci/Desktop/STABLE/node_modules/request-promise/node_modules/request-promise-core/lib/errors.js:32:15)
at Request.plumbing.callback (/Users/enricoranucci/Desktop/STABLE/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:104:33)
at Request.RP$callback [as _callback] (/Users/enricoranucci/Desktop/STABLE/node_modules/request-promise/node_modules/request-promise-core/lib/plumbing.js:46:31)
at Request.self.callback (/Users/enricoranucci/Desktop/STABLE/node_modules/request/request.js:185:22)
at Request.emit (events.js:315:20)
at Request.<anonymous> (/Users/enricoranucci/Desktop/STABLE/node_modules/request/request.js:1154:10)
at Request.emit (events.js:315:20)
at IncomingMessage.<anonymous> (/Users/enricoranucci/D
calculateSpotMarketPnL(orders) {
let accumulatedProfit = 0;
let startCalculatingPnL = false;
let accumulatedAmount = 0;
Object.values(orders).map((item, index) => {
const nextIdx = index + 1;
if (item.type === 'buy') {
accumulatedAmount = parseFloat(accumulatedAmount) + parseFloat(item.amount);
accumulatedAmount = accumulatedAmount.toPrecision(8);
accumulatedProfit += item.costProceed;
const closePosition = function(amount,exchange,pair) {
let price = memory.ledger[exchange][pair].Bid;
return memory.exchanges[exchange]
.cancelOrderSTOP(0, pair, 'Close', amount, price, price, price, (data) => {
console.log(data)
}) .catch((e) => {
if (e.message == 'Exchange_Timeout') {
console.log(exchange, 'timeout');
} else {
console.log('\r\n', e);
error: Error: Module did not self-register: '\\?\C:\Users\Administrator\Desktop\win_14\node_modules\@neon-exchange\nash-protocol-legacy\build\main\native\win_index.node'.
at Object.Module._extensions..node (internal/modules/cjs/loader.js:1248:18)
at Module.load (internal/modules/cjs/loader.js:1047:32)
at Function.Module._load (internal/modules/cjs/loader.js:935:14)
at Module.require (internal/modules/cjs/loader.js:1087:19)
at Module.require (pkg/prelude/bootstrap.js:1225:31)
at require (internal/modules/cjs/helpers.js:73:18)
at loadNodeFile (C:\snapshot\test\Desktop\node14\node_modules\@neon-exchange\nash-protocol-legacy\build\main\native\index.js:22:20)
at Object.<anonymous> (C:\snapshot\test\Desktop\node14\node_modules\@neon-exchange\nash-protocol-legacy\build\main\native\index.js:27:19)
at Module._compile (pkg/prelude/bootstrap.js:1320:22)
payload: {
allowTaker: false,
amount: { amount: '443.49', currency: 'gunthy' },
buyOrSell: 'SELL',
cancelAt: undefined,
cancellationPolicy: 'GOOD_TIL_CANCELLED',
limitPrice: { amount: '0.00000769', currency_a: 'btc', currency_b: 'gunthy' },
marketName: 'gunthy_btc',
nonceOrder: 1461336292,
noncesFrom: [ 68 ],