Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
ai
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
ai
Commits
c2a1da9a
Commit
c2a1da9a
authored
Mar 15, 2022
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
1e681c6a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
16 deletions
+63
-16
ai.js
ai.js
+56
-16
test_lodash.js
test_lodash.js
+7
-0
No files found.
ai.js
View file @
c2a1da9a
...
...
@@ -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
...
...
test_lodash.js
0 → 100644
View file @
c2a1da9a
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment