[SHARE] Simple RSI BULL/BEAR strategy
(03-19-2018, 09:49 PM)jvs Wrote:
(03-19-2018, 05:53 AM)tommiehansen Wrote:
(03-18-2018, 11:30 PM)jvs Wrote: Gentleman - over the weekend I left a box running testing different settings on the strategy.

I set it to change 4 settings:

Candle size: From 300 seconds (5 minutes) to 3600 seconds (1 hour), in steps of 1 minute.
SMA Fast Period: From 20 periods to 95 periods, in steps of 5.
SMA Slow Period: From 100 periods to 2000 periods, in steps of 20.
ADX Period: From 2 periods to 20 periods, in steps of 1.

So, 1.4 odd million tests later - testing on a dataset of ETH/USDT from 1/1/2016 to 1/3/2018, the setting that came out tops was....(drum roll)

Candle size: 480 seconds (8 minutes)
SMA Fast Period: 95
SMA Slow Period: 200
ADX Period: 3

The default settings of candle size 15 minutes, SMA Fast of 50 periods and slow of 1000 periods, results in a return of around 242,621%

Good for you, do note that the default is the default though and will not be optimized for anything basically. Smile

I'll also ramp up testing since i've just finished making something usable of the PHP-stuff i've been writing that makes it simpler to do brute-force tests with more dynamic parameters. Something that is needed to really test something and where the run time can be over 20 hours (and over 5000 runs per go) and so on, here's a screen of the current 'run screen':
https://i.imgur.com/j5I3eWH.png

There just isn't any feasible way of testing things 'for real' with the current Gekko UI.

How do you think you will go about looping through the different ranges?

I just used a whole bunch of nested for loops... I can't help but think there is a better way...

Code:
foreach (range(300, 3600, 60) as $candle){
    foreach(range(20,95,5) as $smaFastPeriod){
        foreach(range(100,2000,20) as $smaSlowPeriod){
            foreach(range(2,20,1) as $adxPeriod){

You just take min/max/stepping, create a range out of it and choose a random value out of it.
Why would you bloody hardcode the params ... ?

Say this is my format:
SMA_short = 10:100,10
RSI = 5:15,5

MIN/MAX/STEPPING

Just create a range out of it and select one random via shuffle() or any other random func (which is best depends on PHP-version... i suggest using 7.1+):

PHP Code:
// loop all lines
$lines preg_split("/((\r?\n)|(\r\n?))/"$params);
$new '';
$hasError false;

foreach(
$lines as $line)
 
 {
 
 if (contains(':'$line))
 
   {

 
   // all lines must has equals sign so use to explode

 
   $lineArr explode('='$line);
 
   $vals rmspace($lineArr[1]);
 
   $vals str_replace(','':'$vals); // make all separators : for simplicy
 
   $vals explode(':'$vals); // create array

 
   // get min/max

 
   $min $vals[0];
 
   $max $vals[1];

 
   // error check

 
   if (!empty($vals[2]))
 
     {

 
     // not empty, get stepping

 
     $step $vals[2];
 
     }
 
     else
      
{
 
     $hasError[] = 'No stepping set. Format is min:max,stepping';
 
     continue;
 
     }

 
   // generate entire range

 
   $range range(0$max$step);

 
   // ..then remove all under $min

 
   foreach($range as $key => $val)
 
     {
 
     if ($range[$key] < $min) unset($range[$key]);
 
     }

 
   // ...and add back $min

 
   $range[0] = $min;

 
   // all above is due to the fact that range() is inclusive and thus we need this logic
 
   // TODO: make a function out of this
 
   // shuffle and get first from shuffled

 
   shuffle($range);
 
   $range $range[0];

 
   // put back at line

 
   $new.= $lineArr[0] . '= ' $range "\n";
 
   }

 
 // else just add to new lines

 
   else
    
{
 
   $new.= $line "\n";
 
   }
 
 

This is just a sample that would take input from e.g. a textarea etc.
rmspace() will not exist since it's a custom function (it just cleans any spaces, tabs etc that might exist) etc but you get the point (or if not -- this is beyond your coding ability, sorry).
  Reply


Messages In This Thread
Werkkrew Stoploss - by susitronix - 02-02-2018, 09:39 PM
Removed post - by susitronix - 02-03-2018, 06:49 PM
@Gryphon Confirmation - by mvangoor - 03-22-2019, 11:59 PM
for 3 months - by ankasem - 02-18-2018, 05:30 PM
RE: [SHARE] Simple RSI BULL/BEAR strategy - by tommiehansen - 03-20-2018, 12:02 PM

Forum Jump:


Users browsing this thread: