Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
forex
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
forex
Commits
7a99f950
Commit
7a99f950
authored
Aug 31, 2021
by
Ahmad Nemati
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parents
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
311 additions
and
0 deletions
+311
-0
ai.js
ai.js
+158
-0
config.json
config.json
+18
-0
csv.js
csv.js
+82
-0
test.js
test.js
+53
-0
No files found.
ai.js
0 → 100644
View file @
7a99f950
let
plus
=
'
plus
'
let
zarib
=
'
zarib
'
function
run
(
data
,
config
)
{
let
commision
=
config
.
commision
let
money
=
config
.
base
let
total
=
0
let
maxReserve
=
0
let
maxAllocatedMoney
=
0
let
maxLevel
=
0
// console.log(data)
let
step
=
0
let
reserv
=
0
let
profit
=
0
let
lastCom
=
0
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
if
(
step
===
0
)
money
=
config
.
base
else
{
if
(
config
.
type
===
zarib
)
money
=
config
.
base
*
config
.
param
*
step
else
if
(
config
.
type
===
plus
)
money
=
config
.
base
+
(
config
.
param
*
step
)
}
let
d
=
inlineCheck
(
money
,
commision
,
data
[
i
],
profit
,
lastCom
)
if
(
Math
.
abs
(
d
.
reserve
)
>
Math
.
abs
(
maxReserve
))
maxReserve
=
d
.
reserve
if
(
money
>
maxAllocatedMoney
)
maxAllocatedMoney
=
money
// console.log(data[i])
// console.log( 'step->'+step)
// console.log(d)
if
(
step
>
maxLevel
)
maxLevel
=
step
if
(
d
.
done
===
true
)
{
step
=
0
reserv
=
0
profit
=
0
lastCom
=
0
total
++
}
else
{
step
++
profit
=
profit
+
d
.
profit
lastCom
=
lastCom
+
d
.
com
}
}
let
percentage
=
maxReserve
+
total
percentage
=
maxAllocatedMoney
/
percentage
let
minus
=
0
if
(
percentage
<
0
)
{
minus
=
percentage
percentage
=
null
}
let
opt
=
{
platform
:
data
[
0
].
signal
,
type
:
config
.
type
+
'
param:
'
+
config
.
param
+
'
base:
'
+
config
.
base
,
total
:
total
,
avgLevel
:
maxLevel
/
total
,
maxLevel
:
maxLevel
,
maxAllocatedMoney
:
maxAllocatedMoney
,
avgAllocatedMoney
:
maxAllocatedMoney
/
total
,
maxReseve
:
maxReserve
,
avgReserve
:
maxReserve
/
total
,
percentage
:
percentage
,
minus
:
minus
}
return
opt
// console.log(data)
}
function
inlineCheck
(
money
,
com
,
data
,
profit
,
lastCom
)
{
// console.log(profit)
com
=
com
*
money
let
target
=
money
+
Math
.
abs
(
profit
)
+
com
+
lastCom
+
1
let
reserve
=
percentage
(
money
,
data
.
drawDown
)
let
profitMoney
=
percentageMinus
(
money
,
data
.
profit
)
let
diff
=
reserve
-
money
diff
=
diff
-
com
-
lastCom
+
profit
// console.log('reserve->'+reserve + ' money->'+money +' com->'+com +' lastCom->'+lastCom + 'profit->'+profit +' diff->'+diff)
if
(
percentage
(
money
,
data
.
runUp
)
>
target
)
return
{
done
:
true
,
reserve
:
diff
}
else
return
{
done
:
false
,
reserve
:
diff
,
profit
:
profitMoney
,
com
:
com
}
}
function
calPer
(
entry
,
last
)
{
return
((
last
-
entry
)
/
entry
)
*
100
}
function
percentage
(
base
,
per
)
{
base
=
parseFloat
(
base
)
per
=
parseFloat
(
per
)
let
percentager
=
per
/
100
let
temp
=
base
*
percentager
return
base
+
temp
}
function
percentageMinus
(
base
,
per
)
{
base
=
parseFloat
(
base
)
per
=
parseFloat
(
per
)
let
percentager
=
per
/
100
let
temp
=
base
*
percentager
return
temp
}
module
.
exports
=
{
run
:
run
,
}
\ No newline at end of file
config.json
0 → 100644
View file @
7a99f950
{
"sort"
:
"platform"
,
"data"
:
[
{
"type"
:
"plus"
,
"commision"
:
0.0008
,
"base"
:
100
,
"param"
:
1000
},
{
"type"
:
"zarib"
,
"commision"
:
0.0008
,
"base"
:
100
,
"param"
:
2
}
]
}
\ No newline at end of file
csv.js
0 → 100644
View file @
7a99f950
const
fs
=
require
(
'
fs
'
);
const
csv
=
require
(
'
fast-csv
'
);
let
_
=
require
(
'
lodash
'
)
let
ai
=
require
(
'
./ai
'
)
async
function
parse
(
name
,
configs
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
let
arr
=
[]
fs
.
createReadStream
(
'
./work/
'
+
name
)
.
pipe
(
csv
.
parse
({
headers
:
true
}))
.
on
(
'
error
'
,
error
=>
reject
(
error
))
.
on
(
'
data
'
,
row
=>
arr
.
push
(
row
))
.
on
(
'
end
'
,
rowCount
=>
resolve
(
initData
(
arr
,
configs
)));
});
}
function
initData
(
data
,
config
)
{
// console.log(data)
data
=
JSON
.
stringify
(
data
)
// data.replace(/Trade #/g, 'id').replace(/Profit %/g, 'profitPer')
data
=
_
.
replace
(
data
,
new
RegExp
(
'
Trade #
'
,
'
g
'
),
'
id
'
)
data
=
_
.
replace
(
data
,
new
RegExp
(
'
Profit %
'
,
'
g
'
),
'
profit
'
)
data
=
_
.
replace
(
data
,
new
RegExp
(
'
Run-up %
'
,
'
g
'
),
'
runUp
'
)
data
=
_
.
replace
(
data
,
new
RegExp
(
'
Drawdown %
'
,
'
g
'
),
'
drawDown
'
)
data
=
_
.
replace
(
data
,
new
RegExp
(
'
Price
'
,
'
g
'
),
'
price
'
)
data
=
_
.
replace
(
data
,
new
RegExp
(
'
Date/Time
'
,
'
g
'
),
'
date
'
)
data
=
JSON
.
parse
(
data
)
// console.log(data)
let
arr
=
[]
for
(
let
i
=
0
;
i
<
data
.
length
;
i
=
i
+
2
)
{
if
(
data
[
i
].
runUp
===
''
)
continue
let
obj
=
{}
obj
.
id
=
parseInt
(
data
[
i
].
id
)
obj
.
signal
=
data
[
i
].
Signal
if
(
data
[
i
].
Type
.
includes
(
'
Long
'
))
obj
.
side
=
'
LONG
'
else
obj
.
side
=
'
SHORT
'
obj
.
openPrice
=
parseFloat
(
data
[
i
].
price
)
obj
.
closePrice
=
parseFloat
(
data
[
i
+
1
].
price
)
obj
.
openDate
=
data
[
i
].
date
obj
.
closeDate
=
data
[
i
+
1
].
date
obj
.
profit
=
parseFloat
(
data
[
i
].
profit
)
obj
.
runUp
=
parseFloat
(
data
[
i
].
runUp
)
obj
.
drawDown
=
parseFloat
(
data
[
i
].
drawDown
)
obj
.
drawDown
=
obj
.
drawDown
*
-
1
arr
.
push
(
obj
)
// let arr=
}
//console.log(arr)
let
cz
=
[]
for
(
let
i
=
0
;
i
<
config
.
length
;
i
++
)
{
cz
.
push
(
ai
.
run
(
arr
,
config
[
i
]))
}
return
cz
}
module
.
exports
=
{
parse
:
parse
,
}
test.js
0 → 100644
View file @
7a99f950
let
fs
=
require
(
'
fs
'
)
let
csv
=
require
(
'
./csv
'
)
let
_
=
require
(
'
lodash
'
)
test
()
async
function
test
()
{
let
configs
=
await
fs
.
readFileSync
(
'
./config.json
'
,
'
utf8
'
)
configs
=
JSON
.
parse
(
configs
)
let
arr
=
[]
let
files
=
await
fs
.
readdirSync
(
'
./work
'
)
for
(
let
i
=
0
;
i
<
files
.
length
;
i
++
)
if
(
files
[
i
].
includes
(
'
.csv
'
))
arr
.
push
(
csv
.
parse
(
files
[
i
],
configs
.
data
))
arr
=
await
Promise
.
all
(
arr
)
let
arr2
=
[]
for
(
let
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
let
inline
=
arr
[
i
]
for
(
let
j
=
0
;
j
<
inline
.
length
;
j
++
)
arr2
.
push
(
inline
[
j
])
}
console
.
log
(
arr2
)
arr2
=
_
.
orderBy
(
arr2
,
[
configs
.
sort
],
[
'
asc
'
]);
// for (let i=0;i<files.length;i++)
createfile
(
JSON
.
stringify
(
arr2
,
null
,
2
))
console
.
log
(
'
Done
'
)
// console.log(d)
}
function
createfile
(
data
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
fs
.
writeFile
(
'
work/result.json
'
,
data
,
'
utf8
'
,
function
(
err
)
{
if
(
err
)
reject
(
err
);
else
resolve
(
data
);
});
});
}
async
function
test2
()
{
let
configs
=
await
fs
.
readFileSync
(
'
./config.json
'
,
'
utf8
'
)
configs
=
JSON
.
parse
(
configs
)
console
.
log
(
configs
)
}
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