@@ -287,6 +287,17 @@ export class AutopilotComponent implements OnInit, OnDestroy {
287
287
} ) ;
288
288
}
289
289
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
+
290
301
setProfitLoss ( ) {
291
302
const lastProfitLoss = JSON . parse ( localStorage . getItem ( 'profitLoss' ) ) ;
292
303
const tempProfitRecord = this . scoreKeeperService . profitLossHash ;
@@ -305,13 +316,8 @@ export class AutopilotComponent implements OnInit, OnDestroy {
305
316
}
306
317
}
307
318
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
+
315
321
const profitObj : ProfitLossRecord = {
316
322
'date' : moment ( ) . format ( ) ,
317
323
profit : profit ,
@@ -385,14 +391,14 @@ export class AutopilotComponent implements OnInit, OnDestroy {
385
391
. subscribe ( patternsResponse => console . log ( 'found patterns ' , patternsResponse ) ) ;
386
392
const lastProfitLoss = JSON . parse ( localStorage . getItem ( 'profitLoss' ) ) ;
387
393
if ( lastProfitLoss && lastProfitLoss . profit !== undefined ) {
388
- if ( Number ( lastProfitLoss . profit ) < 0 ) {
394
+ if ( Number ( this . calculatePl ( lastProfitLoss . profitRecord ) ) < 0 ) {
389
395
if ( lastProfitLoss . lastStrategy === Strategy . Daytrade ) {
390
396
this . increaseDayTradeRiskTolerance ( ) ;
391
397
} else {
392
398
this . decreaseRiskTolerance ( ) ;
393
399
}
394
400
395
- } else if ( Number ( lastProfitLoss . profit ) > 0 ) {
401
+ } else if ( Number ( this . calculatePl ( lastProfitLoss . profitRecord ) ) > 0 ) {
396
402
if ( lastProfitLoss . lastStrategy === Strategy . Daytrade ) {
397
403
this . decreaseDayTradeRiskTolerance ( ) ;
398
404
} else {
0 commit comments