BBands strategy idea
#1
Information 
i using this strategy and its always work
using the BB indicator , LTC\USTD , 1 min chart .

i choose the last price that the candle touch the lower BB line , and open buy order and wait the price to come down to it , then when the buy already done , i see where BB upper line where and open sell order and wait while the price go up .


so the code have to check when the price hit the lower bb line to buy , then save the upper bb band on that point , then when the if ( price = upper bb for the previous buying price) { sell ; }

im sorry about my bad english .

this strategy always work for me , the problem is i dont know how to automate it .

see the attachment pic , you will understand 


Attached Files
.png   Untitled.png (Size: 159.08 KB / Downloads: 95)
  Reply
#2
Hey,


I tried something quick, and come with this code :

BBandCheck.js :
Code:
/*
    BBands crossing strat
    
    (CC-BY-SA 4.0) ManuManu for Gekko
    Code derived from RSI_BULL_BEAR by Tommie Hansen ( https://github.com/tommiehansen/gekko_tools/tree/master/strategies )
    https://creativecommons.org/licenses/by-sa/4.0/
*/

// req's
var log = require ('../core/log.js');
var config = require ('../core/util.js').getConfig();

// strategy
var strat = {
    
    /* INIT */
    init: function()
    {
        this.name = 'BBandCrossing';
        this.requiredHistory = config.tradingAdvisor.historySize;
        this.resetTrend();
        
        // debug set to false to disable all logging (improves performance)
        this.debug = true;
        
        // add indicators
        this.addTulipIndicator('BBands', 'bbands', { optInTimePeriod: this.settings.TimePeriod, optInNbStdDevs :this.settings.NbStdDevs });
        
        this.sellLimit = 9999999.0;
        
        this.startTime = new Date();
                
        
    }, // init()
    
    resetTrend: function()
    {
        var trend = {
            duration: 0,
            direction: 'none',
            longPos: false,
        };
    
        this.trend = trend;
    },
    /* CHECK */
    check: function()
    {
        if( this.candle.close.length < this.requiredHistory ) { return; } // check if candle length is correct
        
        // get all indicators
        let ind = this.tulipIndicators,
            BBlower = ind.BBands.result.bbandsLower,
            BBupper = ind.BBands.result.bbandsUpper;
            
//            log.debug('BBand : ' + Object.keys(ind.BBands.result) );
            //log.debug('BBAnd : ' + BBlower + " - " + BBupper);
            //log.debug('close : ' + this.candle.close);
            //log.debug('low : ' + this.candle.low);
            
            
        if ( this.candle.low < BBlower )
        {
            if ( this.long() )
            {
                this.sellLimit = BBupper;
                log.debug("sell Limit : " + this.sellLimit );
            }
        }
        
        if ( this.trend.direction =="up" && this.candle.close > this.sellLimit)
        {
            this.short();
        }
    }, // check()
    
    
    /* LONG */
    long: function()
    {
        if( this.trend.direction !== 'up' ) // new trend? (only act on new trends)
        {
            this.resetTrend();
            this.trend.direction = 'up';
            this.advice('long');
            log.debug('go long');
            return true;
        }
        return false;
    },
    
    
    /* SHORT */
    short: function()
    {
        if( this.trend.direction !== 'down' )
        {
            this.resetTrend();
            this.trend.direction = 'down';
            this.advice('short');
            log.debug('go short at ' + this.candle.close);
        }
    },
    
    
    /* END backtest */
    end: function(){
        
        let seconds = ((new Date()- this.startTime)/1000),
            minutes = seconds/60,
            str;
            
        minutes < 1 ? str = seconds + ' seconds' : str = minutes + ' minutes';
        
        log.debug('Finished in ' + str);
    }
    
};

module.exports = strat;

You also need a toml config file for settings :
( I tried the fisrt values google returned me, not sure at all what are the best values : )
BBandCheck.toml :
Code:
# BBand Params :
TimePeriod = 12
NbStdDevs = 2

I tried to backtest it, and it works some times, BUT :
* if you go long, and the asset is then going down, you can reach this situation where you will never going short again, and just loose.
* the other point is that I'm not sure how good Gekko is for 1 minute trading.
I'm not sure how it's working, and AskMike or anyone with more experience could you more, but I have the feeling that with 1 minute candle, your real buy price can be different from the price the strategy was thinking, and so be loosing from this.

Tell us what your experience is with this strategy !!

Any comment on the code also appreciated ( as it's kind of my first own strategy coding )

ManuManu
  Reply
#3
And, by the way, I tried to add a stop loss, but, as always, it's even worse :

When the trend is goind down, the stop loss will sold the position, then the strat will buy another time, and so on.
So basically, you're loosing Sad

ManuManu
  Reply
#4
(02-20-2018, 07:05 PM)ManuManu Wrote: And, by the way, I tried to add a stop loss, but, as always, it's even worse :

When the trend is goind down, the stop loss will sold the position, then the strat will buy another time, and so on.
So basically, you're loosing Sad

ManuManu

Just a friendly heads up: Note that by reusing my code without attribution and claiming the entire thing as your own you are breaking the CC-BY-SA 4.0 license attached to it. Something that is illegal.
As the license state you are free to use, remix and build upon the work but you can't claim authorship of the entire code base and you can't leave out the original author. The CC-BY-SA 4.0 is very clear.
  Reply
#5
ooppss..
Sorry Tommie,

I obviously started with your Bull/Bear strat, and just changed the header without really thinking about it ( and by the way, I didn't put a real name in the copyright part ).

I will change that ( also I'm not sure what is the correct way to change that, tell me if my change is ok for you )

ManuManu
  Reply


Forum Jump:


Users browsing this thread: