Ichimoku Indicator
#3
Hi PatTrends,

I work too on a strategie based on Ichimoku.

This is base on the NPM package "Ichimoku" but the current version do not include "laggingspan" (chikou) who is a great indicator.

Here my starting code. Maybe somone can improve it.


First of all you have to install the npm package ichimoku on the root of the gekko folder :

Code:
npm install --save ichimoku

Then add the following file strategies/Ichimoku.js

Code:
var log = require('../core/log');
var config = require ('../core/util.js').getConfig();
var Ichimoku = require("ichimoku");

var strat = {};

// Prepare everything our method needs
strat.init = function() {
    this.ichimoku = new Ichimoku({
        conversionPeriod : this.settings.conversionPeriod,
        basePeriod       : this.settings.basePeriod,
        spanPeriod       : this.settings.spanPeriod,
        displacement     : this.settings.displacement,
        values           : []
    });

    this.requiredHistory = 82;
    this.oldIchimokuValue = null;
    this.ichimokuValue = null;
    this.wait_price_over_cloud = false;
    this.wait_price_under_cloud = false;
}

// What happens on every new candle?
strat.update = function(candle) {
    
    var updateIchimokuValue = this.ichimoku.nextValue({
       high  : candle.high,
       low   : candle.low,
       close : candle.close
   });
    
    
    this.oldIchimokuValue = (this.ichimokuValue ? this.ichimokuValue : null);
    this.ichimokuValue = {
        tenkan: (updateIchimokuValue ? updateIchimokuValue.conversion : 0),
        kijun: (updateIchimokuValue ? updateIchimokuValue.base : 0),
        spanA: (updateIchimokuValue ? updateIchimokuValue.spanA : 0),
        spanB: (updateIchimokuValue ? updateIchimokuValue.spanB : 0)
    }
    
}

strat.check = function() {

    // Check Kijun over Tenkan
    kijun_over_before_last = (this.oldIchimokuValue.tenkan >= this.oldIchimokuValue.kijun) ? false : true;
    kijun_over_last = (this.ichimokuValue.tenkan >= this.ichimokuValue.kijun) ? false : true;
    kijun_crossing_tenkan = (kijun_over_before_last == false && kijun_over_last == true) ? true : false;
    // Check Tenkan over Kijun
    tenkan_over_before_last = (this.oldIchimokuValue.kijun >= this.oldIchimokuValue.tenkan) ? false : true;
    tenkan_over_last = (this.ichimokuValue.kijun >= this.ichimokuValue.tenkan) ? false : true;
    tenkan_crossing_kijun = (tenkan_over_before_last == false && tenkan_over_last == true) ? true : false;

    var sell_signal = false;
    // SELL signal 1 : Kijun over Tenkan
    if((kijun_crossing_tenkan || this.wait_price_under_cloud)){
        if(this.candle.close < Math.max(this.ichimokuValue.spanA,this.ichimokuValue.spanB)){
            sell_signal = true;
            this.wait_price_over_cloud = false;
            this.wait_price_under_cloud = false;
            log.debug("[INFO] SELL signal - " + this.wait_price_under_cloud);
        }
        else{
            log.debug("[INFO] Kijun over Tenkan BUT wait price under the cloud");
            this.wait_price_under_cloud = true;
        }
        
    }
    // Add here other SELL signals
    // SELL actions
    if(sell_signal){    
        this.advice('short');
    }
    // Find BUY signals
    var buy_signal = false;
    // BUY signals 1 : Tenkan over Kijun and price over Span
    if((tenkan_crossing_kijun || this.wait_price_over_cloud)){
        if(this.candle.close > Math.max(this.ichimokuValue.spanA,this.ichimokuValue.spanB)){
            buy_signal = true;
            this.wait_price_over_cloud = false;
            this.wait_price_under_cloud = false;
            log.debug("[INFO] BUY signal");
        }
        /*
        else{
            log.debug("[INFO] Tenkan over Kijun BUT wait price over the cloud");
            this.wait_price_over_cloud = true;
        }
        */
    }
    // Add here other BUY signals
    // BUY actions
    if(buy_signal){        
        this.advice('long');
    }
}

module.exports = strat;

Then add the following file config/strategies/Ichimoku.toml

Code:
# Ichimoku settings
conversionPeriod = 9
basePeriod = 26
spanPeriod = 52
displacement = 26
  Reply


Messages In This Thread
Ichimoku Indicator - by PatTrends - 02-28-2018, 10:18 PM
RE: Ichimoku Indicator - by PatTrends - 03-01-2018, 02:12 PM
RE: Ichimoku Indicator - by Fizcko - 03-01-2018, 05:01 PM
RE: Ichimoku Indicator - by muditgrover - 03-09-2018, 09:20 AM
RE: Ichimoku Indicator - by edoe - 03-10-2018, 06:09 AM
RE: Ichimoku Indicator - by PatTrends - 03-03-2018, 08:00 PM
RE: Ichimoku Indicator - by riesgo.rafael - 03-13-2018, 01:51 AM
RE: Ichimoku Indicator - by Kris191 - 03-14-2018, 05:15 AM
RE: Ichimoku Indicator - by PatTrends - 03-20-2018, 09:36 PM
RE: Ichimoku Indicator - by palofug87 - 05-27-2018, 04:19 PM
RE: Ichimoku Indicator - by PatTrends - 05-29-2018, 02:42 AM
RE: Ichimoku Indicator - by palofug87 - 05-29-2018, 09:19 PM
RE: Ichimoku Indicator - by PatTrends - 05-31-2018, 06:44 PM
RE: Ichimoku Indicator - by ardialamwijaya - 11-07-2019, 04:16 AM

Forum Jump:


Users browsing this thread: