Skip to content

Commit

Permalink
v0.3.10 - Configurable stop loss trailing
Browse files Browse the repository at this point in the history
  • Loading branch information
andresilvasantos committed Apr 7, 2018
1 parent c33df5d commit c3c3eb5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 22 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In order to find out the group id you've just created, run node with the followi
const bitprophet = require('bitprophet')
bitprophet.options({
telegram: {
token: YOUR_TELEGRAM_BOT_TOKEN
token: "YOUR_TELEGRAM_BOT_TOKEN"
}
})
bitprophet.listenToTelegramChatId()
Expand All @@ -44,12 +44,12 @@ This is the code to start BitProphet. If the only thing you need is to be notifi
const bitprophet = require('bitprophet')
bitprophet.options({
binance: {
key: YOUR_BINANCE_API_KEY,
secret: YOUR_BINANCE_API_SECRET
key: "YOUR_BINANCE_API_KEY",
secret: "YOUR_BINANCE_API_SECRET"
},
telegram: {
chatId: YOUR_TELEGRAM_GROUP_ID,
token: YOUR_TELEGRAM_BOT_TOKEN
chatId: "YOUR_TELEGRAM_GROUP_ID",
token: "YOUR_TELEGRAM_BOT_TOKEN"
}
})

Expand Down
9 changes: 1 addition & 8 deletions strategies/buydip.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,7 @@ module.exports = {
var stoch5m = bp.indicators.stochastic(chart5m, 14, 24)
var stoch5mAvg = bp.indicators.average(stoch5m)
var maxDiff5m = bp.indicators.measureMaxDiff(chart5m, 120)

var volume24h = 0
for(var i = chart1h.length - 24; i < chart1h.length; ++i) {
var high = parseFloat(chart1h[i].high)
var low = parseFloat(chart1h[i].low)
var avgPrice = (high - low) / 2. + low
volume24h += parseFloat(chart1h[i].volume) * avgPrice
}
var volume24h = bp.indicators.volume24h(chart1h, 60)

setPairValid(volume24h >= 100 && stoch1hAvg > 30 && stoch5mAvg >= 20 && maxDiff5m < 100)
},
Expand Down
21 changes: 12 additions & 9 deletions strategy_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ module.exports = {
}
}

this.manageStopLoss = function(pairData, lastClose, trailing = 1) {
this.manageStopLoss = function(pairData, lastClose, trailingType = 2, trailingPercentage = 0.006, sellPriceDistance = 0.001) {
var diffPercentage = (lastClose - pairData.entryPrice) / pairData.entryPrice * 100

if(lastClose < pairData.stopLoss.sellPrice && lastClose < pairData.stopLoss.stopPrice) {
Expand All @@ -164,17 +164,20 @@ module.exports = {
return true
}

if(trailing == 0) {
if(lastClose / pairData.entryPrice >= 1.006 && pairData.stopLoss.sellPrice < pairData.entryPrice) {
pairData.stopLoss.stopPrice = pairData.entryPrice * 1.001
switch(trailingType) {
case 0:
default:
break
case 1:
if(lastClose / pairData.entryPrice >= (1 + trailingPercentage) && pairData.stopLoss.sellPrice < pairData.entryPrice) {
pairData.stopLoss.stopPrice = pairData.entryPrice * (1 + sellPriceDistance)
pairData.stopLoss.sellPrice = pairData.entryPrice
this.sendMessage(pairData, "stop loss adjusted to 0.0%", "point_up")
}
}
else if(trailing == 1) {
if(pairData.entryPrice < lastClose / 1.006 && pairData.stopLoss.stopPrice < lastClose / 1.006) {
pairData.stopLoss.stopPrice = lastClose / 1.006
pairData.stopLoss.sellPrice = lastClose / 1.009
case 2:
if(pairData.entryPrice < lastClose / (1 + trailingPercentage) && pairData.stopLoss.stopPrice < lastClose / (1 + trailingPercentage)) {
pairData.stopLoss.stopPrice = lastClose / (1 + trailingPercentage)
pairData.stopLoss.sellPrice = lastClose / (1 + trailingPercentage + sellPriceDistance)

var percentage = (pairData.stopLoss.stopPrice / pairData.entryPrice - 1) * 100
this.sendMessage(pairData, "stop loss adjusted to " + percentage.toFixed(2) + "%", "point_up")
Expand Down

0 comments on commit c3c3eb5

Please sign in to comment.