BBRSI Stop loss?
#12
I tried, and I failed...

I tried a whole bunch of other things first, like adding another price zone, changing the threshold when a stop loss is initiated, adding another RSI so it switches to a slower RSI after stop loss (similar to how RSI Bull Bear switches RSI), adding +DI/-DI indicator to indicator, but none of those work in that they all performed worse than the original.

Then I remember what I said yesterday. You need to modify the logic for when it buys into the market so it doesn't buy back in immediately after the stop loss executes and takes as many stop loss as necessary until the buy conditions no longer apply. 

So here's the code (it might be a little messy, but it's really for reference):
Code:
/*

BB strategy - okibcn 2018-01-03
With Stop Loss - Crypto49er 2018-05-03

*/
// helpers
var _ = require('lodash');
var log = require('../core/log.js');

var BB = require('./indicators/BB.js');
var rsi = require('./indicators/RSI.js');
var rsiLong = require('./indicators/RSI.js');


var advised = false;
var buyPrice = 0.0;
var slTriggered = false;

// let's create our own method
var method = {};

// prepare everything our method needs
method.init = function () {
this.name = 'BB';
this.nsamples = 0;
this.trend = {
  zone: 'none',  // none, top, high, low, bottom
  duration: 0,
  persisted: false
};

this.requiredHistory = this.tradingAdvisor.historySize;

// define the indicators we need
this.addIndicator('bb', 'BB', this.settings.bbands);
this.addIndicator('rsi', 'RSI', this.settings);
this.addIndicator('rsiLong', 'RSI', { interval: 96 });
}


// for debugging purposes log the last
// calculated parameters.
method.log = function (candle) {
// var digits = 8;
// var BB = this.indicators.bb;
// //BB.lower; BB.upper; BB.middle are your line values

// log.debug('______________________________________');
// log.debug('calculated BB properties for candle ', this.nsamples);

// if (BB.upper > candle.close) log.debug('\t', 'Upper BB:', BB.upper.toFixed(digits));
// if (BB.middle > candle.close) log.debug('\t', 'Mid   BB:', BB.middle.toFixed(digits));
// if (BB.lower >= candle.close) log.debug('\t', 'Lower BB:', BB.lower.toFixed(digits));
// log.debug('\t', 'price:', candle.close.toFixed(digits));
// if (BB.upper <= candle.close) log.debug('\t', 'Upper BB:', BB.upper.toFixed(digits));
// if (BB.middle <= candle.close) log.debug('\t', 'Mid   BB:', BB.middle.toFixed(digits));
// if (BB.lower < candle.close) log.debug('\t', 'Lower BB:', BB.lower.toFixed(digits));
// log.debug('\t', 'Band gap: ', BB.upper.toFixed(digits) - BB.lower.toFixed(digits));

// var rsi = this.indicators.rsi;

// log.debug('calculated RSI properties for candle:');
// log.debug('\t', 'rsi:', rsi.result.toFixed(digits));
// log.debug('\t', 'price:', candle.close.toFixed(digits));
}

method.check = function (candle) {
var BB = this.indicators.bb;
var price = candle.close;
this.nsamples++;

var rsi = this.indicators.rsi;
var rsiVal = rsi.result;

var rsiLong = this.indicators.rsiLong;
var rsiLongVal = rsiLong.result;


// price Zone detection
var zone = 'none';
if (price >= BB.upper) zone = 'top';
if ((price < BB.upper) && (price > BB.middle * 1.01)) zone = 'high';
if ((price <= BB.middle * 1.1) && (price >= BB.middle * 0.9)) zone = 'middle';
if ((price > BB.lower) && (price < BB.middle * 0.99)) zone = 'low';
if (price <= BB.lower) zone = 'bottom';
log.debug('current zone:  ', zone);
log.debug('current trend duration:  ', this.trend.duration);

if (this.trend.zone == zone) {
  this.trend = {
    zone: zone,  // none, top, high, low, bottom
    duration: this.trend.duration+1,
    persisted: true
  }
}
else {
  this.trend = {
    zone: zone,  // none, top, high, low, bottom
    duration: 0,
    persisted: false
  }
}

if (slTriggered){
 if (!advised && price >= BB.middle && rsiVal >= this.settings.thresholds.high) slTriggered = false;
} else {
 if (!advised && price <= BB.lower && rsiVal <= this.settings.thresholds.low && this.trend.duration >= this.settings.thresholds.persistence) {
   this.advice('long');
   log.debug("Bought at", candle.close);
   log.debug('Date', candle.start);
   log.debug('RSI', rsiVal, 'RSI Long', rsiLongVal);

   advised = true;
   buyPrice = candle.close;

 }
}

if (advised && price >= BB.middle && rsiVal >= this.settings.thresholds.high) {
 this.advice('short');
 log.debug('Date', candle.start);
 log.debug("Sold at", candle.close);
 log.debug('RSI', rsiVal, 'RSI Long', rsiLongVal);
 advised = false;


}

if (advised && buyPrice > candle.close * (1 + this.settings.stoploss.percentage * .01)){
 log.debug('Date', candle.start);
 log.debug("Stop loss triggered, sell at", candle.close);
 log.debug('RSI', rsiVal, 'RSI Long', rsiLongVal);
  this.advice('short');
  advised = false;
  slTriggered = true;
}



// this.trend = {
//   zone: zone,  // none, top, high, low, bottom
//   duration: 0,
//   persisted: false


}

module.exports = method;

The idea here is the bot is restricted from buying until the sell conditions it looks for is met. Then the restriction is lifted. This way, the bot thinks it is still hodling even though it has sold at stop loss. This works as described. But then the problem is this: the trades that the bot was stopped out usually end up losing less than the stop loss amount (or might even turn positive) had the bot stayed in the trade instead of stopping out. 

Here's an example. Look at 3/9 2:30 and 3/10 18:50.

Original strategy:

.png   Screen Shot 2018-05-08 at 12.20.37 PM.png (Size: 66.36 KB / Downloads: 34)

With Stop Loss:

.png   Screen Shot 2018-05-08 at 12.19.02 PM.png (Size: 66.3 KB / Downloads: 32)

The original end up losing ~1% less in both trades because it stayed in for twice as long (4 hours instead of 2 hours). Even though the stop loss strategy had a gain over the original in the 3/14 5:30 trade, cumulatively, the original will always do better. I tried adjusting the stop loss percentage but no matter what the original will do better. 

This comes back down to the nature of crypto. It is a highly speculative instrument but 90% (pulling this number from thin air) of people are extremely bullish in the long run (think McAfee). In the past month that I had been swing trading, I had been way more successful when I didn't have any stop loss in place. This has to do with the general switch in trend from bear to bull, but it alway comes back to hodling rather than taking a "L". With the BBRSI strategy, it only takes  an "L" because there will be more opportunity for gains in the very near term. 

I think the best way for people that are risk adversed to use these strategies is once you see a significant profit (>30%), take that percentage out of control from the bot. Repeat this until you reach a comfortable level of acceptable losses. If you do this 3x, you practically have the bot trade with house money.
If it isn't crypto, it isn't worth mining, it isn't worth speculating.
https://www.youtube.com/c/crypto49er
  Reply


Messages In This Thread
BBRSI Stop loss? - by bojim - 04-24-2018, 08:53 PM
Stop loss? - by susitronix - 04-25-2018, 12:59 AM
RE: BBRSI Stop loss? - by crypto49er - 04-26-2018, 12:47 PM
RE: BBRSI Stop loss? - by susitronix - 05-02-2018, 10:41 AM
RE: BBRSI Stop loss? - by bojim - 05-03-2018, 04:06 PM
RE: BBRSI Stop loss? - by xFFFFF - 05-02-2018, 12:05 PM
RE: BBRSI Stop loss? - by bojim - 05-03-2018, 04:51 PM
RE: BBRSI Stop loss? - by crypto49er - 05-03-2018, 08:16 PM
RE: BBRSI Stop loss? - by crypto49er - 05-03-2018, 09:27 PM
RE: BBRSI Stop loss? - by bojim - 05-06-2018, 11:30 PM
RE: BBRSI Stop loss? - by crypto49er - 05-07-2018, 03:08 PM
RE: BBRSI Stop loss? - by crypto49er - 05-08-2018, 04:55 PM
RE: BBRSI Stop loss? - by bojim - 05-09-2018, 06:26 PM

Forum Jump:


Users browsing this thread: