avatarAshmeen Kaur

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

7423

Abstract

o lower. One should always remember that this indicator is very lagging and therefore has to be used with extreme caution.</p><p id="a101">Since it has been created by Wilder Wiles, also the creator of the Relative Strength Index, it uses Wilder’s own type of moving average, the smoothed kind. To simplify things, the smoothed moving average can be found through a simple transformation of the exponential moving average.</p><figure id="ef99"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*kcMsTOLJ3uJyUeN_.png"><figcaption></figcaption></figure><p id="485e">The above formula means that a 100 smoothed moving average is the same thing as (100 x 2) -1 = 199 exponential moving average. While we are on that, we can code the exponential moving average using this function:</p><div id="b794"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">ma</span>(<span class="hljs-params">Data, lookback, what, where</span>):

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(Data)):
  <span class="hljs-keyword">try</span>:
    Data[i, where] = (Data[i - lookback + <span class="hljs-number">1</span>:i + <span class="hljs-number">1</span>, what].mean())
    
        <span class="hljs-keyword">except</span> IndexError:
            <span class="hljs-keyword">pass</span>
<span class="hljs-keyword">return</span> Data</pre></div><div id="7a41"><pre>def ema(Data, alpha, lookback, what, <span class="hljs-built_in">where</span>):

<span class="hljs-comment"># alpha is the smoothing factor</span>
<span class="hljs-comment"># window is the lookback period</span>
<span class="hljs-comment"># what is the column that needs to have its average calculated</span>
<span class="hljs-comment"># where is where to put the exponential moving average</span>

alpha = alpha / (lookback + 1.0)
beta  = 1 - alpha

<span class="hljs-comment"># First value is a simple SMA</span>
Data = ma(Data, lookback, what, <span class="hljs-built_in">where</span>)

<span class="hljs-comment"># Calculating first EMA</span>
Data[lookback + 1, <span class="hljs-built_in">where</span>] = (Data[lookback + 1, what] * alpha) + (Data[lookback, <span class="hljs-built_in">where</span>] * beta)</pre></div><div id="3da7"><pre><span class="hljs-comment"># Calculating the rest of EMA</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(lookback + <span class="hljs-number">2</span>, <span class="hljs-built_in">len</span>(Data)):
        <span class="hljs-keyword">try</span>:
            Data[i, where] = (Data[i, what] * alpha) + (Data[i - <span class="hljs-number">1</span>, where] * beta)
    
        <span class="hljs-keyword">except</span> IndexError:
            <span class="hljs-keyword">pass</span>
<span class="hljs-keyword">return</span> Data</pre></div><p id="8783">Below is the function code that calculates the ATR.</p><div id="b80a"><pre>def atr(<span class="hljs-keyword">data</span>, lookback, high, low, close, <span class="hljs-keyword">where</span>):

<span class="hljs-keyword">data</span> = adder(<span class="hljs-keyword">data</span>, <span class="hljs-number">1</span>)
  
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(<span class="hljs-keyword">data</span>)):
    
    <span class="hljs-keyword">try</span>:
        
        <span class="hljs-keyword">data</span>[i, <span class="hljs-keyword">where</span>] = max(<span class="hljs-keyword">data</span>[i, high] - <span class="hljs-keyword">data</span>[i, low], abs(<span class="hljs-keyword">data</span>[i, high] - <span class="hljs-keyword">data</span>[i - <span class="hljs-number">1</span>, close]), abs(<span class="hljs-keyword">data</span>[i, low]  - <span class="hljs-keyword">data</span>[i - <span class="hljs-number">1</span>, close]))
        
    except ValueError:
        
        pass
    
<span class="hljs-keyword">data</span>[<span class="hljs-number">0</span>, <span class="hljs-keyword">where</span>] = <span class="hljs-number">0</span>   
  
<span class="hljs-keyword">data</span> = ema(<span class="hljs-keyword">data</span>, <span class="hljs-number">2</span>, (lookback * <span class="hljs-number">2</span>) - <span class="hljs-number">1</span>, <span class="hljs-keyword">where</span>, <span class="hljs-keyword">where</span> + <span class="hljs-number">1</span>)</pre></div><div id="e149"><pre><span class="hljs-keyword">data</span> = deleter(<span class="hljs-keyword">data</span>, <span class="hljs-keyword">where</span>, <span class="hljs-number">1</span>)

<span class="hljs-keyword">data</span> = jump(<span class="hljs-keyword">data</span>, lookback)

<span class="hljs-keyword">return</span> <span class="hljs-keyword">data</span></pre></div><p id="3950">Let us try applying the code on OHLC data and see the plot of a 14-period Average True Range:</p><div id="da61"><pre><span class="hljs-attr">my_data</span> = atr(my_data, <span class="hljs-number">14</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>)</pre></div><figure id="8f6c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*AI40oZyZ11lSAGcg.png"><figcaption><b>EURUSD daily values in the first panel with the 14-period Average True Range in the second panel.</b></figcaption></figure><p id="0934">Now we are ready to continue with the choppiness index. Let us consider that we will calculate a 20-period Average True Range on our OHLC historical data:</p><div id="0afd"><pre><span class="hljs-comment"># Adding a few columns</span>

<span class="hljs-attr">my_data</span> = adder(my_data, <span class="hljs-number">10</span>)</pre></div><div id="4e56"><pre><span class="hljs-comment"># Calculating a 20-period ATR</span> <span class="hljs-attr">my_data</span> = atr(my_data, <span class="hljs-number">20</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>)</pre></div><p id="fe8e">Now, the first step into the indicator is, to sum up, the values of the ATR together. This intuition can be coded in the following manner (Full function code provided below):</p><div id="d525"><pre><span class="hljs-comment"># Calculating the Sum of ATR's (atr_col is the index where the ATR is stored, in our example, it is 4)</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(my_data)):</pre></div><div id="8d39"><pre>my_data[i, <span class="hljs-built_in">where</span>] = my_data[i - lookback + 1:i + 1, atr_col].<span class="hljs-built_in">sum</span>()</pre></div><p id="f3d8">Now, we have to calculate the range from the highest to lowest using the max() and min() built-in functions. The code should resemble the following:</p><div id="4e6e"><pre><span class="hljs-comment"># Calculating the range</span> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">ran

Options

ge</span>(<span class="hljs-built_in">len</span>(my_data)): <span class="hljs-keyword">try</span>: my_data[i, <span class="hljs-number">5</span>] = <span class="hljs-built_in">max</span>(my_data[i - lookback + <span class="hljs-number">1</span>:i + <span class="hljs-number">1</span>, <span class="hljs-number">1</span>] - <span class="hljs-built_in">min</span>(my_data[i - lookback + <span class="hljs-number">1</span>:i + <span class="hljs-number">1</span>, <span class="hljs-number">2</span>])) <span class="hljs-keyword">except</span>: <span class="hljs-keyword">pass</span></pre></div><p id="8dd6">Next, we calculate the ratio between the two measures we have just derived. The code can be as simple as:</p><div id="6fde"><pre><span class="hljs-comment"># Calculating the Ratio</span> <span class="hljs-section">my_data[:, 6] = my_data[:, 4] / my_data[:, 5]</span></pre></div><p id="90b7">And finally, we simply apply the function as presented above, using this code:</p><div id="2f0c"><pre># <span class="hljs-function">Calculate the Choppiness Index <span class="hljs-keyword">for</span> i in <span class="hljs-title">range</span><span class="hljs-params">(len(Data))</span>:

Data[i, <span class="hljs-number">7</span>] =</span> <span class="hljs-number">100</span> * np.<span class="hljs-built_in">log</span>(Data[i, <span class="hljs-number">6</span>]) * (<span class="hljs-number">1</span> / np.<span class="hljs-built_in">log</span>(<span class="hljs-number">20</span>))</pre></div><figure id="84eb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*Pdavt5otr708my32.png"><figcaption><b>EURUSD in the first panel with the 20-period Choppiness Index in the second panel.</b></figcaption></figure><div id="a88b"><pre><span class="hljs-keyword">def</span> <span class="hljs-title function_">choppiness_index</span>(<span class="hljs-params">Data, lookback, high, low, where</span>):

<span class="hljs-comment"># Calculating the Sum of ATR's</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(Data)):
    Data[i, where] = Data[i - lookback + <span class="hljs-number">1</span>:i + <span class="hljs-number">1</span>, <span class="hljs-number">4</span>].<span class="hljs-built_in">sum</span>()    

<span class="hljs-comment"># Calculating the range</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(Data)):
    <span class="hljs-keyword">try</span>:
        Data[i, where + <span class="hljs-number">1</span>] = <span class="hljs-built_in">max</span>(Data[i - lookback + <span class="hljs-number">1</span>:i + <span class="hljs-number">1</span>, <span class="hljs-number">1</span>] - <span class="hljs-built_in">min</span>(Data[i - lookback + <span class="hljs-number">1</span>:i + <span class="hljs-number">1</span>, <span class="hljs-number">2</span>]))
    <span class="hljs-keyword">except</span>:
        <span class="hljs-keyword">pass</span></pre></div><div id="26e1"><pre><span class="hljs-comment"># Calculating the Ratio</span>
Data[:, <span class="hljs-built_in">where</span> + 2] = Data[:, <span class="hljs-built_in">where</span>] / Data[:, <span class="hljs-built_in">where</span> + 1]

<span class="hljs-comment"># Calculate the Choppiness Index</span>
<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(len(Data)):
    
    Data[i, <span class="hljs-built_in">where</span> + 3] = 100 * np.log(Data[i, <span class="hljs-built_in">where</span> + 2]) * (1 / np.log(lookback))</pre></div><div id="afbd"><pre><span class="hljs-comment"># Cleaning</span>
Data = deleter(Data, 5, 3)

<span class="hljs-built_in">return</span> Data</pre></div><figure id="0506"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*Pus4gyPeLlz_vLbr.png"><figcaption><b>USDCHF in the first panel with the 20-period Choppiness Index in the second panel.</b></figcaption></figure><p id="a466">The choppiness index function can therefore be called using the following code:</p><div id="c8a9"><pre><span class="hljs-attr">my_data</span> = choppiness_index(my_data, <span class="hljs-number">20</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">4</span>)</pre></div><figure id="4ed9"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*_oe4B9oeIE-hr1Yz.png"><figcaption><b>GBPUSD in the first panel with the 20-period Choppiness Index in the second panel.</b></figcaption></figure><h1 id="f15a">Using the Choppiness Index</h1><p id="549d">The way to use the choppiness index is to place the barriers by default at 38.2% and 61.8%, then we interpret the readings as follow:</p><ul><li><b>Readings above 61.8% indicate a choppy market that is bound to breakout. We should be ready for some directional.</b></li><li><b>Readings below 38.2% indicate a strong trending market that is bound to stabilize. Hence, it may not be the best idea to follow the trend at the moment.</b></li></ul><figure id="7bc6"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*MA4E4UosNty1IRHD.png"><figcaption><b>EURCAD in the first panel with the 20-period Choppiness Index in the second panel.</b></figcaption></figure><p id="3618">If you want to see how to create all sorts of algorithms yourself, feel free to check out Lumiwealth. From algorithmic trading to blockchain and machine learning, they have <i>hands-on</i> detailed courses that I highly recommend.</p><div id="fead" class="link-block">
      <a href="https://www.lumiwealth.com/algorithmic-trading-landing-page/?utm_source=influence&amp;utm_medium=medium&amp;utm_campaign=sofien">
        <div>
          <div>
            <h2>Learn Algorithmic Trading with Python Lumiwealth</h2>
            <div><h3>undefined</h3></div>
            <div><p>undefined</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*FbCz_ARtbOdywMlC)"></div>
          </div>
        </div>
      </a>
    </div><h1 id="e420">Summary</h1><p id="05a4">To sum up, what I am trying to do is to simply contribute to the world of objective technical analysis which is promoting more transparent techniques and strategies that need to be back-tested before being implemented. This way, technical analysis will get rid of the bad reputation of being subjective and scientifically unfounded.</p><p id="5d41">I recommend you always follow the the below steps whenever you come across a trading technique or strategy:</p><ul><li><i>Have a critical mindset and get rid of any emotions.</i></li><li><i>Back-test it using real life simulation and conditions.</i></li><li><i>If you find potential, try optimizing it and running a forward test.</i></li><li><i>Always include transaction costs and any slippage simulation in your tests.</i></li><li><i>Always include risk management and position sizing in your tests.</i></li></ul><p id="beb3">Finally, even after making sure of the above, stay careful and monitor the strategy because market dynamics may shift and make the strategy unprofitable.</p></article></body>

How to manage time while you are in a long-distance relationship

A long-distance relationship advice

Photo by Maddi Bazzocco on Unsplash

This age of Video calls and messengers shows that maintaining a long-distance relationship would be easier than earlier now.

There are four major challenges for long-distance relationships:

1. Trust

Photo by Jannis Lucas on Unsplash

Trust is playing a significant role in keeping any relationship. In the long-distance as partners rarely meet, so the question of trust arises between them. You don’t know what your significant other is up to.

Let yourself trust — and earn that trust yourself.

2. Communication

Photo by free stocks on Unsplash

There’s always a barrier between you when talking to your partner. Due to advancement in technology, we can use various modes to communicate with the partner. Some of them are partner calls, video calls, text messages, graphic messages, love themes, emoticons etc. It's advisable to use each method to avoid the feeling of distance.

Apart from modes of communication, the message transmit must be clear to understand to avoid the situation of chaos.

3. Activities

Photo by Vladimir Kudinov on Unsplash

Usually, partners who reside near enjoy some activities which help them feel special. But in the distance, No in-person cooking, going to the gym, holding hands in the park, or anything that involves closeness!

60% of couples in a long-distance relationship will stay together.

4. Take the Love Language Quiz

Do you or your partner value quality time? Quality time lovers need to spend the most time with each other.

Love to hear words of affirmation? Make sure you’re getting the words you want to feel loved. You may need to hear from your significant other how much you’re loved for reassurance, or want compliments from your partner to feel unique and special.

There are specific considerations that will make a healthy distant relationship.

1. Be Committed to the Relationship-

Photo by Kelly Sikkema on Unsplash

It’s about time value when we Prioritise our schedules well and fix a common time to communicate. It's really important to understand the depth of a relationship by committing. When both commit to each other in all manner and follow the common time decided, it will lead to a healthy bond.

2. Don’t rely solely on technology.-

Photo by Євгенія Височина on Unsplash

Technology helps to communicate better in distant relations but it will not create a personal touch. The personal touch is the heartbeat of every relationship and can be maintained by fixing short meets or arrange gifts for each other.

As we all know the frequency of meets is very less in distance relation, gifts play a great role to show love/feel special to another person even when both are far away.

3. Reframe the situation as a positive — and believe in it.

Given the positives that accompany some long-distance relationships, it may very well make sense to celebrate your situation as something that can bring benefits despite its drawbacks.

Respect the reason why you’re apart. Instead of cribbing that both are in a long-distance relationship, we draw the benefits of such situation like waiting for calling time, craze and excitement develop in case of gifts, planning for short meets etc.

4. Do Stuff Together Even Though You’re Apart

Photo by Hannah Busing on Unsplash

When we are apart, we can feel a sense of togetherness also. We can think of the tasks or activities in which we can involve each other. Finding common interest is the best way to do it.

For instance, Giving a video call to a partner while cooking his favourite dish. Another can be helping a partner in arranging things in an organised manner by smart techniques. Another way is helping in promoting the content created by one through others social profiles etc.

5. Use this time to get to know them well

Photo by Annie Spratt on Unsplash

The time we get in a distant relation is utilised to know each other in a better manner. You can count such as a courtship period, apart from knowing both love, understanding, compatibility will develop through fun activities. Count Down The Days Until You’re Reunited.

The more you get involved in communications, the better it is to create a perfect bond.

6. Remind your partner frequently what you love about your relationship.

Photo by Priscilla Du Preez on Unsplash

If both will frequently discuss what they find best in their love bond, it will strengthen and maintain the relationship.

One doesn't need to wait for others to initiate such reminders. Anyone can do so to make the other person realise how special they are for each other.

Such reminders will act as a-pillars to their love relationship.

7. Learn how to address important issues both remotely and in person.

Distant relations are tough to maintain as remotely many issues were developed a mess. Both must act maturely and before getting any conclusion, must give a chance to others to explain once.

Be Open Says;

Relationships
Long Distance
Relationship Advice
Love
Emotions
Recommended from ReadMedium