Beispiel #1
0
def Logic(Account, Lookback):
    try:
        # Process dataframe to collect signals
        # Lookback = helpers.getSignals(Lookback)

        # Load into period class to simplify indexing
        Lookback = helpers.Period(Lookback)

        Today = Lookback.loc(0)  # Current candle
        Yesterday = Lookback.loc(-1)  # Previous candle
        # print(Today)
        if Today['close'] < Yesterday['close']:
            ExitPrice = Today['close']
            for Position in Account.Positions:
                if Position.Type == 'Long':
                    Account.ClosePosition(Position, 0.5, ExitPrice)

        if Today['close'] > Yesterday['close']:
            Risk = 0.03
            EntryPrice = Today['close']
            EntryCapital = Account.BuyingPower * Risk
            if EntryCapital >= 0:
                Account.EnterPosition('Long', EntryCapital, EntryPrice)

    except ValueError:
        pass  # Handles lookback errors in beginning of dataset
Beispiel #2
0
def Logic(Account, Lookback):
    try:
        # Process dataframe to collect signals
        # Lookback = process(Lookback)

        # Load into period class to simplify indexing
        Lookback = helpers.Period(Lookback)

        Today = Lookback.loc(0)  # Current candle

        if Today['date'] >= datetime.strptime('2017-05-01', '%Y-%m-%d'):
            if Today['color'] == 'darkOrange':
                ExitPrice = Today['close']
                for Position in Account.Positions:
                    if Position.Type == 'Long':
                        Account.ClosePosition(Position, 0.2, ExitPrice)

        if Today['color'] == 'darkBlue':
            Risk = 0.03
            EntryPrice = Today['close']
            AccountValue = Account.TotalValue(EntryPrice)
            EntryCapital = AccountValue * Risk
            if EntryCapital >= 0:
                try:
                    Account.EnterPosition('Long', EntryCapital, EntryPrice)
                except ValueError:
                    pass
    except ValueError:
        pass
def Logic(Account, Lookback, LookbackPeriod):
    try:
        # Load into period class to simplify indexing
        Lookback = helpers.Period(Lookback)

        Today = Lookback.loc(0)  # Current candle
        Yesterday = Lookback.loc(-LookbackPeriod)  # Previous candle
        print('from {} to {}'.format(Yesterday['date'], Today['date']))

        if Today['close'] < Yesterday['close']:
            ExitPrice = Today['close']
            for Position in Account.Positions:
                if Position.Type == 'Long':
                    Account.ClosePosition(Position, 1, ExitPrice)

        if Today['close'] > Yesterday['close']:
            EntryPrice = Today['close'] + (Today['close'] * FeesSpread)
            EntryCapital = Account.BuyingPower
            if EntryCapital > 0:
                Account.EnterPosition('Long', EntryCapital, EntryPrice)
    except ValueError:
        pass  # Handles lookback errors in beginning of dataset