How To Develop Strategy For Gekko Bot

A complete guide to Gekko bot codes and instruction to start automatic trading on crypto exchange platforms.

How To Develop Strategy For Gekko Bot

In continuation of crypto trading bot series, we've already learned about How To Install Gekko Trading Bot. Today we're going to understand how to develop strategy for cryptocurrency trading using Gekko Bot.

What is Strategy?

A trading strategy is a predetermined plan intended to produce a positive return by going long or short on markets. The key reasons that a well-researched trading approach helps are its verifiability, quantifiability, accuracy and objectivity.
It is a system of buying and selling in markets that is based on predefined principles that are used to make trading decisions.


Procedure

Step 1 : Creating a Strategy

Strategies are at the center of Gekko's trading operation. They look at the competition and decide what to do based on metrics of technical research. A single approach is limited to a single exchange market.

Gekko comes up with a few inbuilt strategies of its own. Besides those, we can write our approach to a strategy in javascript.

Step 2(a) : Strategy's Boilerplate

Boilerplate is any written document that can be reproduced in new contexts or implementations without major modifications to the original text.

// Let's create our own strategy
var strat = {};

// Prepare everything our strat needs
strat.init = function() {
  // your code!
}

// What happens on every new candle?
strat.update = function(candle) {
  // your code!
}

// For debugging purposes.
strat.log = function() {
  // your code!
}

// Based on the newly calculated
// information, check if we should
// update or not.
strat.check = function(candle) {
  // your code!
}

// Optional for executing code
// after completion of a backtest.
// This block will not execute in
// live use as a live gekko is
// never ending.
strat.end = function() {
  // your code!
}

module.exports = strat;

Step 2(b) : Understanding Strategy's Boilerplate

The boilerplate above comprises four functions. Their execution is done by Gekko.

Starting Gekko :

run init

On Each New Candle :

A candlestick is a type of price chart used in a technological analysis that indicates high , medium, open and closed security values over a certain period of time.

run update

// once the strategy has completed warmup then

run log
run check
  • init function ;

Executed as the trading plan begins. Your approach will initialize indicators for status and registration.

In the scope of technical analysis, the indicator is a statistical measure dependent on the price and/or volume of the security. The outcome can be used to forecast future costs.

  • update function ;

This feature will run on a fresh candle. You can view the current candle as the first (and only) parameter (also contained in this.candle).

  • log function ;

The log function is executed on a new candle while the debug flag is on (always off when operating in the UI, as configured in the CLI gekkos configuration). Logging is used to log a certain state of the plan and can be used to debug the strategy to obtain further insight into whether certain actions have been made.

CLI is command line input

  • check function ;

Many tactics need to be warmed up before a trading plan can be launched. For example, the strategy will measure the moving average for the first 3 candles, since it must have at least 3 candles to generate a number on which the strategy reasoning relies. The check feature is performed after the warm-up cycle is done. The default history needed is 0.

Setting up init function :

this.requiredHistory = 5;
// require 5 candles before giving advice

Setting up advice function :

this.advice({
  direction: 'long', // or short
  trigger: { // ignored when direction is not "long"
    type: 'trailingStop',
    trailPercentage: 5
    // or:
    // trailValue: 100
  }
});
  • candle variables ;

The following list of candle variables will be accessible when writing techniques, they are part of the candle object that is given to your update and check functions (this.candle can also be accessed).

candle.close //the closing price of the candle
candle.high //the highest price of the candle
candle.low //the lowest price of the candle
candle.volume //the trading volume of that candle
candle.trades //number of trades in that candle

Step 2(c) : Points to Remember

  • By config.tradingAdvisor.strategy to configure (or something you have called your file inside the gekko/strategies) in your loaded configuration, you can trigger your own strategy.

  • For each new candle, Gekko will perform the update operation. The candle in a config.tradingAdvisor.candleSize in the loaded configuration is configured within minutes.

  • It is recommended to use this property to set historical config.tradingAdvisor.historySize to build an initial batch of candles.

  • Never depend on system time, as both on live and backtesting can be achieved by any process. You will see the property candle.start and is an entity for the moment when candles began.

Step 3 : Strategy Tools

  • Indicators ;

In addition to adding indicators from the library TAlib. Gekko natively supports a few indicators.

// add a native indicator
this.addIndicator('name', 'type', parameters);

// add a TA-lib indicator
this.addTalibIndicator('name', 'type', parameters);

// add a Tulip indicator
this.addTulipIndicator('name', 'type', parameters);

The first parameter is the name, the second is the type of indicator you want, and the third is an object with all the parameters of the indicator.

If we want to use an MACD indicator then :

In your init function:

var parameters = {short: 10, long: 20, signal: 9};
this.addIndicator('mynativemacd', 'MACD', parameters);

// add a TA-lib indicator
var parameters = {optInFastPeriod: 10, optInSlowPeriod: 21, optInSignalPeriod: 9};
this.addTalibIndicator('mytalibmacd', 'macd', parameters);

// add a Tulip indicator
var parameters = {optInFastPeriod: 10, optInSlowPeriod: 21, optInSignalPeriod: 9};
this.addTulipIndicator('mytulipmacd', 'macd', parameters);

In your check or update function:

var result = this.indicators.mytalibmacd.result;

Step 4 : Strategy Parameters

Change the implementation of strategy by developing custom strategy parameters. In this way, the same approach can be applied simultaneously using various criteria for different markets.

In a MACD ; Strategy has parameters concerning the underlying MACD indicator (such as values for the LONG and SHORT EMAs). Create custom configuration settings in the config/strategies directory:

// custom settings:
config.custom = {
  my_custom_setting: 10,
};

Retrieve them in our the strategy :

// anywhere in your code:
log.debug(this.settings.my_custom_setting); // Logs 10

Our configuration name shall be the same as the strategy name

  • External Libraries

Gekko uses internally a few general purpose libraries. The API from such repositories are open to you as well. Lodash and async are the most notable libraries.

// before any other code
var _ = require('lodash');
var async = require('async');
  • Logging

Gekko has a tiny logger that we can use (preferably in our log function)

// before any other code
var log = require('../core/log.js');

// in your log function
log.debug('hello world');

Implementing strategies on computer system allow Gekko bot in collecting data and successfully trading on cryptocurrency exchange. We hope that we answered all your doubts. For more on blockchain, technology and projects visit Tutorials at EtherWorld.co.

Merge

Also read:

________________________________________________________

Disclaimer: The information contained on this web page is for education purpose only. Readers are suggested to conduct their own research, review, analyze and verify the content before relying on them.

To publish press releases, project updates and guest posts with us, please email at contact@etherworld.co.

Subscribe to EtherWorld YouTube channel for easy digestable content.

Support us at Gitcoin

You've something to share with the blockchain community, join us on Discord!

Follow us at Twitter, Facebook, LinkedIn, and Instagram.


Share Tweet Send
0 Comments
Loading...
You've successfully subscribed to EtherWorld.co
Great! Next, complete checkout for full access to EtherWorld.co
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.