Intramarket Indicator Differences | Algorithmic Crypto Trading Strategy in Python

neurotrader · Intermediate ·🔢 Mathematical Foundations ·2y ago

About this lesson

Using the difference between an indicator measured on two different symbols to build a trading strategy for Ethereum. Code: https://github.com/neurotrader888/IntramarketDifference Links https://en.wikipedia.org/wiki/Random_walk#Gaussian_random_walk The content covered on this channel is NOT to be considered as any financial or investment advice. Past results are not necessarily indicative of future results. This content is purely for education/entertainment.

Full Transcript

in this video we will look at intra Market differencing a very simple multi-symple analysis Technique we will consider Bitcoin and ethereum as an example here's a plot of Bitcoin and ethereum just by looking we can see that the prices of these two cryptocurrencies tend to move together the correlation between the hourly log returns is 0.84 when measured from 2018 to 2023. this isn't surprising or necessarily interesting crypto in general tends to move together but what I find interesting is when one crypto is doing something different compared to the others perhaps the simplest way to do this is intermarket differencing an example would be measuring the RSI on both Bitcoin and ethereum then subtracting the two RSI readings at each candle to create a new indicator this idea isn't restricted to the RSI in theory any indicator measured on one symbol could be used but for inter-market differencing to be useful the indicator measure needs to be stationary and normalized to have the same scale for both symbols to provide an example for the normalization of an indicator I'll use the closing price minus a moving average in its raw form this indicator is not viable for enter Market differencing this is because different symbols have different price scales the higher price of Bitcoin will dominate an intermarket difference using logarithmic prices is a typical remedy for scaling issues but another problem is different symbols have different volatilities Bitcoin and ethereum actually have comparable volatility but if we were instead considering Bitcoin and Dogecoin the different levels of typical volatility would be an issue both these scale of prices and the inherent volatility of different markets should be considered when preparing indicators for inter-market differencing for the close minus the moving average we can mostly remedy both of these issues by dividing the difference between the close and a moving average by the average true range let's look at the code for this normalized indicator this function cmma implements this indicator we pass it the Open high low close data and look back for the moving average and a look for the average true range the average true range look back should be fairly large big enough to get a general idea of the volatility present in a market since I'm using hourly data I'll use 168 or one week we compute the average true range with the pandas ta module we compute the moving average then we subtract the moving average from the closing price we divide this Difference by the average true range I multiply the average true range by the square root of the look back this will normalize the scale of the indicator across different look backs of the moving average the square root is from a property of random walks which is beyond the scope of this video but I'll leave a link to something in the description here's the normalized close minus moving average indicator with a look back of 24 on bitcoin and ethereum from 2018 to 2023. the indicator measured on both symbols has the same scale throughout the period the values of the indicator generally move together just as the markets themselves move together but they do differ at times let's return to the main section of the code we first load hourly Bitcoin and ethereum data from csvs we compute the log returns for both cryptocurrencies and shift them forward for a future return we will use these returns later when we are assessing an example strategy now we declare some parameters look back is the moving average period for the close minus moving average indicator threshold is used by the example strategy I'll talk about it more in a minute and ATR look back is the look back for the average true range we compute the close minus moving average indicator for both Bitcoin and ethereum using the specified look backs the intramarket indicator is the difference between the indicators measured on both symbols here I chose to do ethereum minus Bitcoin as the example strategy we'll look at in a second we'll be targeting ethereum but instead we could have flipped it and done Bitcoin minus ethereum it doesn't really matter it's the same information it just flips the sign here's a plot of ethereum's price and our inter-market difference indicator when this indicator is above zero it means ethereum is higher above its moving average than Bitcoin and vice versa Loosely this can be interpreted as when the indicator is above zero ethereum has been outperforming Bitcoin and when below zero ethereum has been underperforming Bitcoin something I find interesting about this indicator is it can have high readings both when the price has been increasing and decreasing in the crypto Market at least in my Experience Momentum tends to work if something is outperforming it tends to continue to outperform so a simple strategy using this intramarket difference indicator is going long ethereum once it crosses above some threshold and holding this long position until the indicator returns to zero the indicator by Design is centered at zero when the intramarket difference is at zero both ethereum and Bitcoin are at some sort of equilibrium similarly for shorts when the indicator crosses below some threshold a short position is entered on ethereum this position is held until the indicator returns to zero this function threshold revert signal implements these rules we pass it an indicator which will be our enter Market difference and a threshold we create an output signal and a position variable to keep track of the current position we Loop through each index in the indicator the indicator is above the threshold we set the position variable to 1 if the indicator is below the negative threshold we set the position variable to negative one now we check for the indicator returning to zero if the position is one and the indicator is less than or equal to zero we set position back to zero and if position is currently negative one and the indicator is greater than or equal to zero we set position back to zero we save the current position to the output signal at each index now we're back at the main section of the code after we compute the intramarket difference we pass this difference to the threshold revert signal function along with a threshold I set the threshold to 0.25 the threshold as well as the look back for the moving average are adjustable parameters which as I'm sure you know is a common issue with trading systems later we will look at the performance of the strategy across a wide variety of both these parameters I think the moving average look back is fairly self-explanatory but how do we set the threshold for the strategy a good first step is to look at the histogram of the inter-market difference the threshold should be somewhere in this distribution if we select an extreme value as the threshold the trades will be sparse if we select a value close to zero the trades will happen more often the threshold could be set so it optimizes some objective function but if the strategy is robust then it should work across many thresholds for now let's stick with 0.25 as it's fairly close to the center of the distribution and it will trigger many trades we multiply the signal we got from the threshold revert signal function by ethereum's next log return this will give us the returns of the strategy at each candle we compute the profit factor using these returns then we get the cumulative sum of these returns and plot and here are the results with a moving average lookback of 24 and a threshold of 0.25 the overall profit factor is 1.08 there were around 4 400 long and short trades both scored slightly above a 50 win rate no transaction costs were included in these results I think these results look pretty good but this is just one pair of the two parameters in the strategy let's look at the profit factors of the strategy across a wide range of the parameter values here's a heat map showing the profit factor of the strategy with several different values of the moving average look back and threshold nearly every parameter set tested had a profit Factor above one it appears lower mid-range values with the lookback had a bit better performance and a threshold around 0.3 was the best in this test period but overall the strategy looks pretty robust inter-market differencing can be applied in many different ways obviously one could difference other indicators the adx RSI macd and so on you could difference indicators across many cryptocurrencies relative to bitcoin then consider a position in the crypto that has the most extreme deviation from Bitcoin throughout the video I've been saying intra market analysis but another term term I think might be more common is inter market analysis intra considered symbols within the same Market Bitcoin ethereum are both part of the crypto Market Pepsi and Coke are both part of the stock market but this type of indicator differencing could be used to compare different markets for example the stock market with the bond market I'm not the person to tell you about these two markets relationship but I've read about people comparing stocks and bonds in some sense this video has been about subtracting two numbers which admittedly isn't super exciting but I always like to lean towards Simplicity and this is perhaps the simplest way to compare two symbols or markets that's it for this one thank you for watching

Original Description

Using the difference between an indicator measured on two different symbols to build a trading strategy for Ethereum. Code: https://github.com/neurotrader888/IntramarketDifference Links https://en.wikipedia.org/wiki/Random_walk#Gaussian_random_walk The content covered on this channel is NOT to be considered as any financial or investment advice. Past results are not necessarily indicative of future results. This content is purely for education/entertainment.
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

Up next
Marks Weightage | Quantitative Aptitude CA Foundation September 2026 | ABC Analysis | Nithin
ArivuPro Academy
Watch →