Indicators based on HIGH and LOW values
#1
Hi all,

first of all, after having some issues with older gekko versions the current one is working like a charm. Thanks for all the great work!

I created some strategies that work fine and sure, after successfully testing more deeply I will share those here...

For my next "project" I want to create a trading strategy that works great in FOREX markets to verify if it can be used for crypto currencies, too. This strategy is based on two SMAs with the same period but calculated based on the HIGH and LOW values of the candles.

And that's why I kindly ask the community to point me to the right direction:

As I've seen all indicators (gekko, talib, tulip) are calculated based on the CLOSE values (please correct me if I'm wrong). 

Is there a way to do what I explained above? If yes, how can this be achieved?

Many thanks for your support.

Best regards,
Christian
  Reply
#2
So i would do this:

1. You do got access to this inside check() in your strategy:
this.candle.high
this.candle.low
...etc...


So...
2. Write a simple func for sma to just run the calc inline and get the sma-values

Here's a simple sma-function:

Code:
// simple sma function
// params: name-of-array, price (of something), number of points (sma lenght)
// returns: the moving average price/value
sma: function(name, price, points)
   {
       // create arr if not exist + generate array
       if( !this[name] )
              {
           let a = 0,     b = [];
           for (a; a < points; a++) { b[a] = 0; }
           this[name] = b;
       }

       let arr = this[name],
           len = arr.length;

       arr[len] = price; // add new to last in array
       arr.shift(); // remove first (old) from array (keeping max order)        
       this[name] = arr; // set/save

       // calculate current average
       let i = 0,
            total = 0;

       for( i; i < len; i++ ) { total += arr[i]; }
   
       let avg = total / len;
       return avg;
   },


Use inside the strategy you're creating.

var strat = {

 // init
 init: function(){
     // your init stuff
 },

 sma: function(){
    // the SMA-code...
  },

 check: function(){
   // get sma-values for candle.high and candle.low
   let sma_high = this.sma('sma_high', this.candle.high, 10);
   let sma_low = this.sma('sma_low', this.candle.low, 10);

   // the rest of your logic, simple sample:
   if( sma_high < sma_low ) this.advice('long')
   else this.advice('short')
 }

}

Do note that this is untested, but you should get the gist of it.....
  Reply
#3
Hi Tommie,

many thanks for your suggestion - I will give it a try...

After digging around I found the files for the "internal" indicators in <gekko-home>/strategies/indicators. So, my second approach is to create 2 additional indicators (SMAHIGH.js, SMALOW.js) - as copies of SMA.js - and use candle.high/candlelow instead of price. This would make it more reusable.

My only doubt is if this will still be "upgrade safe"...

Btw, your RSI Bull/Bear (ADX) strategy is ingenious!!!

Best regards,
Christian
  Reply


Forum Jump:


Users browsing this thread: