Need some help to create strategy
Hello Gekko...!!!
I Love Gekko so much and i appreciated.
i want to implement a strategy that depend on price of coin, for example: if bitcoin hits 12000 dollar threshold i want to purchase .5 btc. and set flag to sell position hold it for second threshold that is 13500 and sell .5 bitcoin for 13500 dollar. after that set flag to buy position again.

any help will be appritiated...

Hi, this strategy will only work in an uptrend. What about a downtrend? What if the price dropped to $9850, after you bought at $12,000. See? But if you still want the strategy, I can guide you through it.
There is a sample on the website.

// Let's create our own buy and sell strategy
var strat = {};

// Prepare everything our strat needs
strat.init = function() {
// setting buy price
this.buyPrice = 2000;

// setting sell price
this.sellPrice = 2500;

// What happens on every new candle?
strat.update = function(candle) {
// your code!

// For debugging purposes.
strat.log = function() {
// your code!

// Based on the newly calculated
// information, check if we should
// update or not.
strat.check = function(candle) {
// buy when it hits buy price
if(candle.close <= this.buyPrice) {
// do some output
console.log("buying BTC @", candle.close);

// sell when it hits sell price
if(candle.close >= this.sellPrice) {
// do some output
console.log("selling BTC @", candle.close);
console.log("Profit:", (candle.close-this.buyPrice));

module.exports = strat;

I am trying to use it myself, the only problem i have is for buying, it does not place the order at the expected price.
For example, lets say the price is setup for buy at $3.002, it will submit the order for 3, instead of 3.002.
Does anyone know why this is?
How to add stoploss into above example?
If I add variable this.stopPrice=1950;
What should be in the function? Please help.

If( .... ){
it would be useful to use Boolean logic in order to declare the states.
if (this.stopState ==true)
     {trigger your stoploss}

i made a tutorial about my dynamique stoploss

maybe you find also usfull stuff in my other tutorials:
TUT#1 BASSic RSI (very basix)

implementing indicators from the Tulip library
thats a nice idee but you could make it Dynamique by using a very simple procent calculation out of the candle.price (of intrest..high...low...close).

you would store the goLong/goShort price and make +-% price out of it, instead of a fixed price.
the procentage can be set in the settings...
>>>for goLong and goShort

if you are new to javascript you could look at my tutorials:


if you stuck in coding let the blog know to get some help

Forum Jump:

Users browsing this thread: