Skip to content

Commit d720805

Browse files
committed
Fixed swingtrade finder
1 parent acdedde commit d720805

File tree

5 files changed

+25
-21
lines changed

5 files changed

+25
-21
lines changed

src/app/autopilot/autopilot.component.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ export class AutopilotComponent implements OnInit, OnDestroy {
221221
.pipe(takeUntil(this.destroy$))
222222
.subscribe(async () => {
223223
const startStopTime = this.getStartStopTime();
224-
console.log(new Date().toString());
225224
if (moment().isAfter(moment(startStopTime.endDateTime).subtract(5, 'minutes')) &&
226225
moment().isBefore(moment(startStopTime.endDateTime))) {
227226
if (this.reportingService.logs.length > 0) {
@@ -618,13 +617,16 @@ export class AutopilotComponent implements OnInit, OnDestroy {
618617
const found = (name) => {
619618
return Boolean(this.currentHoldings.find((value) => value.name === name));
620619
};
621-
622-
do {
623-
stock = this.machineDaytradingService.getNextStock();
624-
} while (found(stock))
625-
const backtestResults = await this.backtestTableService.getBacktestData(stock);
626-
if (backtestResults) {
627-
cb(stock, backtestResults.ml);
620+
let counter = this.machineDaytradingService.getCurrentStockList().length;
621+
while (counter > 0 && (this.cartService.buyOrders.length + this.cartService.otherOrders.length) < this.maxTradeCount) {
622+
do {
623+
stock = this.machineDaytradingService.getNextStock();
624+
} while (found(stock))
625+
const backtestResults = await this.backtestTableService.getBacktestData(stock);
626+
if (backtestResults) {
627+
cb(stock, backtestResults.ml);
628+
}
629+
counter--;
628630
}
629631
}
630632

@@ -650,7 +652,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
650652
console.log('training daytrade results ', trainingResults);
651653
if (trainingResults[0].correct / trainingResults[0].guesses > 0.6 && trainingResults[0].guesses > 50) {
652654
await this.addDaytrade(stock);
653-
if (this.cartService.otherOrders.length > this.maxTradeCount) {
655+
if ((this.cartService.buyOrders.length + this.cartService.otherOrders.length) > this.maxTradeCount) {
654656
break;
655657
}
656658
}
@@ -713,7 +715,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
713715
}
714716

715717
async addBuy(holding: PortfolioInfoHolding, allocation = round(this.riskToleranceList[this.riskCounter], 2)) {
716-
if (this.cartService.buyOrders.length < this.maxTradeCount) {
718+
if ((this.cartService.buyOrders.length + this.cartService.otherOrders.length) < this.maxTradeCount) {
717719
console.log('Adding buy ', holding);
718720

719721
const currentDate = moment().format('YYYY-MM-DD');
@@ -740,7 +742,7 @@ export class AutopilotComponent implements OnInit, OnDestroy {
740742
}
741743

742744
async addDaytrade(stock: string) {
743-
if (this.cartService.otherOrders.length < this.maxTradeCount) {
745+
if ((this.cartService.buyOrders.length + this.cartService.otherOrders.length) < this.maxTradeCount) {
744746
const currentDate = moment().format('YYYY-MM-DD');
745747
const startDate = moment().subtract(100, 'days').format('YYYY-MM-DD');
746748
try {

src/app/backtest-table/backtest-table.service.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ export class BacktestTableService {
1414
private optionsDataService: OptionsDataService,
1515
private portfolioService: PortfolioService) { }
1616

17-
async getBacktestData(symbol: string, startDate: string = null, endDate: string = null) {
18-
const current = moment(endDate).format('YYYY-MM-DD');
19-
const start = moment(startDate).subtract(365, 'days').format('YYYY-MM-DD');
17+
async getBacktestData(symbol: string) {
18+
const current = moment().format('YYYY-MM-DD');
19+
const start = moment().subtract(365, 'days').format('YYYY-MM-DD');
2020

2121
try {
2222
const indicatorResults = await this.backtestService.getBacktestEvaluation(symbol, start, current, 'daily-indicators').toPromise();
@@ -47,7 +47,8 @@ export class BacktestTableService {
4747
strongbuySignals: [],
4848
buySignals: [],
4949
strongsellSignals: [],
50-
sellSignals: []
50+
sellSignals: [],
51+
high52: instruments[symbol].fundamental.high52
5152
};
5253
const latestMlResult = await this.aiPicksService.trainAndActivate(symbol);
5354
if (latestMlResult) {

src/app/machine-daytrading/machine-daytrading.service.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ export class MachineDaytradingService {
131131

132132
setCurrentStockList(stockList) {
133133
this.currentStockList = stockList;
134-
this.resetStockCounter();
134+
}
135+
136+
getCurrentStockList() {
137+
return this.currentStockList;
135138
}
136139

137140
getNextStock() {
@@ -145,10 +148,6 @@ export class MachineDaytradingService {
145148
return this.currentStockList[this.counter].ticker ? this.currentStockList[this.counter].ticker : this.currentStockList[this.counter].name;
146149
}
147150

148-
resetStockCounter() {
149-
this.counter = 0;
150-
}
151-
152151
resetStock() {
153152
this.selectedStock = null;
154153
}

src/app/shared/services/reporting.service.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export class ReportingService {
4646
'Previous Implied Move': results.previousImpliedMovement,
4747
'AI Prediction': JSON.stringify(results.ml),
4848
'Options Volume': results.optionsVolume,
49-
'Market Cap': results.marketCap
49+
'Market Cap': results.marketCap,
50+
'52 Week High': results.high52
5051
};
5152
if (selectedColumns.length > 0) {
5253
selectedColumns.forEach((column: {field: string, header: string}) => {

src/app/shared/stock.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ export interface Stock {
5151
ml?: any;
5252
optionsVolume?: number;
5353
marketCap?: number;
54+
high52?: number;
5455
}

0 commit comments

Comments
 (0)