-
Notifications
You must be signed in to change notification settings - Fork 3
232 lines (230 loc) · 7.7 KB
/
optimize-indi.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
---
name: Optimize Indicator params
# yamllint disable-line rule:truthy
on:
push:
branches:
- 'optimize-indi'
jobs:
Compile:
defaults:
run:
shell: powershell
runs-on: windows-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v3
with:
path: Include/EA31337-classes
ref: dev
repository: EA31337/EA31337-classes
- name: Enables optimization mode
run: echo '#define __input__' > config/define.h
- name: Compile for MQL4
uses: fx31337/mql-compile-action@master
with:
include: .
init-platform: true
mt-version: 5.0.0.2361
path: Stg_ADX.mq4
verbose: true
- name: Compile for MQL5
uses: fx31337/mql-compile-action@master
with:
include: .
mt-version: 5.0.0.2515
path: Stg_ADX.mq5
verbose: true
- name: List compiled files
run: '(Get-ChildItem -Recurse -Path . -Include *.ex[45]).fullname'
- run: Get-Location
- name: Upload EA
uses: actions/upload-artifact@v2
with:
name: EA
path: '*.ex?'
Process:
env:
SETS_DIR: sets/optimize/indicator
outputs:
sets-list: ${{ steps.get-sets.outputs.sets }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set output with list of sets
id: get-sets
run: |
import glob, json, os
os.chdir(os.getenv('SETS_DIR'))
files = glob.glob("*.set")
print("::set-output name=sets::{}".format(json.dumps(files)))
shell: python
- name: Display output
run: echo ${{ steps.get-sets.outputs.sets }}
- name: Upload config
uses: actions/upload-artifact@v2
with:
name: config
path: 'config'
- name: Upload sets
uses: actions/upload-artifact@v2
with:
name: sets
path: ${{ env.SETS_DIR }}
Optimize:
needs: [Compile, Process]
runs-on: ubuntu-latest
strategy:
matrix:
pair: [EURUSD]
setfile: ${{ fromJson(needs.Process.outputs.sets-list) }}
tf: [M1, M5, M15, M30]
max-parallel: 4
steps:
- uses: actions/download-artifact@v2
with:
path: .
- name: Generate env file
run: >-
grep -w = config/${{ matrix.pair }}_${{ matrix.tf }}.h
| sed -e 's/[}; ]*//g;s/([^)]*)//g;s/^.*{//g' | tee sets/.env
- name: Generate SET file from the template file
uses: cuchi/jinja2-action@v1.2.0
with:
template: sets/${{ matrix.setfile }}.j2
output_file: sets/${{ matrix.setfile }}
data_file: sets/.env
data_format: env
- name: Sets input data
id: data
run: |
tfs = {"M1":1, "M5":2, "M15":4, "M30":8, "H1":16, "H4":32, "H8":64}
print("::set-output name=tf::{}".format(tfs.get("${{ matrix.tf }}")))
setfile = "sets/${{ matrix.setfile }}"
for line in open(setfile, "r").readlines():
if line.strip().endswith(",F=1"):
print("::set-output name=param::{}"
.format(line.strip().replace(",F=1", "")))
break
shell: python
- name: Sets timeframe
run: echo Active_Tfs=${{ steps.data.outputs.tf }} | tee -a sets/*.set
- name: Display SET file
run: cat sets/${{ matrix.setfile }}
- uses: ea31337/mql-tester-action@master
with:
BtDeposit: 100000
BtDest: ${{ github.workspace }}/_results
BtMonths: 11-12
BtPair: ${{ matrix.pair }}
BtYears: 2020
OptFormatBrief: true
OptFormatJson: true
OptOptimize: true
OptVerbose: true
SetFile: ${{ github.workspace }}/sets/${{ matrix.setfile }}
SetParams: ${{ steps.data.outputs.param }}
TestExpert: "Stg_ADX"
TestPeriod: ${{ matrix.tf }}
TestReportName: Report-${{ matrix.pair }}-${{ matrix.tf }}
- name: Upload result files
uses: actions/upload-artifact@v2
with:
name: results
path: ./_results/*.*
- name: Process results
run: |
pwd
ls
jq --version
jq . _results/*.json
jq -r '(."Result params"/";")[0]' _results/*.json
jq -r '((."Result params"/";")[0]/"=")[0]'
jq -r '(."Result params"/";")[0]' _results/*.json \
>> $GITHUB_ENV
jq -r '"pname="+((."Result params"/";")[0]/"=")[0]' \
_results/*.json >> $GITHUB_ENV
- name: Process SET file
run: |
echo Timeframe=${{ matrix.tf }} >> sets/${{ matrix.setfile }}
cat sets/${{ matrix.setfile }}
- name: Generate config file from the SET file
uses: cuchi/jinja2-action@v1.2.0
with:
template: config/template.j2
output_file: config/${{ matrix.pair }}_${{ matrix.tf }}.h
data_file: sets/${{ matrix.setfile }}
data_format: env
- name: Display config file
run: cat config/${{ matrix.pair }}_${{ matrix.tf }}.h
- name: Upload updated config file
uses: actions/upload-artifact@v2
with:
name: config
path: ./config/${{ matrix.pair }}_${{ matrix.tf }}.h
Push:
needs: Optimize
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
persist-credentials: false
# Otherwise, you will failed to push refs to dest repo.
fetch-depth: 0
- uses: actions/download-artifact@v2
with:
name: config
path: config
- uses: actions/download-artifact@v2
with:
name: results
path: .results
- name: Parse results
run: |
cat << EOF >> $GITHUB_ENV
RES_DD=$(jq -rs '.[0]|."Drawdown %"' .results/*.json)
RES_PF=$(jq -rs '.[0]|."Profit factor"' .results/*.json)
RES_TT=$(jq -rs '.[0]|."Total trades"' .results/*.json)
EOF
shell: bash -ex {0}
- name: Check differences
id: git-details
run: echo "::set-output name=changed::$(git diff | wc -l)"
- name: Commit files
env:
COMMIT_MSG: >-
${{ github.workflow }}
(pf=${{ env.RES_PF }}; dd=${{ env.RES_DD }}; tt=${{ env.RES_TT }})
GIT_EMAIL: ${{ github.actor }}@users.noreply.github.com
GIT_NAME: ${{ github.actor }}
run: |
echo '*.j2' >> .git/info/exclude
echo '.results' >> .git/info/exclude
echo "Lines changed: ${{ steps.git-details.outputs.changed }}"
git config --local core.autocrlf false
git config --local user.email $GIT_EMAIL
git config --local user.name $GIT_NAME
git add config/*.h && git add --renormalize config/*.h
git pull origin ${{ github.ref }} --autostash --rebase -X ours
git commit --allow-empty -am "$COMMIT_MSG"
NO_PAGER=1 git --no-pager diff HEAD^
- name: Push changes
env:
DD: ${{ env.RES_DD }}
PF: ${{ env.RES_PF }}
TT: ${{ env.RES_TT }}
uses: ad-m/github-push-action@master
with:
branch: dev-optimize-${{ env.PF }}pf-${{ env.DD }}dd-${{ env.TT }}tt
force: true
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Re-pull on failure
if: ${{ failure() }}
run: git pull origin ${{ github.ref }} --autostash --rebase -X ours
- name: Re-push on failure
if: ${{ failure() }}
uses: ad-m/github-push-action@master
with:
branch: ${{ github.ref }}
force: true
github_token: ${{ secrets.GITHUB_TOKEN }}