Commit c2a1da9a authored by Ahmad Nemati's avatar Ahmad Nemati

init

parent 1e681c6a
......@@ -185,16 +185,21 @@ function run(data, config, risk, pfTrade, riskFreeLevel, detail, loss, durs, max
if (endDays > maxDays)
maxDays = endDays
// let runnigTime = 0
// runnigTime = calculateRunnigTime(data[i].side, data[i].unixOpen, data[i].unixClose, d.targetPrice)
// if (step !== 0)
// runnigTime = runnigTime + (unixMid - unixStart)
//
// runnigTime = runnigTime / 3600
// if (needPrintData)
// obj.runnigTime = runnigTime
//
// maxRuntime = maxRuntime + runnigTime
let runnigTime = 0
runnigTime = calculateRunnigTime(data[i].side, data[i].unixOpen, data[i].unixClose, d.targetPrice)
if (typeof runnigTime ==="undefined")
{
runnigTime=0
}
//console.log(runnigTime)
if (step !== 0)
runnigTime = runnigTime + (unixMid - unixStart)
runnigTime = runnigTime / 3600
if (needPrintData)
obj.runnigTime = runnigTime
maxRuntime = maxRuntime + runnigTime
listDays.push(endDays)
......@@ -590,6 +595,9 @@ function getTargetPrice(money, targetMoney, basePrice, side) {
function calculateRunnigTime(side, startTime, endTime, targetPrice) {
let arr = grabData(startTime, endTime)
if (arr ===[])
return 0
for (let i = 0; i < arr.length; i++) {
if (arr[i].h === 0)
continue
......@@ -604,6 +612,28 @@ function calculateRunnigTime(side, startTime, endTime, targetPrice) {
}
}
let arr2=[]
if (side ==='LONG')
arr2 = _.orderBy(arr, ['h'], ['desc']);
else
arr2= _.orderBy(arr,['l'])
for (let i = 0; i < arr.length; i++) {
if (arr[i].h === 0)
continue
if (side === 'LONG') {
if (arr2[0].h === arr[i].h)
return timeFrame * (i + 1)
} else {
if (arr2[0].l >= arr[i].l) {
return timeFrame * (i + 1)
}
}
}
}
......@@ -613,17 +643,27 @@ function grabData(start, end) {
let indexStart = false
let startIndex = (start - candles[0].t) / timeFrame
let endIndex = (end - candles[0].t) / timeFrame
// console.log(start ,end,candles[0].t,timeFrame,startIndex,endIndex)
// console.log(startIndex)
// console.log('line:'+endIndex +' with end'+end)
for (let i = startIndex; i <= endIndex; i++) {
if (indexStart && candles[i].t <= end)
arr.push(candles[i])
try {
for (let i = startIndex; i <= endIndex; i++) {
if (indexStart && candles[i].t <= end)
arr.push(candles[i])
else if (candles[i].t === start) {
indexStart = true
arr.push(candles[i])
else if (candles[i].t === start) {
indexStart = true
arr.push(candles[i])
}
}
}
catch (e)
{
return []
}
return arr
......
const _=require('lodash')
let arr=[{h:1,l:2},{h:5,l:1},{h:5,l:10}]
console.log(_.orderBy(arr,['l']))
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment