Skip to content

Commit

Permalink
sort by intervals
Browse files Browse the repository at this point in the history
  • Loading branch information
mrddter committed Oct 30, 2024
1 parent 9a6016f commit 597fb36
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/helpers/run-strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { findCandleIndex, getDiffInDays, round, generatePermutations, calculateS
import { getCandles as getCandlesFromPrisma } from './prisma-historical-data'
import { getStrategy } from './strategies'
import { BacktestError, ErrorCode } from './error'
import { getIntervals } from '../core/common'
import * as logger from './logger'

export async function run(runParams: RunStrategy): Promise<RunStrategyResult | RunStrategyResultMulti[]> {
Expand Down Expand Up @@ -106,7 +107,14 @@ export async function run(runParams: RunStrategy): Promise<RunStrategyResult | R
allSupportCandles.push(...candles)
}

allSupportCandles.sort((a, b) => a.closeTime - b.closeTime)
// allSupportCandles.sort((a, b) => a.closeTime - b.closeTime)

const intervalOrder = getIntervals()
allSupportCandles.sort((a, b) => {
const byTime = a.closeTime - b.closeTime
if (byTime !== 0) return byTime
return intervalOrder.indexOf(a.interval) - intervalOrder.indexOf(b.interval)
})

// Run evaluation
for (let symbolCount = 0; symbolCount < historicalNames.length; symbolCount++) {
Expand Down Expand Up @@ -182,7 +190,7 @@ export async function run(runParams: RunStrategy): Promise<RunStrategyResult | R
sharpeRatio: 0
}

let fromTime = candles[candleIndex].closeTime
let fromTime = candles[candleIndex - 1].closeTime

for (candleIndex; candleIndex < candleIndexEnd; candleIndex++) {
let canBuySell = true
Expand Down Expand Up @@ -228,6 +236,7 @@ export async function run(runParams: RunStrategy): Promise<RunStrategyResult | R
}
}
}

fromTime = currentCandle.closeTime

// Define buy and sell methods
Expand Down

0 comments on commit 597fb36

Please sign in to comment.