Skip to content

Commit 2c44037

Browse files
committed
Fix pl again
1 parent 1c0c654 commit 2c44037

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/app/autopilot/autopilot.component.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,17 @@ export class AutopilotComponent implements OnInit, OnDestroy {
287287
});
288288
}
289289

290+
calculatePl(records) {
291+
let profit = 0;
292+
for (let key in records) {
293+
if (records[key]) {
294+
profit += Number(records[key].toFixed(2));
295+
}
296+
}
297+
298+
return profit;
299+
}
300+
290301
setProfitLoss() {
291302
const lastProfitLoss = JSON.parse(localStorage.getItem('profitLoss'));
292303
const tempProfitRecord = this.scoreKeeperService.profitLossHash;
@@ -305,13 +316,8 @@ export class AutopilotComponent implements OnInit, OnDestroy {
305316
}
306317
}
307318

308-
let profit = 0;
309-
for (let key in tempProfitRecord) {
310-
if (tempProfitRecord[key]) {
311-
profit += Number(tempProfitRecord[key].toFixed(2));
312-
}
313-
}
314-
319+
const profit = this.calculatePl(tempProfitRecord);
320+
315321
const profitObj: ProfitLossRecord = {
316322
'date': moment().format(),
317323
profit: profit,
@@ -385,14 +391,14 @@ export class AutopilotComponent implements OnInit, OnDestroy {
385391
.subscribe(patternsResponse => console.log('found patterns ', patternsResponse));
386392
const lastProfitLoss = JSON.parse(localStorage.getItem('profitLoss'));
387393
if (lastProfitLoss && lastProfitLoss.profit !== undefined) {
388-
if (Number(lastProfitLoss.profit) < 0) {
394+
if (Number(this.calculatePl(lastProfitLoss.profitRecord)) < 0) {
389395
if (lastProfitLoss.lastStrategy === Strategy.Daytrade) {
390396
this.increaseDayTradeRiskTolerance();
391397
} else {
392398
this.decreaseRiskTolerance();
393399
}
394400

395-
} else if (Number(lastProfitLoss.profit) > 0) {
401+
} else if (Number(this.calculatePl(lastProfitLoss.profitRecord)) > 0) {
396402
if (lastProfitLoss.lastStrategy === Strategy.Daytrade) {
397403
this.decreaseDayTradeRiskTolerance();
398404
} else {

0 commit comments

Comments
 (0)