diff --git a/src/broker.ts b/src/broker.ts index 95051b3..89ae530 100644 --- a/src/broker.ts +++ b/src/broker.ts @@ -124,7 +124,7 @@ export class Broker { const prevClose = first(data['close'].values.slice(-2)) as number; let reprocessOrders = false; - for (let i = 0; i < this.orders.length; i = 0) { + for (let i = 0; i < this.orders.length; i++) { const order = this.orders[i]; /* istanbul ignore if */ diff --git a/test/sma-cross.strategy.ts b/test/sma-cross.strategy.ts index 73a2a13..bf973cb 100644 --- a/test/sma-cross.strategy.ts +++ b/test/sma-cross.strategy.ts @@ -33,7 +33,8 @@ export class SmaCross extends Strategy { next(ctx: Context) { const { index, signals } = ctx; if (index < this.params.n1 || index < this.params.n2) return; - if (signals.get('crossUp')) this.buy({ size: 1000 }); + const price = ctx.data['close']; + if (signals.get('crossUp')) this.buy({ size: 1000, tpPrice: price * 1.15, slPrice: price * 0.9 }); if (signals.get('crossDown')) this.sell({ size: 1000 }); } }