Skip to content

Instantly share code, notes, and snippets.

@marcelomf
Last active February 9, 2019 09:59
Show Gist options
  • Save marcelomf/8ae693e5983a7d23fe159f4c816698be to your computer and use it in GitHub Desktop.
Save marcelomf/8ae693e5983a7d23fe159f4c816698be to your computer and use it in GitHub Desktop.
Part of my engine.js
function onTrade(trade, is_preroll, cb) {
if (s.period && trade.time < s.period.time) {
return
}
var day = (new Date(trade.time)).getDate()
if (s.last_day && day !== s.last_day) {
s.day_count++
}
s.last_day = day
if (!s.period) {
initBuffer(trade)
}
s.in_preroll = is_preroll || (so.start && trade.time < so.start)
if (!s.period.last_try_trade && !s.in_preroll) {
s.period.last_try_trade = now()
}
if(trade.time > s.period.close_time ||
(!s.in_preroll && so.mode != "sim" && moment.duration(moment(now()).diff(s.period.last_try_trade)).asMinutes() >= 1)){
var period_id = tb(trade.time).resize(so.period_length).toString()
s.period.last_try_trade = now()
s.strategy.onPeriod.call(s.ctx, s, function () {
writeReport()
s.acted_on_stop = false
if (!s.in_preroll && !so.manual) {
executeStop(true)
if (s.signal) {
executeSignal(s.signal)
}
}
s.action = null
s.signal = null
if (trade.time > s.period.close_time) {
s.lookback.unshift(s.period)
initBuffer(trade)
}
withOnPeriod(trade, period_id, cb)
})
}
else {
withOnPeriod(trade, period_id, cb)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment