Ejemplo n.º 1
0
 def pips_to_sma_calculator(self, ev):
     if ev.signal == 'buy':
         return an.pip_difference(ev.lt_sma_est, ev.price['ask'])
     elif ev.signal == 'sell':
         return an.pip_difference(ev.lt_sma_est, ev.price['bid'])
     else:
         return 0
Ejemplo n.º 2
0
 def push_next_ma_bar_1h(self, gap=1300):
     ev = event.Event('tick', self.df.index[self.lastrow])
     ev.df = self.df[self.lastrow - gap:self.lastrow].resample('1H', how=self.ohlc_dict).dropna(how='any')
     ev.ticker = self.ticker
     ev.price = {'ask': self.df_full.iloc[self.lastrow]['closeAsk'], 'bid': self.df_full.iloc[self.lastrow]['closeBid']}
     ev.spread = round(an.pip_difference(self.df_full.iloc[self.lastrow]['closeAsk'], self.df_full.iloc[self.lastrow]['closeBid']), 1)
     self.lastrow += 1
     return ev
Ejemplo n.º 3
0
    def sl_tp_calculator(self, event, signal):
        if signal == 'buy':
            price = event.price['ask']
            sl = round(Decimal(min(event.df['low'].iloc[-2:])), 5)
            if an.pip_difference(price, sl) < event.min_pip_sl:
                sl -= event.min_pip_sl / 10000
            diff = price - sl
            tp = round(price + (diff * Decimal(1.5)), 5)
            return (sl, tp)

        elif signal == 'sell':
            price = event.price['bid']
            sl = round(Decimal(max(event.df['high'].iloc[-2:])), 5)
            if an.pip_difference(price, sl) < event.min_pip_sl:
                sl += event.min_pip_sl / 10000
            diff = (sl - price)
            tp = round(price - (diff * Decimal(1.5)), 5)
            return (sl, tp)
        else:
            return (0,0)
Ejemplo n.º 4
0
    def check_sl(self, event, trade_details):
        if trade_details['signal'] == 'buy':
            if event.price['bid'] - self.trailing_stop >= trade_details['sl'] and 'be' in trade_details.keys():
                event.type = 'alter_trade'
                event.trade_details = trade_details
                event.trade_details['sl'] = event.price['bid'] - self.trailing_stop
                event.trade_details['pip_sl'] = an.pip_difference(event.trade_details['sl'], event.trade_details['price']['ask'])
                event.slchecked = True
                return event
            elif event.price['bid'] - self.initial_stop_change >= trade_details['price']['ask'] and 'be' not in trade_details.keys():
                event.type = 'alter_trade'
                event.trade_details = trade_details
                event.trade_details['sl'] = event.trade_details['price']['ask']
                event.trade_details['be'] = True
                event.slchecked = True
                return event
            else:
                event.type = 'none'
                return event

        elif trade_details['signal'] == 'sell':
            if event.price['ask'] + self.trailing_stop <= trade_details['sl'] and 'be' in trade_details.keys():
                event.type = 'alter_trade'
                event.trade_details = trade_details
                event.trade_details['sl'] = event.price['ask'] + self.trailing_stop
                event.trade_details['pip_sl'] = an.pip_difference(event.trade_details['sl'], event.trade_details['price']['bid'])
                event.slchecked = True
                return event
            elif event.price['ask'] + self.initial_stop_change <= trade_details['price']['bid'] and 'be' not in trade_details.keys():
                event.type = 'alter_trade'
                event.trade_details = trade_details
                event.trade_details['sl'] = trade_details['price']['bid']
                event.trade_details['be'] = True
                event.slchecked = True
                return event
            else:
                event.type = 'none'
                return event
        else:
            event.type = 'none'
            return event
Ejemplo n.º 5
0
 def pip_take_profit_calculator(self, signal, price, takeprofit):
     if signal == 'buy':
         return an.pip_difference(price['ask'], takeprofit)
     elif signal == 'sell':
         return an.pip_difference(price['bid'], takeprofit)
Ejemplo n.º 6
0
 def pip_stop_loss_calculator(self, signal, price, stoploss):
     if signal == 'buy':
         return an.pip_difference(price['ask'], stoploss)
     elif signal == 'sell':
         return an.pip_difference(price['bid'], stoploss)
Ejemplo n.º 7
0
            continue

        elif event.type == 'tick' and portfolio.open_trade and not (hasattr(
                event, 'plchecked')):
            queue.add_to_queue(portfolio.check_position(event))
            try:
                if portfolio.trade_details['signal'] == 'sell':
                    print('Position:  ', portfolio.trade_details['signal'])
                    print('From Entry:',
                          (portfolio.trade_details['price']['bid'] -
                           event.price['ask']) * 10000)
                    print('Price:     ', event.price['ask'])
                    print('SL:        ', portfolio.trade_details['sl'])
                    print(
                        'To SL:     ',
                        an.pip_difference(portfolio.trade_details['sl'],
                                          event.price['ask']))
                    print(
                        'To TP:     ',
                        an.pip_difference(portfolio.trade_details['tp'],
                                          event.price['ask']))
                elif portfolio.trade_details['signal'] == 'buy':
                    print('Position: ', portfolio.trade_details['signal'])
                    print('From Entry',
                          (event.price['bid'] -
                           portfolio.trade_details['price']['ask']) * 10000)
                    print('Price:    ', event.price['bid'])
                    print('SL:       ', portfolio.trade_details['sl'])
                    print(
                        'To SL:    ',
                        an.pip_difference(portfolio.trade_details['sl'],
                                          event.price['bid']))