Skip to content
This repository has been archived by the owner on Feb 15, 2022. It is now read-only.

Writing a custom Strategy and the bot is selling/buying Over and Over again #527

Closed
elikjwilliams opened this issue Sep 6, 2017 · 0 comments
Labels

Comments

@elikjwilliams
Copy link

Any help here? The bot will literally buy/sell over and over again even if the parameters are not met. I am thinking once a coin has been sold or bought there is a flag that needs to be flipped off.

Pasting code below. Ignore the sloppiness as I've been trying to debug :)

onPeriod: function (s, cb) {
  here = 'again'
  current_time = s.period.close_time
  current_price = s.period.close
  pct_change = ((current_price / prev_price)-1) * 100
  time_change = Math.abs(current_time - prev_time) / (1000.0 * 3600.0 * 24.0)
  if (s.in_preroll) return cb()

  //calculate 24hour data
  else if (time_change >= 1){

    //Case 2: 24 hour data is +5 sell
    if (pct_change > 5 && time_change >= 1 && (!s.trend || s.trend === 'down')){
     if (s.trend !== 'up') {
        s.acted_on_trend = false
     }

      s.signal = !s.acted_on_trend ? 'sell' : null
      prev_time = current_time
      prev_price = s.period.close
  time_change = Math.abs(current_time - prev_time) / (1000.0 * 3600.0 * 24.0)
   pct_change = ((current_price / prev_price)-1) * 100
  
    }

    //Case 3: 24 hour data is -5 buy
    else if (pct_change < -5  && time_change >= 1 && (!s.trend || s.trend === 'up')){
      if (s.trend !== 'down') {
        s.acted_on_trend = false
     }
      s.trend = 'down'
      s.signal = !s.acted_on_trend ? 'buy' : null
      prev_time = current_time
      prev_price = s.period.close
  time_change = Math.abs(current_time - prev_time) / (1000.0 * 3600.0 * 24.0)
   pct_change = ((current_price / prev_price)-1) * 100
  
    }
      }

  cb()
},
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants