def calculate_signals(self, event): if event.type == 'TICK': pair = event.instrument price = event.bid pd = self.pairs_dict[pair] if pd["ticks"] == 0: pd["short_sma"] = price pd["long_sma"] = price else: pd["short_sma"] = self.calc_rolling_sma( pd["short_sma"], self.short_window, price) pd["long_sma"] = self.calc_rolling_sma(pd["long_sma"], self.long_window, price) # Only start the strategy when we have created an accurate short # window if pd["ticks"] > self.short_window: if pd["short_sma"] > pd["long_sma"] and not pd["invested"]: signal = SignalEvent(pair, "market", "buy", event.time) self.events.put(signal) pd["invested"] = True if pd["short_sma"] < pd["long_sma"] and pd["invested"]: signal = SignalEvent(pair, "market", "sell", event.time) self.events.put(signal) pd["invested"] = False pd["ticks"] += 1
def calculate_signals(self, event): if event.type == 'TICK': price = event.bid if self.ticks == 0: self.short_sma = price self.long_sma = price else: self.short_sma = self.calc_rolling_sma(self.short_sma, self.short_window, price) self.long_sma = self.calc_rolling_sma(self.long_sma, self.long_window, price) # Only start the strategy when we have created an accurate short window if self.ticks > self.short_window: if self.short_sma > self.long_sma and not self.invested: signal = SignalEvent(self.pairs[0], "market", "buy", event.time) self.events.put(signal) self.invested = True if self.short_sma < self.long_sma and self.invested: signal = SignalEvent(self.pairs[0], "market", "sell", event.time) self.events.put(signal) self.invested = False self.ticks += 1
def calculate_signals(self, event): if event.type == 'TICK' and event.instrument == self.pairs[0]: if self.ticks % 5 == 0: if self.invested == False: signal = SignalEvent(self.pairs[0], "market", "buy", event.time) self.events.put(signal) self.invested = True else: signal = SignalEvent(self.pairs[0], "market", "sell", event.time) self.events.put(signal) self.invested = False self.ticks += 1
def calculate_signals(self, event): if event.type == 'TICK': if self.ticks % 200 == 0: if self.invested == False: signal = SignalEvent(self.instrument, "market", "buy") self.events.put(signal) self.invested = True else: signal = SignalEvent(self.instrument, "market", "sell") self.events.put(signal) self.invested = False self.ticks += 1