Need some help to create strategy
#3
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) {
this.advice("long");
// do some output
console.log("buying BTC @", candle.close);
return;
}

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

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?
  Reply


Messages In This Thread
Need some help to create strategy - by sweetpearl - 01-20-2018, 05:36 PM
RE: Need some help to create strategy - by c86s - 01-25-2018, 06:34 AM

Forum Jump:


Users browsing this thread: