BBRSI Stop loss?
#11
(05-06-2018, 11:30 PM)bojim Wrote: Thanks for the update.  The candle size is 10 minutes.

Quick check of the new changes and the profit dropped even further to 50.41266% using the same settings with 3% stop loss.

This is an example of the the bad trade tendency after stop loss.

[Image: attachment.php?aid=118]


First, let's take a look at how the original does during that same time frame. It makes the same bad trade at 2/2 5:30 AM. But then it doesn't enter back into a position until the next day. 


.png   2018-05-07 10_48_28-Gekko.png (Size: 19.71 KB / Downloads: 26)

Now, in the picture you uploaded in the previous post, I circled (sorry, couldn't find my highlighter in Windows 10 Photo) every time it entered into a trade right after it exited after a stop-loss. It didn't seem like it entered right back into the market after exiting, but then I remember this is 10 minute candles and that is exactly what it's doing.


.png   InkedBBRSI - LTC fail_LI.png (Size: 239.76 KB / Downloads: 24)

So essentially, a stop loss alone isn't enough. You need to modify the logic behind when it buys into the market. I might take another crack at it if I can get Gab0's Japonicus working today (it's not related, but I am working on making a video about that today).
If it isn't crypto, it isn't worth mining, it isn't worth speculating.
https://www.youtube.com/c/crypto49er
  Reply
#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
#13
(05-08-2018, 04:55 PM)crypto49er Wrote: 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:


With Stop Loss:


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.

You're awesome just for the effort alone.

I'll take a look at the new changes ASAP.

Thanks!
  Reply


Forum Jump:


Users browsing this thread: