<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Coinpocalypse on Medium]]></title>
        <description><![CDATA[Stories by Coinpocalypse on Medium]]></description>
        <link>https://medium.com/@coinpocalypse?source=rss-e67210086841------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*5r-4Z2Z0v4O7cTkunFqIlg.png</url>
            <title>Stories by Coinpocalypse on Medium</title>
            <link>https://medium.com/@coinpocalypse?source=rss-e67210086841------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 08:31:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@coinpocalypse/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Data selection in algorithmic scripting]]></title>
            <link>https://medium.com/@coinpocalypse/data-selection-in-algorithmic-scripting-720c0dc98e0b?source=rss-e67210086841------2</link>
            <guid isPermaLink="false">https://medium.com/p/720c0dc98e0b</guid>
            <category><![CDATA[pine-script]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Coinpocalypse]]></dc:creator>
            <pubDate>Mon, 18 Feb 2019 12:31:04 GMT</pubDate>
            <atom:updated>2019-02-18T12:31:04.375Z</atom:updated>
            <content:encoded><![CDATA[<p>As I mentioned in one of the earlier pieces I wrote, data selection in scripting is in my opinion one of the harder subjects in creating a stable and profitable bot. In IT it’s a well known saying: <em>“Garbage in, garbage out.”</em> Writing a bot is one thing, but the data you decide to feed it and let it analyse, will determine - in great part - the reliability and stability of your bot and therefore your future outcome.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*eDM3eOpPfzGMaJ_R7hdNpg.jpeg" /></figure><p>All calculations have a source <em>(data type)</em> and they need to be specified, so the code knows what to calculate with. It is absolutely worth spending some of your time on this subject, to get a good understanding of how these data types affect your scripts. It takes a while to wrap your head around them and how/when/where you apply them. FYI: I am by no means an expert in this field, so look at this as nothing more than anecdotal experience.</p><p>I will write my way through the basics of what I think will help you on your way and in this case that means plotting the OHLC candles.</p><p>There are four basic candle values: open, high, low, close. When you select one of them, it really means you select the following data: <em>“The open/high/low/close data point of the time period you applied to the instrument.”</em></p><p>If we would plot these values in the simplest way, it would look like this in code <em>(Figure 1)</em> and on the chart <em>(Figure 2)</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*MI3kfIKPZIX2NttC-sFwvg.png" /><figcaption>Figure 1. Simple data type plot code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Cm6GCS2pUjLsBEJxjs7qkA.png" /><figcaption>Figure 2. How the plot code looks on a chart</figcaption></figure><p>Something to think about: only the open is known at the start of a period, assuming the high or low of a period is not the same as the open (which it can be). Only the close is known when a period is ended.</p><p>So, now you know how TradingView candlesticks are plotted, you can imagine the line chart, which is only plotted using the close and is therefore a lot <em>“cleaner”</em>.</p><p><strong>Different timeframes</strong></p><p>What if I want to use data from a different timeframe then the one I’m currently looking at? This requires the use of the security() function, which in Pine Script is used like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/681/1*fpLzaJVFFod6chEjpO_EGQ.png" /><figcaption>Figure 3. Pine Script security function</figcaption></figure><p>This function will need a symbol (including an exchange) like the following: “BINANCE:BTCUSDT”, so it will know where to pull the data from. If you want to pull data from chart you’re looking at, just use tickerid.</p><p>Then it looks at the resolution, which is the timeframe, for the 15 minute chart this is “15”, for the 4 hour chart it’s “240” and for the daily chart it’s “D”. If you want to pull data from the timeframe you’re looking at, you enter period.</p><p>The expression it needs is the data type, which I just discussed.</p><p>gaps and lookahead are more advanced parameters of this function, which are by default set to off and most of you are better off for it. If you want to play around with these settings, you should check this <a href="https://www.tradingview.com/wiki/Context_Switching,_The_%E2%80%98security%E2%80%99_Function">link</a>.</p><p>If I’m looking at a 15 minute Bitcoin chart and i want to see the daily data, I will need to code the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*1_xjMDU0Lz5eNa-w4cjbfA.png" /><figcaption>Figure 4. Different timeframe selection.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6VckGfjLMfcHYAo-9NJEBw.png" /><figcaption>Figure 5. Result of different timeframe selection</figcaption></figure><p>This worked perfectly, but it would still be nice to turn this into a more dynamic piece of code, so you can edit the values through a menu. I would like a selection of resolutions and expressions to choose from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*I48ZrRHhA5GG6FJ8PNMOGQ.png" /><figcaption>Figure 6. Dynamic timeframe and data selection</figcaption></figure><p>The results from this code above is exactly the same as in <em>Figure 5</em>, so let’s a bit to give it more functionality. What if you don’t want to see all four plots? You should be able to switch them off. We do this by creating an option in the menu for each plot and altering the lines with plot function. You do this by using a language operator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/670/1*brigjr5k8afED-y-l0Cr9w.png" /><figcaption>Figure 7. Language operator</figcaption></figure><p>You should read this as following: If ‘expr1&#39; is, it will execute ‘expr2’. If not, then it will execute ‘expr3’. Without this making much sense in a grammatical way, it does show the opportunity for using this as a switch. Let me show you how this looks in code, it makes more sense in my opinion.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/881/1*elJBfnTC9hTVWCQeOxoNZQ.png" /><figcaption>Figure 8. Language operator coded</figcaption></figure><p>You can see that I added a showPlot variable for each line, which can be set to true or false. Then, in the plot codes, I added the language operator which now reads a lot better: If showPlot is true, then show Data or else (false) do nothing (na). In the menu it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/402/1*EDXJ2RDHgDkrX2E-xycHIA.png" /><figcaption>Figure 9. A dynamic data selection menu</figcaption></figure><p>So, now i can plot one line (by turning 3 of them off) with a lesser used data type of my selection, HLC3 in this instance, which stands for (high + low + close) / 3, on a daily timeframe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dM_JAKFNMLv9daClAopCag.png" /><figcaption>Figure 10. HLC3 `data type on daily timeframe</figcaption></figure><p><strong>Exotic data inputs</strong></p><p>Experimenting with data types makes your bot more versatile and sometimes it definitely makes more sense to use one instead of the other. What would happen if you choose to use very different inputs to use in your calculations? What about using OBV as the calculations for Bollinger Bands?</p><p><strong>Extra Dimensions</strong></p><p>If playing with data types makes your bot more versatile, then playing with timeframes opens a door to new dimensions for your bot, by being able to give it instructions such as:</p><ul><li>Only buy/long when the daily close is above the SMA200 and the RSI is leaving oversold conditions on the 1 hour timeframe</li><li>Do not sell/short when the 4 hour close is above the Ichimoku Tenkan-sen and 30 minute OBV is still rising</li><li>Do not execute a buy/long or sell/short at all when the daily Bitcoin ATR (volatility) is below 4%.</li></ul><p><em>These are just examples, but demonstrate the newfound abilities.</em></p><p>I hope this piece will help you in trying out a lot of combinations, i have no doubt there is winner in there, thanks for reading!</p><p>You can follow me on <a href="https://twitter.com/coinpocalypse">Twitter</a>, where you can also find the link to my bot which shares it’s calls for free on Telegram! Im also on <a href="http://bit.ly/coinpocalypse-scripts">TradingView</a>, where you can see and use my scripts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=720c0dc98e0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Simple Start]]></title>
            <link>https://medium.com/@coinpocalypse/a-simple-start-80fe92c92b15?source=rss-e67210086841------2</link>
            <guid isPermaLink="false">https://medium.com/p/80fe92c92b15</guid>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[indicators]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[algorithmic-trading]]></category>
            <dc:creator><![CDATA[Coinpocalypse]]></dc:creator>
            <pubDate>Mon, 11 Feb 2019 10:59:14 GMT</pubDate>
            <atom:updated>2019-02-11T12:35:08.419Z</atom:updated>
            <content:encoded><![CDATA[<p>In this article I will explain some of the basic functions of Pine Script by creating a Moving Averages crossover strategy. If you follow along step by step, you too can make your own trend script!</p><p><strong>Ingredients</strong></p><p>So, what do you need for this script to work? For a simple script you only need a couple of things, but there are some basics. To get started, go to a chart in TradingView and click “<strong>Pine Editor”</strong> at the bottom of your screen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*AlpIYgug0xsZQiiA9A-RmQ.png" /><figcaption><em>Figure 1</em></figcaption></figure><p>You will now see a notepad-like editor, which we will use to create scripts. The first thing you will notice is the important line of //@version=3. This is critical and is needed to communicate that you will be using version 3 of Pine Script. Be sure to always start with this line.</p><p>There are two types of scripts within Pine Script, namely <em>study</em> and <em>strategy</em>. The main difference between them, is that you can create alerts under a study and you can backtest your script under strategy. Why TradingView split these functionalities is one of the great mystery’s of our time, but that is just the way it is.</p><p>In the example script loaded, the third line says plot(close). This means the script will plot a line of the current close data point of the instrument you apply it to. If you are used to looking at candlesticks, you know that they stand for the Open, High, Low and Close (OHLC) of a period. This means that a plot(low), would plot a line of the lows of every period that you have selected, such as the Daily, 4 Hours, 1 Hour etcetera. Selecting the data you for you script to calculate with is arguably one of the harder parts of algorithmic scripting, but I’ll be sure to dedicate one article to it in the series.</p><p><strong>Setting up your strategy</strong></p><p>So, let’s take a closer look at the strategy() function and replace the study() function in the editor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vooGMifm3OYCf7bkxHljgA.png" /><figcaption>Figure 2. Strategy function</figcaption></figure><p>Looks messy, but setting this up the right way will help making your backtest results a lot more reliable. Once you have your strategy running, you can find most of these settings in the configuration menu of your strategy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/466/1*M7ewR0kdeBaAKtApkSE0tg.png" /><figcaption>Figure 3. Srategy settings menu</figcaption></figure><p>And this is how that looks as code</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*afmAIbhbn1fyYhQK4Tf_RQ.png" /><figcaption>Figure 4. Strategy code in the editor</figcaption></figure><p>And this is what that means:</p><ul><li>Sets title and shorttitle to “A Simple Start - Strategy [CP]”</li><li>Sets overlay to ‘true’, so that the script will be layed over the price, instead of seperate pane. Usefull for Moving Averages, not so much for a RSI or OBV script.</li><li>Sets starting capital to test with to 50.000 USD. You want this to be a high number. If you are testing your script on Bitcoin for example, it will have trouble testing it at the time $BTC was at $20.000 a piece. You can always see what trouble that causes by setting this lower.</li><li>Pyramiding gives you the ability to layer buy orders with a designated percentage of your stash. Not needed in Moving Averages crossovers, so 0.</li><li>Sets commission type to percentage and value at 0.075%. Specifically for trading on Binance. If you have a bag of $BNB, the commission/trading fees are 0.075% (discount of 0.025%).</li><li>Disables intrabar strategy and order calculation. These are two settings that are best turned off, as they will mess with your backtest results greatly.</li><li>Sets the quantity value to 100%. So you will be trading with your entire stash from long to short, which is a great way to see the effectiveness of your strategy, specifically on Moving Averages crossovers.</li></ul><p>This might seem like a lot take in, but don’t underestimate the importance of setting the scope of your strategy.</p><p>Now that we’ve defined the scope, we can continue creating two Moving Averages, a <strong>fast</strong> one and a <strong>slow</strong> one. For this script we will use the Simple Moving Average. So let’s take a look at how Pine Script calculates the SMA.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*Lef-_oV3nqnLE0wVInyPWA.png" /><figcaption>Figure 5. SMA function in detail</figcaption></figure><p>To calculate we need a source and a length. The source is data that the calculation uses and for this example we will use the close data point. The length is the number of periods (bars) the calculation uses. The higher the length, the slower the Moving Average responds. So we will be using a small number for the Fast MA and a greater length for the Slow MA. After defining that MA’s we will use the plot function to draw them on your screen.</p><p>This is how that looks as code in your editor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*iY6cEEcdPM8-U2ldBwcE-w.png" /><figcaption>Figure 5. MA’s defined</figcaption></figure><p>As you can see, i gave the plot function some extra details, such as the color of the MA, the width of the line and a title. So now the Fast and Slow MA is set in stone with 5 and 25 periods, but I would like this to be easily changed. Actually, I want to do the same thing with the source of my data. So we can create a menu setting to change this with the input() function. That looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_RIKaNEwJ-vMDbbhoN4j2g.png" /><figcaption>Figure 7. Input is now dynamic</figcaption></figure><p>So, now the inputs of my SMA’s are dynamic and that makes testing a lot easier. To zoom in on the input() function, you can see that in the case of lengthFastMA, we set the default value to 5, the type to integer, which means it is a whole number and gave it a title so we can recognize it easily in the menu later on.</p><p>As you can see i also added some commentary to different parts of the code. This makes it easier to read if you want to share your code with others or for yourself when your scripts run into the hundreds of lines.</p><p>Now that we’ve got dynamic SMA’s, there are just two steps left.</p><ul><li>Defining the conditions that would signal a long/buy or short/sell signal.</li><li>Excuting that strategy</li></ul><p><strong>Defining conditions</strong></p><p>Conditions are basically rules. X is a bigger than Y for example, which in code would become x &gt; y . These mechanisms to compare values to eachother are called operators and i’ll also zoom in on them in a different article.</p><p>Fortunately Pine Script has an built-in function to detect crossovers, crossunders or just crosses. Let’s take a look at what information they need.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*oZOZKxyuE0CtoQE-7J5qRg.png" /><figcaption>Figure 8. Crossover function in detail</figcaption></figure><p>It looks like it needs to check two variables, ‘x’ and ‘y’, which we will replace with the Fast MA and the Slow MA. If it detects that this happened it will return a signal to us, namely a boolean, which is a datatype that can only consist of ‘true’ or ‘false’. So what we want to define is the following:</p><ul><li>Long/Buy signal: The Fast MA crosses over the Slow MA</li><li>Short/Sell signal: The Fast MA crosses under the Slow MA</li></ul><p>This is how that looks as code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*iM4jtDi52KqoOxGUl1zy8w.png" /><figcaption>Fig 9. Conditions defined</figcaption></figure><p>Now we are left with the final part of the script.</p><p><strong>Strategy execution</strong></p><p>Based on the conditions we just set with the crossover() and crossunder() function we need the last bit of code to execute the strategy when the conditions are met. This is done with the strategy.entry() function. Let’s take a closer look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/663/1*ekwmsWk3oCrV7JnnG9Tr9g.png" /><figcaption>Figure 10. Strategy entry function in detail</figcaption></figure><p>Once again, a lot of options and when you want to continue building scripts and they become more complex, you will definitely need to go down that rabbit hole. For our purpose, we only need to give it a name and trigger it when the conditions we set earlier, are met. We do this with the following code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vayWcHNH2tVxasKsQb6N6g.png" /><figcaption>Figure 11. Strategy execution</figcaption></figure><p>If you look at the latest addition of code it reads as following:</p><ul><li>If the Fast MA crosses over the Slow MA, enter a Long position with the ID “MA Cross - Long”</li><li>If the Fast MA crosses under the Slow MA, enter a Short position with the ID “MA Cross - Short”</li></ul><p>The last thing that you need to do is hit the Save button, and when it’s done compiling you can hit <strong>“Add to Chart”</strong> and you’ll see the SMA’s appearing on your screen. You can now hit the cogwheel button to change the periods of your SMA’s and under <strong>“Strategy Tester”</strong> you’ll see the results of your strategy change instantly!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1IXVWrnMco0rRNxWXfA3vw.png" /><figcaption>Figure 12. Result of you SMA strategy. Fast MA 5 / Slow MA 37. 4 Hour timeframe</figcaption></figure><p>This was the start of the series and I hope you this has made starting with scripting easier. If you have any feedback, do let me know!</p><p>You can follow me on <a href="https://twitter.com/coinpocalypse">Twitter</a>, where you can also find the link to my bot which shares it’s calls for free on Telegram! Im also on <a href="https://www.tradingview.com/u/Coinpocalypse/#published-scripts">TradingView</a>, where you can see and use my scripts.</p><p>It also wouldn’t hurt to study the <a href="https://www.tradingview.com/study-script-reference/">Pine Script Language Reference Manual</a>, so you can get up to date on al the functions, variables and operators used by Pine Script.</p><p><strong>FYI: </strong>I have an advanced script with multiple MA’s and other filters you can use for free, you can find it <a href="https://www.tradingview.com/script/hR26UKdm-Moving-Averages-Strategy-CP/"><strong><em>here</em></strong></a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80fe92c92b15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An introduction into algorithmic scripting]]></title>
            <link>https://medium.com/@coinpocalypse/an-introduction-into-algorithmic-scripting-304befaf2fb0?source=rss-e67210086841------2</link>
            <guid isPermaLink="false">https://medium.com/p/304befaf2fb0</guid>
            <category><![CDATA[algorithmic-trading]]></category>
            <category><![CDATA[trading]]></category>
            <category><![CDATA[scripting]]></category>
            <category><![CDATA[indicators]]></category>
            <dc:creator><![CDATA[Coinpocalypse]]></dc:creator>
            <pubDate>Wed, 06 Feb 2019 18:54:06 GMT</pubDate>
            <atom:updated>2019-02-06T19:04:37.736Z</atom:updated>
            <content:encoded><![CDATA[<h3>An introduction into algorithmic scripting.</h3><p>Yesterday, I introduced myself on Crypto Twitter and I wanted to follow up with an article about algorithmic scripting.</p><h3>Ｃｏｉｎｐｏｃａｌｙｐｓｅ on Twitter</h3><p>Hello Crypto Twitter, Let me introduce myself. I&#39;m not new here, but I am using a new account to promote and be critical about all matters concerning automated trading.</p><p>This is my first article and I’ve given some thought on the subject. There is a ton to choose from and a lot of choices would have been a nice and easy start, but I wanted to show you what the goal of the coming series is.</p><p>So for this article, I will be telling you all about one of my favourite indicators, ADX &amp;DI, which shows strength and directional movement, how i made it my own and is now one of the pillars of my automated trading style.</p><p>I will start off with some basic info about this indicator and focus on the usability. You can expect more technical articles with code examples in the future, so hopefully you can make your own!</p><p><strong>ADX &amp; DI</strong></p><p>The ADX is a combination of two other indicators developed by J. Welles Wilder, the positive directional indicator (abbreviated +DI) and negative directional indicator (-DI).</p><p>The Average Directional Index (ADX) line shows the strength of the trend. The higher the ADX value, the stronger the trend. According to Wilder, a trend is present when the ADX is above the value of 25. DI values range between zero and 100.</p><p>The +DI generally moves in sync with price, which means the +DI rises when price rises, and it falls when price falls. It is important to note that the -DI behaves in the opposite manner and moves counter-directional to price. <br>The -DI rises when price falls, and it falls when the price rises. This takes a little getting used to. Just remember that the strength of a price move up or down is always recorded by a peak in the respective DMI line.</p><p>Reading directional signals is easy. When the +DI is dominant and rising, price direction is up. When the -DI is dominant and rising, price direction is down. But the strength of price must also be considered. <br>DI strength ranges from a low of 0 to a high of 100. The higher the DI value, the stronger the prices swing. DI values over 25 mean price is directionally strong. DI values under 25 mean price is directionally weak.</p><p><strong>So, how does it look?</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jEuyBg_pGzvPMh2lmzvI-w.png" /><figcaption>ADX (black), +DI (green) and -DI (red)</figcaption></figure><p>Just by looking at the picture above, you can see the 3 dynamic lines moving all over the place. Without even knowing what any of these lines mean, you could observe the following:</p><ul><li>The ADX can be higher than both the +DI and the -DI</li><li>The -DI can be higher than both the ADX and the +DI</li><li>The +DI can be between the ADX and the -DI</li><li>The +DI can be moving down and the -DI can move up at the same time</li><li>The space between the +DI and the -DI can be smaller or bigger if you compare it to the previous period(s)</li><li>And so on and so on…</li></ul><p>This is just to illustrate we can define an insane amount of combinations that can give us a lot of information. Wilder himself had a few simple standard rules for this indicator:</p><ul><li>ADX above 25 equals a strong price trend</li><li>Strong trend <strong>and</strong>+DI crosses up the -DI should signal a long entry</li><li>Strong trend <strong>and</strong> -DI crosses up the +DI should signal a short entry</li></ul><p>If you code those rules into pine script, it paints the following picture.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TZFA2kdfydXWF2LxDFeMqw.png" /><figcaption>Long entry’s (green circles) and short entry’s (red circles), while trend is strong on the H4 timeframe</figcaption></figure><p>I don’t need to zoom in to see that besides these signals being mostly right, they are also a bit late. Not ideal for maximizing your profits, especially when you zoom in on the lower timeframes as in the picture below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_R7m7RGv5ZQPMEE_ST30Yg.png" /><figcaption>Same rules, lower timeframe (M15)</figcaption></figure><p>So why is this one of my favourite indicators? Because by now I can finally make my own rules and turn this lagging indicator into a leading one.</p><p><strong>Make your own rules</strong></p><p>I first came across this indicator in the public library of TradingView and at that point it was in version 2, which wasn’t the greatest because it handles price data in an awful way.</p><p>At that time I didn’t know how to port it to version 3, so i left it alone for a while untill I could code better. This took longer than I care to admit, but when I was finally porting it, I noticed that some of the code was off and did some more research into the math behind the indicator.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YFBzRtzZ_Y48_zVCi7b7tQ.jpeg" /></figure><p>I then changed the code and it finally gave the right values. At this point it looks like it does in the pictures above, very rough. The next step is smoothing out the data to eliminate false positives and bad signals as much as possible. To do this, you use filters.</p><p><strong>Filters</strong></p><p>Filters come in many forms, the most known is probably the SMA, or Simple Moving Average, it smooths out the price data over a specified period. Turns out, you can smooth prety much everything. However, filters have their own problems as they introduce lag. So looking for the right mix between smoothing data and reducing lag as much as possible seems to be one of the holy grails of algorithmic trading.</p><p>As you do your research you come across the most intricate filters of which some of the code will make you go cry in a corner of the room. After a while they grow on you and personally I’ve been very impressed by the filters of John Ehler, who has a background in engineering and talks about Spectral Dilation, Cycle Analytics and Digital Signal Processing.</p><p>I incorporated his SuperSmoother and Laguerre filters into my scripts and it made a big difference. If you want to know more about that, he has written a book, Rocket Science for Traders, which I recommend if you want to go down that rabbit hole.</p><p>So, how does the ADX &amp; DI look with those filters on it. Take a look.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*THuD6Ezr_SLY3JY6j0gQ8g.png" /><figcaption>Normal ADX &amp; DI below, filterd version and different rules in the upper ribbon</figcaption></figure><p>You don’t have to look very hard to see the difference it makes. By coding my own rules it makes better trades, all because of smooth data baby. In this case it gave the following result in a short period.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TMNKRwoyMHHxqB30rHdPgg.jpeg" /><figcaption>Perfect result for marketing</figcaption></figure><p>I joke a bit about the result off course, the sample size is way too small. Here is another one on the M5 chart of $XRPUSD</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0uwGv2oyPvMf1zpPjhL1yw.jpeg" /><figcaption>Net result after 0.075% trade commission. 260 trades, all made on candle close in 1 month.</figcaption></figure><p>This is the kind of result I’m working for and it took me a while to get here for sure. After reading this, I hope you’re motivated to start coding yourself. Don’t worry, you can make these scripts as complicated as you are able to, but some of the easiest codes can make all the difference in a good way. This was an opening article to show you where it lead me and maybe can lead you too.</p><p><strong>FYI:</strong> I just published the ADX &amp; DI script to TradingView and you can use it if you want to! I’m also running a bot on Telegram for free so you can check out the results live! You can find the link to the ADX &amp; DI script and the free bot on <a href="http://twitter.com/coinpocalypse">twitter.com/coinpocalypse</a>. If you enjoyed reading this, do give me a follow for future updates or shoot me a DM.</p><p>Thanks for reading and hope to see you next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=304befaf2fb0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>