(df, n)
return out(SETTINGS, df, result)
Average True Range
Average True Range
Average True Range
def ATR(df, n):
    """
    Average True Range
    """
    L = len(df['High'])
    TR_l = [None]*L
    for i in range(1, L):
        TR = max(df['High'].iloc[i] - df['Low'].iloc[i], \
					abs(df['High'].iloc[i] - df['Close'].iloc[i-1]), \
					abs(df['Low'].iloc[i] - df['Close'].iloc[i-1]) )
        TR_l[i] = TR
    
    TR_s = pd.Series(TR_l[1::])
    
    alpha = 1.0/n
    result = emaHelper(TR_s, n, alpha)

    return out(SETTINGS, df, result)
def ATR ( df , n ) : L = len ( df [ 'High' ] ) TR_l = [ None ] * L for i in range ( 1 , L ) : TR = max ( df [ 'High' ] . iloc [ i ] - df [ 'Low' ] . iloc [ i ] , abs ( df [ 'High' ] . iloc [ i ] - df [ 'Close' ] . iloc [ i - 1 ] ) , abs ( df [ 'Low' ] . iloc [ i ] - df [ 'Close' ] . iloc [ i - 1 ] ) ) TR_l [ i ] = TR TR_s = pd . Series ( TR_l [ 1 : : ] ) alpha = 1.0 / n result = emaHelper ( TR_s , n , alpha ) return out ( SETTINGS , df , result )