BBRSI Stop loss?
#1
I understand that stop loss is a weakness of Gekko right now, at least from what I've read.

However, hope springs eternal!  

Can anyone recommend a stop loss indicator that yields any kind of positive results when testing?  Every stop loss strategy/indicator I've tried seems to only make things worse.  

BBRSI seems to be the most consistent strategy I've tested so far, but it still has large losses from time to time.   A BBRSI_STOPLOSS  strat would be great if stop loss remotely worked.  It seems that after a stop loss occurs, other indicators in a strat can re-trigger a buy right back into another losing situation.  I've tried to modify a stop loss indicator to wait X amount of candles after a stop before allowing other indicators to trigger a buy, but I have yet to see it yield better test results than simply not having a stop loss indicator at all.

Does BBRSI_STOPLOSS exist?
  Reply
#2
hi
I had also tried indicator based stoplosses but the result was:
it would loose only half the bag for a huge stepdown.
Also noticed that additional stoplosses would be good somehow if they all are set somewhat sloppy.

Halve the bag is much better then the full bag AND...
...without stoploss...say a simple RSI strategie, would keep the bag to the bottom.
BUT THEN it must first rise up to the upper RSI threshold in order to sell the bagbefore it can buy again.
That looses one additional trade (buy/sell). Makes two messed up trades without pseudo stoploss.

I also tried using delays but no beneficial results.
while and after the stoploss i also block the rsi like you do thats good.
Then for unlock i use a additional RSI threshold:
Code:
if (this.myrsi > this.settings.RSI.myunlockthreshold && this.lockrsitrader !== false){
    this.lockrsitrader = false;
}
This creates a more dynamique behaviour rather than a blind counter that could miss lot of things.
In the newest version i enhanced this.function by using a seperat RSI for the unlock mechanism and-
i added two thresholds:
say after a massive stepup my strat has ride up and sold at the top.
now my stepup trend logic is finished but the signal is still high so i leave the RSI locked.
To unlock, first the unlockRSI must reach the lower thershold and set another boolean.
now it must reach the higher treshold for unlocking the RSI trader.
Code:
if (this.logic.lockwait !== false)
   {
       if (this.rsireset.lo > this.resetrsi && this.logic.lock !== false)
       {
           this.logic.lock = false;
       }
       if (this.rsireset.hi < this.resetrsi && this.logic.lock !== true)
       {
           this.logic.lockwait = false;
           this.logic.akku = true;
           this.macroReset();
           this.macrotrend.directionlast = this.macrotrend.direction;
           this.macrotrend.direction = 'akku';
       }
   }
//this.resetrsi == signal
//this.rsireset.lo == treshold low...

This works nice and compared with the one threshold solution it creates a directional selection.
For the stoploss itself i found that ALL indicators are based on averaging candle data.
This makes the detection of movement very slow since every new value must fight aginst the past that is no longer true.
Its because of the wild nature of the signals would create so many errors.

to get rid of this.problem i designed my own trendline indicator that works exactly the other way around:
it does the averaging for the trend vectors (support/resistance) BUT the signals for stop/hype are realtime candle.data.
Thats rather neat and it works ;-)

see my other reply:

i developed my own indicator where the RSI trades on the usual trend but for the "super trend" i added a stoploss and a hypetrend-sell-lock.
My macrotrend indicator then begins to sample the lows/highs and if they become valide i back them up into the averaging array.
After that i can calculate the step size to the last low/high in order to calculate the vectors to the present candle.
Theese vectors then have the same angle until a new hi/lo has been backuped/averaged and the vector angle will change.

Backtest results. same strat/settings
please dont mind the comments. its commented for a frind
https://imgur.com/a/JAm5dz3
https://imgur.com/a/jlow72W
https://imgur.com/a/UHiKtlU
https://imgur.com/a/KuGOrWS




From the support vector i can set a % below or above (user.setttings) for calculate the stopvector.
the same for the resistance vector.
the signal that engage the trends and also the signals for the vectors can be choosen:
candle.close
candle.hi
candle.low
candle.vwp (volume wightet price)
candle.myEXPOwhatEvercalculusCurve...hehe

the logic is very simple its only a stoploss and a hype trend but:
if gekko is short and a stepdown occurs, the RSI would buy much to early.
Therefor the stoploss kicks in only to inhibit the RSI from trading.

if gekko is short when a stepup occurs then it instantly trys to buy in and shift over the top before sell.

Its a short term strategie that makes alot of trades but if it goes bearish its beneficial to sell at profit and not keep that hot patatoe.hehe
Tryed to make it even better but it just hurts the basic function when tested over 4/3/2/1month
sometimes a improvement tested over 21days does not work well for 4/3/2/1month
  Reply
#3
(04-24-2018, 08:53 PM)bojim Wrote: I understand that stop loss is a weakness of Gekko right now, at least from what I've read.

However, hope springs eternal!  

Can anyone recommend a stop loss indicator that yields any kind of positive results when testing?  Every stop loss strategy/indicator I've tried seems to only make things worse.  

BBRSI seems to be the most consistent strategy I've tested so far, but it still has large losses from time to time.   A BBRSI_STOPLOSS  strat would be great if stop loss remotely worked.  It seems that after a stop loss occurs, other indicators in a strat can re-trigger a buy right back into another losing situation.  I've tried to modify a stop loss indicator to wait X amount of candles after a stop before allowing other indicators to trigger a buy, but I have yet to see it yield better test results than simply not having a stop loss indicator at all.

Does BBRSI_STOPLOSS exist?


bojim,

I created a video on how to setup stop loss for BBRSI. 

D.Tube - Gekko Trading Bot - Adding Stop Loss
If it isn't crypto, it isn't worth mining, it isn't worth speculating.
https://www.youtube.com/c/crypto49er
  Reply
#4
Hi
Very nice video. Thanks good explanation!
  Reply
#5
Maybe its Your repo, I dont know: https://github.com/krisstox/gekko-strategies
My projects [Strategies] [Datasets]
  Reply
#6
(04-26-2018, 12:47 PM)crypto49er Wrote: bojim,

I created a video on how to setup stop loss for BBRSI. 

D.Tube - Gekko Trading Bot - Adding Stop Loss


Very informative video, thanks!

I've tried something similar a couple of times.  My issue has been that the other indicators often re trigger a buy right away and send the strategy back into another loss scenario.  

I will give your suggestions a try and see if it helps.



Thanks also susitronix for the detailed response. 

My current BBRSI in live trading has had modest gains at times, but then tends to take a large loss to wipe out any gains.  I'm hoping this information will improve the strategy.
  Reply
#7
For sake of conversation, here's my dilemma... 

I back test BBRSI from 01-01-18 - 04-15-18 - gdax - USD & LTC - profit 143.93787%

Code:
interval = 14

[thresholds]
low = 40
high = 40
persistence = 9

[bbands]
TimePeriod = 20
NbDevUp = 2
NbDevDn = 2

Then I test the BBRSI-SL in this thread which looks like the same code that's in the video.

If I set stoploss percentage to 100 - (basically no stop loss) I get the exact same results for the same pair and date range: 143.93787%

If I add the stoploss percentage to 3, my profit changes to 59.60740% for the same test.  Adding this simple stop loss approach, seems to further reduce gains.  Please note this is just default settings, I've not put it through any of genetic algorithm tests yet.

In live trading so far, BBRSI rarely takes more than a 1% profit, and it can have several positive trades before encountering a negative one.  However it seems that the negative side is always far more severe and eats back into the gains quickly. 

Still a novice...  will be taking a closer look at susitronix suggestions.

Thanks!
  Reply
#8
(05-03-2018, 04:51 PM)bojim Wrote: For sake of conversation, here's my dilemma... 

I back test BBRSI from 01-01-18 - 04-15-18 - gdax - USD & LTC - profit 143.93787%

Code:
interval = 14

[thresholds]
low = 40
high = 40
persistence = 9

[bbands]
TimePeriod = 20
NbDevUp = 2
NbDevDn = 2

Then I test the BBRSI-SL in this thread which looks like the same code that's in the video.

If I set stoploss percentage to 100 - (basically no stop loss) I get the exact same results for the same pair and date range: 143.93787%

If I add the stoploss percentage to 3, my profit changes to 59.60740% for the same test.  Adding this simple stop loss approach, seems to further reduce gains.  Please note this is just default settings, I've not put it through any of genetic algorithm tests yet.

In live trading so far, BBRSI rarely takes more than a 1% profit, and it can have several positive trades before encountering a negative one.  However it seems that the negative side is always far more severe and eats back into the gains quickly. 

Still a novice...  will be taking a closer look at susitronix suggestions.

Thanks!

bojim,

What did you set for the candle size and the warmup period? I just want to replicate what you are getting and see if I can figure out why.

My best guess without knowing specifics is the modified stop-loss strategy holds through some of sideway trades that BBRSI normally makes money on. So it trades significantly less and performs significantly worse than the default strategy.

*Update: The strategy itself prevents selling at a loss of over 3%, so it doesn't actually sell at a stop loss of 3%. Although I think I made it this way because the strategy would have bought right back in because all conditions are still valid in the candle after selling. But let me cobble the code together so you can confirm as well.
If it isn't crypto, it isn't worth mining, it isn't worth speculating.
https://www.youtube.com/c/crypto49er
  Reply
#9
bojim,

I was wrong. And I'm happy to be! I'm glad you asked more questions about it. 

I just correctly implemented stop loss this time. The simple idea is to send a sell signal in a separate if statement that checks the buy price vs. the current price. 

The code is below:

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 advised = false;
var buyPrice = 0.0;

// 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);
}


// 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;

 // price Zone detection
 var zone = 'none';
 if (price >= BB.upper) zone = 'top';
 if ((price < BB.upper) && (price >= BB.middle)) zone = 'high';
 if ((price > BB.lower) && (price < BB.middle)) 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 (!advised && price <= BB.lower && rsiVal <= this.settings.thresholds.low && this.trend.duration >= this.settings.thresholds.persistence) {
   this.advice('long');

   advised = true;
   buyPrice = candle.close;

 }

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

 if (advised && price >= BB.middle && rsiVal >= this.settings.thresholds.high) {
   this.advice('short');
   advised = false;


 }

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


}

module.exports = method;
Here is the TOML file: 
Code:
interval = 14

[thresholds]
low = 40
high = 40
persistence = 9

[bbands]
TimePeriod = 20
NbDevUp = 2
NbDevDn = 2

#Should be a number between 1 - 99
[stoploss]
percentage = 3

I eventually will put this on a Github repo somewhere. But honestly it wasn't that much of a contribution.
So I tested it and confirmed that it works. It does, although there will be times when you will lose more than 3% as it depends on the duration of your candles (the longer, the higher the chance of losing more than 3%). It still took off the more damaging trades than the original so it performs another 5% better in the date range that you were testing.

Original:
[Image: kYxBpAM.png]
With Stop Loss:
[Image: Va3Qd4f.png]
Hope this helps!
If it isn't crypto, it isn't worth mining, it isn't worth speculating.
https://www.youtube.com/c/crypto49er
  Reply
#10
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]


Attached Files
.png   Capture.PNG (Size: 21.87 KB / Downloads: 422)
  Reply


Forum Jump:


Users browsing this thread: