title: Heiken Ashi Using pandas python
body: <p><a href="https://i.stack.imgur.com/vIEKx.png" rel="noreferrer"><img src="https://i.stack.imgur.com/vIEKx.png" alt="enter image description here"></a>
  I was defining a function Heiken Ashi which is one of the popular chart type in Technical Analysis.
  I was writing a function on it using Pandas but finding little difficulty.
  This is how Heiken Ashi [HA] looks like-</p>
  
  <pre><code>                 Heikin-Ashi Candle Calculations
             HA_Close = (Open + High + Low + Close) / 4
             HA_Open = (previous HA_Open + previous HA_Close) / 2
             HA_Low = minimum of Low, HA_Open, and HA_Close
             HA_High = maximum of High, HA_Open, and HA_Close
  
                 Heikin-Ashi Calculations on First Run
              HA_Close = (Open + High + Low + Close) / 4
                     HA_Open = (Open + Close) / 2
                             HA_Low = Low
                             HA_High = High
  </code></pre>
  
  <p>There is a lot of stuff available on various websites using for loop and pure python but i think Pandas can also do job well.
  This is my progress-</p>
  
  <pre><code>   def HA(df):
  
         df['HA_Close']=(df['Open']+ df['High']+ df['Low']+ df['Close'])/4
  
         ha_o=df['Open']+df['Close']  #Creating a Variable
         #(for 1st row)
  
         HA_O=df['HA_Open'].shift(1)+df['HA_Close'].shift(1) #Another variable
         #(for subsequent rows)
  
         df['HA_Open']=[ha_o/2 if df['HA_Open']='nan' else HA_O/2]     
         #(error Part Where am i going wrong?)
  
         df['HA_High']=df[['HA_Open','HA_Close','High']].max(axis=1)
  
         df['HA_Low']=df[['HA_Open','HA_Close','Low']].min(axis=1)
  
         return df
  </code></pre>
  
  <p>Can Anyone Help me with this please?`
  It doesnt work....
  I tried on this-</p>
  
  <pre><code>  import pandas_datareader.data as web 
    import HA
    import pandas as pd
    start='2016-1-1'
    end='2016-10-30'
    DAX=web.DataReader('^GDAXI','yahoo',start,end)
  </code></pre>
  
  <p>This is the New Code i wrote</p>
  
  <pre><code>    def HA(df):
              df['HA_Close']=(df['Open']+ df['High']+ df['Low']+df['Close'])/4
  ...:        ha_o=df['Open']+df['Close']
  ...:        df['HA_Open']=0.0
  ...:        HA_O=df['HA_Open'].shift(1)+df['HA_Close'].shift(1)
  ...:        df['HA_Open']= np.where( df['HA_Open']==np.nan, ha_o/2, HA_O/2 )
  ...:        df['HA_High']=df[['HA_Open','HA_Close','High']].max(axis=1)
  ...:        df['HA_Low']=df[['HA_Open','HA_Close','Low']].min(axis=1)
  ...:        return df
  </code></pre>
  
  <p>But still the HA_Open result was not satisfactory</p>