Intramarket Difference Index Strategy by Amjad_S
By Amjad_S
Performance Metrics
- Author: Amjad_S
- Symbol: OANDA:JP225USD
- Timeframe: 1 hour
- Net P&L: +744.95 USD (+74.22%)
- Win Rate: 31.2%
- Profit Factor: 1.528
- Max Drawdown: 286.37 USD (17.20%)
- Total Trades: 138
- Sharpe Ratio: 0.37
Description
Hi Traders !! The IDI Strategy: In layman’s terms this strategy compares two indicators across markets and exploits their differences.note: it is best the two markets are correlated as then we know we are trading a short to long term deviation from both markets' general trend with the assumption both markets will trend again sometime in the future thereby exhausting our trading opportunity.📍 Import Notes: This Strategy calculates trade position size independently (i.e. risk per trade is controlled in the user inputs tab), this means that the ‘Order size’ input in the ‘Properties’ tab will have no effect on the strategy. Why ? because this allows us to define custom position size algorithms which we can use to improve our risk management and equity growth over time. Here we have the option to have fixed quantity or fixed percentage of equity ATR (Average True Range) based stops in addition to the turtle trading position size algorithm.‘Pyramiding’ does not work for this strategy’, similar to the order size input togeling this input will have no effect on the strategy as the strategy explicitly defines the maximum order size to be 1. This strategy is not perfect, and as of writing of this post I have not traded this algo. Always take your time to backtests and debug the strategy.🔷 The IDI Strategy:By default this strategy pulls data from your current TV chart and then compares it to the base market, be default BTCUSD . The strategy pulls SMA and RSI data from either market (we call this the difference data), standardizes the data (solving the different unit problem across markets) such that it is comparable and then differentiates the data, calling the result of this transformation and difference the Intramarket Difference (ID). The formula for the the ID is ID = market1_diff_data - market2_diff_data (1)Where market(i)_diff_data = diff_data / ATR(j)_market(i)^0.5, where i = {1, 2} and j = the natural numbers excluding 0 Formula (1) interpretation is the following When ID > 0: this means the current market outperforms the base marketWhen ID = 0: Markets are at long run equilibriumWhen ID +threshold (inputs for MA and RSI based ID thresholds are found under the ‘‘INTRAMARKET DIFFERENCE INDEX’’ group’), ETHUSD outperforms BTCUSD, we assume the momentum to continue so we go long ETHUSD. In the standard case we would exit the market when the IDI returns to its long run equilibrium of 0 (for the positive case the ID may return to 0 because ETH’s difference data may have decreased or BTC’s difference data may have increased). However in this strategy we will not define this as our exit condition, why ? This is because we want to ‘‘let our winners run’’, to achieve this we define a trailing Donchian Channel stop loss (along with a fixed ATR based stop as our volatility proxy). If we were too use the 0 exit the strategy may print a buy signal (ID > +threshold in the simple case, market regimes may be used), return to 0 and then print another buy signal, and this process can loop may times, this high trade frequency means we fail capture the entire market move lowering our profit, furthermore on lower time frames this high trade frequencies mean we pay more transaction costs (due to price slippage, commission and big-ask spread) which means less profit. By capturing the sum of many momentum moves we are essentially following the trend hence the trend following strategy type. Here we also print the IDI (with default strategy settings with the MA difference type), we can see that by letting our winners run we may catch many valid momentum moves, that results in a larger final pnl that if we would otherwise exit based on the equilibrium condition(Valid trades are denoted by solid green and red arrows respectively and all other valid trades which occur within the original signal are light green and red small arrows). another example...Note: if you would like to plot the IDI separately copy and paste the following code in a new Pine Script indicator template. Pine Script®indicator("IDI")// INTRAMARKET INDEX var string g_idi = "intramarket diffirence index"ui_index_1 = input.symbol("BINANCE:BTCUSD", title = "Base market", group = g_idi)// ui_index_2 = input.symbol("BINANCE:ETHUSD", title = "Quote Market", group = g_idi)type = input.string("MA", title = "Differrencing Series", options = ["MA", "RSI"], group = g_idi)ui_ma_lkb = input.int(24, title = "lookback of ma and volatility scaling constant", group = g_idi)ui_rsi_lkb = input.int(14, title = "Lookback of RSI", group = g_idi) ui_atr_lkb = input.int(300, title = "ATR lookback - Normalising value", group = g_idi)ui_ma_threshold = input.float(5, title = "Threshold of Upward/Downward Trend (MA)", group = g_idi)ui_rsi_threshold = input.float(20, title = "Threshold of Upward/Downward Trend (RSI)", group = g_idi)//>>+----------------------------------------------------------------+}// CUSTOM FUNCTIONS |// indexHighTF = barstate.isrealtime ? 1 : 0 [close_, ma_, rsi_, atr_] = request.security(symbol, timeframe = timeframe.period, expression = [close[indexHighTF], // Instentiate UDT variables ta.sma(close, malookback)[indexHighTF], ta.rsi(close, rsilookback)[indexHighTF], ta.atr(atrlookback)[indexHighTF]]) data = functions.new(close_, ma_, rsi_, atr_) data // Intramerket Difference Index idi(type, symbol1, malookback, rsilookback, atrlookback, mathreshold, rsithreshold) => threshold = float(na) index1 = getUDTdata(symbol1, malookback, rsilookback, atrlookback) index2 = getUDTdata(syminfo.tickerid, malookback, rsilookback, atrlookback) // declare difference variables for both base and quote symbols, conditional on which difference type is selected var diffindex1 = 0.0, var diffindex2 = 0.0, // declare Intramarket Difference Index based on series type, note // if > 0, index 2 outpreforms index 1, buy index 2 (momentum based) until equalibrium // if >+----------------------------------------------------------------+}// STRATEGY FUNCTIONS CALLS |//>+----------------------------------------------------------------+}plot(intramarket_difference, color = color.orange)hline(type == "MA" ? ui_ma_threshold : ui_rsi_threshold, color = color.green)hline(type == "MA" ? -ui_ma_threshold : -ui_rsi_threshold, color = color.red)hline(0)Expand 72 linesNote it is possible that after printing a buy the strategy then prints many sell signals before returning to a buy, which again has the same implication (less profit. Potentially because we exit early only for price to continue upwards hence missing the larger "trend"). The image below showcases this cenario and again, by allowing our winner to run we may capture more profit (theoretically). This should be clear...🔸 Mean Reversion Case:We stated prior that mean reversion of anomalies is an standerdies fact of financial data, how can we exploit this ?We exploit this by normalizing the ID by applying the Ehlers fisher transformation. The transformed data is then assumed to be approximately normally distributed. To form the strategy we employ the same logic as for the z score, if the FT normalized ID > 2.5 ( 0.5), Random Geometric Brownian Motion (H = 0.5) and Mean Reverting / Contrarian (H < 0.5). In my interpretation this can be used as a trend filter that eliminates market noise. We utilize the trending and mean reverting based states, as extra conditions required for valid trades for both strategy types respectively, in the process increasing our trade entry quality.🔷 Example model Architecture:Here is an example of one configuration of this strategy, combining all aspects discussed in this post.Future Updates- Automation integration (next update)