def tenkan_sen_kijun_sen_cross_f_sl(row):
    '''
    Tenkan Sen Kijun Sen cross - only stron version (algo 1_1)
    Result files
     - fixed senkou_span_b - 2020-7-23_10_6_24
     - senkou_span_b o _a - 2020-7-23_10_14_10
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        if ((row['tenkan_sen'] > row['kijun_sen'])
                and (row['tenkan_sen'] > row['senkou_span_a'])
                and (row['tenkan_sen'] > row['senkou_span_b'])
                and (row['c_mean'] > row['c_mean_26'])):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        if row['senkou_span_a'] > row['senkou_span_b']:
                            TRANS.set_sl(sl_type='fixed',
                                         sl_factor=row['senkou_span_b'],
                                         date_sl=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        else:
                            TRANS.set_sl(sl_type='fixed',
                                         sl_factor=row['senkou_span_a'],
                                         date_sl=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['low'] < TRANS.stop_loss:
            # closing trade when SL is hit
            TRANS.close_transaction(TRANS.stop_loss,
                                    get_date_only(row),
                                    be_verbose=BE_VERBOSE)
            BUDZET.manage_amount(TRANS.close_total)
            TRANS.reset_values()
            return -1
        if row['tenkan_sen'] < row['kijun_sen']:
            # closing trade when close signal appears
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
def algo_1_2(row):
    '''
    Tenkan Sen Kijun Sen cross - strong version (algo 1_1)
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        if row['kumo'] == 1:
            condition = ((row['tenkan_sen'] > row['senkou_span_b'])
                         and (row['tenkan_sen'] < row['senkou_span_a']))
        elif row['kumo'] == -1:
            condition = ((row['tenkan_sen'] < row['senkou_span_b'])
                         and (row['tenkan_sen'] > row['senkou_span_a']))
        else:
            condition = False
        if (condition and (row['cross'] == 1) and (row['cross_2'] == -1)
                and (row['c_1'] > row['c26']) and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                if stock_number > 0:
                    TRANS.open_transaction(stock_number,
                                           row['open'],
                                           get_date_only(row),
                                           be_verbose=BE_VERBOSE)
                    TRANS.define_risk(verbose=BE_VERBOSE)
                    TRANS.curr_value(price=row['close'],
                                     date=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                    TRANS.set_sl(sl_type='fixed',
                                 sl_factor=(row['open'] - row['atr_sl']),
                                 date_sl=get_date_only(row),
                                 be_verbose=BE_VERBOSE)
                    BUDZET.manage_amount(-TRANS.open_total)
                    return 1
    else:
        if ((row['cross'] == -1) and (row['cross_2'] == 1)
                or (row['c_1'] < TRANS.stop_loss)):
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
def kumo_brekaut_02_01(row):
    '''
    Kumo breakout modified, removed c_1 > c_26
    1. SŁABE
    
    2.
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if ((row['kumo'] == 1) and (row['c_1'] > row['senkou_span_a'])
                and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        temp_sl = row['senkou_span_a'] - row['atr_sl']
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=temp_sl,
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            temp_sl = row['senkou_span_a'] - row['atr_sl']
            TRANS.set_sl(sl_type='fixed',
                         sl_factor=temp_sl,
                         date_sl=get_date_only(row),
                         be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
예제 #4
0
def kumo_brekaut_01_02(row):
    '''
    To jest dopiero prawdziwy Kumo breakout, clear stop loss
    1.
    total: 45383.67,  prct: 41.64%,  years: 10,  prct/year: 4.16%, nr -: 55,
    sum -: -18812.82, nr +: 54, sum +: 64196.49, ATR_RAIO: 0.5
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BOSSA_DATE

    if get_date_only(row) == BOSSA_DATE:
        BE_VERBOSE = True
    else:
        BE_VERBOSE = False
    if not TRANS.in_transaction:
        if ((row['kumo'] == 1) and (row['close'] > row['senkou_span_a'])
                and (row['close'] > row['c26']) and (row['kumo26'] == 1)):
            stock_number = TRANS.how_many_stocks(row['close'], BUDZET.equity)
            temp_sl = row['senkou_span_b'] - row['atr_sl']
            TRANS.open_transaction(stock_number,
                                   row['close'],
                                   get_date_only(row),
                                   be_verbose=False)
            TRANS.curr_value(price=row['close'],
                             date=get_date_only(row),
                             be_verbose=False)
            temp_sl = row['senkou_span_b'] - row['atr_sl']
            if BE_VERBOSE:
                print('+++ {} KUPUJE {}'.format(get_date_only(row), STOCK))
            TRANS.set_sl(sl_type='fixed',
                         sl_factor=temp_sl,
                         date_sl=get_date_only(row),
                         be_verbose=BE_VERBOSE)
            TRANS.define_risk(verbose=BE_VERBOSE)
            BUDZET.manage_amount(-TRANS.open_total)
            return 1
    else:
        if row['close'] < TRANS.stop_loss:
            if BE_VERBOSE:
                print('--- {} ZAMYKAM {}'.format(get_date_only(row), STOCK))
            TRANS.close_transaction(row['close'],
                                    get_date_only(row),
                                    be_verbose=BE_VERBOSE)
            BUDZET.manage_amount(TRANS.close_total)
            TRANS.reset_values()
            return -1
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=False)
            temp_sl = row['senkou_span_b'] - row['atr_sl']
            curr_sl = TRANS.stop_loss
            TRANS.set_sl(sl_type='fixed',
                         sl_factor=temp_sl,
                         date_sl=get_date_only(row),
                         be_verbose=False)
            new_sl = TRANS.stop_loss
            if new_sl > curr_sl and BE_VERBOSE:
                print('''
                       ^^^ {} UP SL {}, {:.2f}, bought {}, open {}
                       '''.format(get_date_only(row), STOCK, TRANS.stop_loss,
                                  TRANS.open_date, TRANS.open_price))
                #TRANS.show_trade()
            TRANS.register_transaction(verbose=False)
def videos_strategy(row):
    '''
    Tenkan Sen Kijun Sen cross - strong version (algo 1_1)
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    global MULT_RISK
    if not TRANS.in_transaction:
        if (((row['c_1']) > row['senkou_span_a'] + row['atr_sl'])
                and ((row['c_1']) > row['senkou_span_b'] + row['atr_sl'])
                and (row['tenkan_sen'] > row['kijun_sen'])
                and (row['c_mean'] > row['c_mean_26'])):  # and
            #(row['s_s_a_m26'] > row['s_s_b_m26'])):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=row['senkou_span_b'] -
                                     row['atr_sl'],
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        TRANS.curr_value(price=row['close'],
                         date=get_date_only(row),
                         be_verbose=BE_VERBOSE)
        if row['tenkan_sen'] < row['kijun_sen']:
            pass
            """
            if row['open'] != 0:
                TRANS.close_transaction(row['open'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                #print('zamykam, bo przeciecie tankan i kijun')
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
            """
        if row['c_1'] < TRANS.stop_loss:
            TRANS.close_transaction(row['open'],
                                    get_date_only(row),
                                    be_verbose=BE_VERBOSE)
            BUDZET.manage_amount(TRANS.close_total)
            TRANS.reset_values()
            #print('zamykam, bo stop loss')
            return -1
        if TRANS.current_value > TRANS.open_total + MULT_RISK * TRANS.risk:
            if row['tenkan_sen'] - row['atr_sl'] > TRANS.stop_loss:
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=(row['senkou_span_a'] - row['atr_sl']),
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
        if TRANS.current_value < TRANS.open_total + MULT_RISK * TRANS.risk:
            if row['kijun_sen'] - row['atr_sl'] > TRANS.stop_loss:
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=(row['senkou_span_b'] - row['atr_sl']),
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
def kumo_brekaut_01_03(row):
    '''
    To jest dopiero prawdziwy Kumo breakout, clear stop loss. Dodałem 
    rzeczywiste test wyjścia z chmury 
    1. SLABE
    total: 8702.63,        prct: 8.62%,        years: 10, prct/year: 0.86%, 
    nr -: 61, sum -: -9491.73, nr +: 40,  sum +: 18194.36,       ATR_RAIO: 0.5
    2. 

    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if ((row['kumo'] == 1) and (row['c_1'] > row['senkou_span_a'])
                and (row['c_3'] < row['senkou_span_a'])
                and (row['c_1'] > row['c26']) and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        temp_sl = row['senkou_span_b'] - row['atr_sl']
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=temp_sl,
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            temp_sl = row['senkou_span_b'] - row['atr_sl']
            TRANS.set_sl(sl_type='fixed',
                         sl_factor=temp_sl,
                         date_sl=get_date_only(row),
                         be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
def kumo_brekaut_01_02(row):
    '''
    To jest dopiero prawdziwy Kumo breakout, clear stop loss 
    1.
    total: 45383.67,  prct: 41.64%,  years: 10,  prct/year: 4.16%, nr -: 55,
    sum -: -18812.82, nr +: 54, sum +: 64196.49, ATR_RAIO: 0.5
    2. 

    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if ((row['kumo'] == 1) and (row['c_1'] > row['senkou_span_a'])
                and (row['c_1'] > row['c26']) and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        temp_sl = row['senkou_span_b'] - row['atr_sl']
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=temp_sl,
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            temp_sl = row['senkou_span_b'] - row['atr_sl']
            TRANS.set_sl(sl_type='fixed',
                         sl_factor=temp_sl,
                         date_sl=get_date_only(row),
                         be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
def kumo_brekaut_02(row):
    '''
    Kumo breakout modified, removed c_1 > c_26
    1.
    total: 34600.39, percent: 31.74%, years: 10, percent/year: 3.17%, 
    number -: 60, sum -: -20757.86, number +: 49, sum +: 55358.25, ATR_RAIO: 0.5
    
    2.
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if ((row['kumo'] == 1) and (row['c_1'] > row['senkou_span_a'])
                and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        temp_sl = row['senkou_span_a'] - row['atr_sl']
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=temp_sl,
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            if TRANS.current_value > (TRANS.open_value + (3 * TRANS.risk)):
                new_sl = (TRANS.current_value -
                          TRANS.risk) / TRANS.stocks_number
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=new_sl,
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            else:
                temp_sl = row['senkou_span_a'] - row['atr_sl']
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=temp_sl,
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
def kumo_brekaut_01_01(row):
    '''
    Kumo breakout, clear stop loss 
    1. slabe
    total: 42600.90, prct: 39.08%, years: 10, prct/year: 3.91%,  nr -: 57,
    sum -: -18267.29,  nr +: 52,  sum +: 60868.18,  ATR_RAIO: 0.5
    2.
    total: -9525.87,  prct: -63.51%,  years: 10,  prct/year: -6.35%, nr -: 14,
    sum -: -9677.75, nr +: 1, sum +: 151.89, ATR_RAIO: 50
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if ((row['kumo'] == 1) and (row['c_1'] > row['senkou_span_a'])
                and (row['c_1'] > row['c26']) and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        temp_sl = row['senkou_span_a'] - row['atr_sl']
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=temp_sl,
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            temp_sl = row['senkou_span_a'] - row['atr_sl']
            TRANS.set_sl(sl_type='fixed',
                         sl_factor=temp_sl,
                         date_sl=get_date_only(row),
                         be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
def kumo_brekaut_01(row):
    '''
    Kumo breakout
    1.
    total: 42122.05, percent: 38.64%, years: 10, percent/year: 3.86%, nr -: 59,
    sum -: -18925.83, number +: 50, sum +: 61047.88, ATR_RAIO: 0.5
    2.
    total: 47832.74, percent: 43.88%, years: 10, prct/year: 4.39%, nr -: 58,
    sum -: -17366.41, number +: 51, sum +: 65199.15, ATR_RAIO: 1
    3.
    total: 91883.32, prct: 153.14%, years: 10, prct/year: 15.31%, nr -: 36,
    sum -: -18271.12, nr +: 24, sum +: 110154.43, ATR_RAIO: 33
    4.
    total: 114699.25, prct: 327.71%, years: 10, prct/year: 32.77%, nr -: 14,
    sum -: -9509.71, nr +: 21, sum +: 124208.96, ATR_RAIO: 50
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if ((row['kumo'] == 1) and (row['c_1'] > row['senkou_span_a'])
                and (row['c_1'] > row['c26']) and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        temp_sl = row['senkou_span_a'] - row['atr_sl']
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=temp_sl,
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            if TRANS.current_value > (TRANS.open_value + (3 * TRANS.risk)):
                new_sl = (TRANS.current_value -
                          TRANS.risk) / TRANS.stocks_number
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=new_sl,
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            else:
                temp_sl = row['senkou_span_a'] - row['atr_sl']
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=temp_sl,
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)
def algo_2_0(row):
    '''
    Tenkan Sen Kijun Sen cross - strong version 2 all in one
    '''
    global BUDZET
    global TRANS_ID
    global TRANS
    global COUNT
    global STOCK
    global data
    global BE_VERBOSE
    if not TRANS.in_transaction:
        condition = True
        if (condition and (row['c_1'] > row['kijun_sen'])
                and (row['c_1'] > row['c26']) and (row['kumo26'] == 1)):
            if row['open'] != 0:
                if BUDZET.equity > 4:
                    stock_number = TRANS.how_many_stocks(
                        row['open'], BUDZET.equity)
                    if stock_number > 0:
                        TRANS.open_transaction(stock_number,
                                               row['open'],
                                               get_date_only(row),
                                               be_verbose=BE_VERBOSE)
                        TRANS.curr_value(price=row['close'],
                                         date=get_date_only(row),
                                         be_verbose=BE_VERBOSE)
                        TRANS.set_sl(sl_type='fixed',
                                     sl_factor=(row['kijun_sen'] -
                                                row['atr_sl']),
                                     date_sl=get_date_only(row),
                                     be_verbose=BE_VERBOSE)
                        TRANS.define_risk(verbose=BE_VERBOSE)
                        BUDZET.manage_amount(-TRANS.open_total)
                        return 1
    else:
        if row['c_1'] < TRANS.stop_loss:
            if row['open'] != 0:
                TRANS.close_transaction(row['close'],
                                        get_date_only(row),
                                        be_verbose=BE_VERBOSE)
                BUDZET.manage_amount(TRANS.close_total)
                TRANS.reset_values()
                return -1
            else:
                print('cena zamkniecia {}'.format(row['open']))
        else:
            TRANS.curr_value(row['close'],
                             date=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            if TRANS.current_value > (TRANS.open_value + (3 * TRANS.risk)):
                new_sl = (TRANS.current_value -
                          TRANS.risk) / TRANS.stocks_number
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=new_sl,
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            else:
                TRANS.set_sl(sl_type='fixed',
                             sl_factor=(row['kijun_sen'] - row['atr_sl']),
                             date_sl=get_date_only(row),
                             be_verbose=BE_VERBOSE)
            TRANS.register_transaction(verbose=BE_VERBOSE)