sell if price>x or sell if price<y
#1
Information 
I know a minimal amount of coding and I'm basically trying to set up simultaneous stop loss and take profit orders. So for example, if the price of BTC becomes higher than 9500 USDT, I want to market sell my BTC position. Likewise, if it drops to below 8500, I also wanna sell it at market price as well. I want to keep my position as long as the price stays in this range. The below code I attempted to use gives the 'child process has dies' error. What's wrong with it? Can somebody help?

var strat = {};

// Prepare everything our strat needs
strat.init = function() {
  // setting take profit price
  this.proPrice = 9500;

  // setting stop loss price
  this.losPrice = 8500;
}

strat.check = function(candle) {
    if(candle.close <= this.losPrice) {
        this.advice(“short”);
        return;
    }
    if(candle.close >= this.proPrice) {
        this.advice(“short”);
        return;
    }
}

module.exports = strat;
  Reply
#2
Hi
If this is the whole code then it could not work
The strat needs some basics:

Code:
var method = {};

method.init = function()
{

}

method.update = function(candle) {

}

method.log = function() {

}

method.check = function(candle)
{

}

module.exports = method;
but thats not everything
You need also to initialize some var (like drivers added in the beginnig of the strat:

Code:
var _ = require('lodash');
var log = require('../core/log.js');
var config = require ('../core/util.js').getConfig();

The full BASSic tulip RSI strat:

Code:
/*
BASSic tulip_RSI
*/

var _ = require('lodash');
var log = require('../core/log.js');
var config = require('../core/util.js').getConfig();

var strat = {};

strat.init = function () {
   //add candle.close
   price =
       {
           close: 0//this.candle
       };
   this.price = price;

   logic =
       {
           longpos: false
       };
   this.logic = logic;

   //first fetch settings from .toml
   var customRSIsettings = this.settings.RSI;

   // define the indicators we need     //move the settings into >>>rsi input length
   this.addTulipIndicator('myrsi', 'rsi', customRSIsettings);
}

strat.update = function (candle) {

}

strat.log = function () {

}

strat.check = function (candle) {
   //update price.close
   this.price.close = this.candle.close;

   //update the indicator before using it
   var resultRSI = this.tulipIndicators.myrsi.result.result;

   //lets trade...
   if (resultRSI > this.settings.trsRSI.high && this.logic.longpos !== false) {
       this.logic.longpos = false;
       this.advice('short');
       log.debug('goShort price ' + this.price.close + '  rsi ' + resultRSI.toFixed(2));
   }
   else if (resultRSI < this.settings.trsRSI.low && this.logic.longpos !== true) {
       this.logic.longpos = true;
       this.advice('long');
       log.debug('goLong price ' + this.price.close + '  rsi ' + resultRSI.toFixed(2));
   }
}

module.exports = strat;
and the settings file:

Code:
[RSI]
optInTimePeriod = 15

[trsRSI]
high = 71
low = 28

#_try_1min_candles_#
#_binance_BTC_USDT_#


You can erase and copie/paste your code to it.

If you dont know about how to use these examples please watch my tutorials,
about how to build a strat:
TUT #1 RSI
  Reply


Forum Jump:


Users browsing this thread: