// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Bill_Howell //@version=4 // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // 19Sep2022 initial, 20Sep2022 fixed colored labels, added min,max from my previous scripts // see https://www.tradingview.com/script/xOLBArA6-International-interest-exchange-rates/ // All manually-provided constants for del[Min, Max]_10Y will become inaccurate with time!! // ONLY time.periods [3M, 6M, 1Y, 5Y] work. // time.periods [1D, 5D, 1M, ALL] do NOT work - I haven't manually provided values from charts. // there are some errors in my manually [read, record] of the 5Y time-periods // additionally, this Pine Script was thrown together in a day, no rigorous testing // exchange rates are shown by darker colors, interest rates lighter similar colors // China - green, Euro - purple, Great Britain - blue, Japan - orange (you can see this in the4 code below!) // stable rates : [JP10Y, CN10Y] // https://www.tradingview.com/x/OXFvIi7I/ // policy-manipulated rates : [TNX, EU10Y, GB10Y] // https://www.tradingview.com/x/V4LOppCz/ //********************************** study(title="International 10Y rates minus US", shorttitle=" ", overlay=true, resolution="") //+-----------------------------------------------------------------+ //+-----------------------------------------------------------------+ // Code in this section was taken from my earlier PineScripts // (eg "SP500 [Puetz time, Fibonacci price]Fractals [trend, relStdDev] 1926-2020") //+-----+ // https://www.tradingview.com/pine-script-docs/en/v4/appendix/HOWTOs.html#count-bars-in-a-dataset // Find the highest and lowest values for the entire dataset // 20Mar2021 Howell - adapt this for viewable data // 20Sep2022 WARNING!! // PineScript fails at providing functions that work over the full length of the visible stock period. // One cannot accurately determine the start time bar // functions like [big, small]est below give WRONG results!! - best to hand-craft answers biggest(series,size) => max = 0.0 for j = 0 to size if series[j] > max max := series[j] max smalest(series,size) => min = 100000. for j = size to 0 if series[j] < min min := series[j] min //+-----+ // Setup general - timeframe.period, n_bars, [min, max] of tracked main price series in chart // User must turn OFF : SP500 axis menu -> Labels -> Indicators and financials name labels (no checkmark) // timeIdx = index to ary_t_length, the active chart timeSpan // t_lengthYear = duration of graph timescale for each timeperiod // visual = "1D" "5D" "1M" "3M" "6M" "1Y" "5Y" "All" // actual = 1 1 30 120 D W 30? or 20? //qnial> (1/365.25) (5/365.25) (1/12) (3/12) (1/2) (1.0) (5.0) (20) // .00273785 0.0136893 0.0833333 0.25 0.5 1. 5. 20. var int timeIdx = 0 // index to UWS constants // 20Sep2022 WARNING!!! : this series of conditional NOT used for delMin_CN10Y!! // See hand-derived values below. // Pine Script is no good for these kinds of things!!! formulae don't work in PineScript for full time-period // gives extremely inaccurate [min, max] results if (timeframe.period == "1") timeIdx := 0 else if (timeframe.period == "5") timeIdx := 1 else if (timeframe.period == "30") timeIdx := 2 else if (timeframe.period == "60") timeIdx := 3 else if (timeframe.period == "120") timeIdx := 4 else if (timeframe.period == "D") timeIdx := 5 else if (timeframe.period == "W") timeIdx := 6 else if (timeframe.period == "M") timeIdx := 7 var ary_t_length = array.new_float(8, 0.0) init_t_length() => array.set(ary_t_length, 0, 0.00273785) array.set(ary_t_length, 1, 0.0136893) array.set(ary_t_length, 2, 0.0833333) array.set(ary_t_length, 3, 0.25) array.set(ary_t_length, 4, 0.5) array.set(ary_t_length, 5, 1.0) array.set(ary_t_length, 6, 5.0) array.set(ary_t_length, 7, 20.0) if barstate.isfirst init_t_length() // 20May2022 t_year_to_millisecs - convert t_lengthYear to millisecs (Unix time duration) var float t_year_to_millisecs = 365.25*24*60*60*1000 t_lengthYear = array.get(ary_t_length, timeIdx) // duration of graph timescale (years) t_lengthUnix = t_lengthYear * t_year_to_millisecs // duration of graph timescale (Unix millisecs) yrFrac = time / t_year_to_millisecs + 1970 //+-----+ // Setup - specifics for this script v_USOIL = security("TVC:USOIL", timeframe.period, close) USOIL_detrend = v_USOIL / pow(10, -1.6684 + (0.00291 * yrFrac)) // 21Sep2022 eyeballed averages from TradingView charts // not terribly useful, as all script plots go to an un-named axis where they share the same scale // it is best to arrange for all script plots to have the same [range, average] // that way all plots will scale [min, max] the same as each other, // and the same scale (visually) as plots that are not part of the script. avg_CADUSD = 0.821 // 01May1987 avg_CNYUSD = 0.1508 // 01May2007 avg_EURUSD = 1.22 // 01Dec2005 avg_JPYUSD = 113.6 // 01Dec2005 a_CADUSD = 1. a_CNYUSD = 1. a_EURUSD = 1. a_JPYUSD = 1. b_CADUSD = 0. b_CNYUSD = 0. b_EURUSD = 0. b_JPYUSD = 0. delMin_CN10Y = 0. delMin_EU10Y = 0. delMin_CA10Y = 0. delMin_JP10Y = 0. delMax_CN10Y = 1. delMax_EU10Y = 1. delMax_CA10Y = 1. delMax_JP10Y = 1. // 21Sep2022 WARNING! // hand-crafted off chart, typed in!! To read the values : // set params like this for a given time.period // [save, run] script // enter [min, max] values shown on graph for the given time.period of : // d_CN10Y = (v_TNX - v_CN10Y - delMin_CN10Y)/(delMax_CN10Y - delMin_CN10Y) // = (v_TNX - v_CN10Y) // = del_CN10Y // YES - this is STUPID work that PineScript should do well... // delMin_CN10Y := 0. // delMin_EU10Y := 0. // delMin_CA10Y := 0. // delMin_JP10Y := 0. // delMax_CN10Y := 1. // delMax_EU10Y := 1. // delMax_CA10Y := 1. if (timeframe.period == "1") // 1 day delMin_CN10Y := 0. delMin_EU10Y := 0. delMin_CA10Y := 0. delMin_JP10Y := 0. delMax_CN10Y := 1. delMax_EU10Y := 1. delMax_CA10Y := 1. delMax_JP10Y := 1. else if (timeframe.period == "5") // 5 days delMin_CN10Y := 0. delMin_EU10Y := 0. delMin_CA10Y := 0. delMin_JP10Y := 0. delMax_CN10Y := 1. delMax_EU10Y := 1. delMax_CA10Y := 1. delMax_JP10Y := 1. else if (timeframe.period == "30") // 1 month delMin_CN10Y := 0. delMin_EU10Y := 0. delMin_CA10Y := 0. delMin_JP10Y := 0. delMax_CN10Y := 1. delMax_EU10Y := 1. delMax_CA10Y := 1. delMax_JP10Y := 1. else if (timeframe.period == "60") // 3 months delMin_CN10Y := -0.158 delMin_EU10Y := 1.452 delMin_CA10Y := -0.971 delMin_JP10Y := 2.412 delMax_CN10Y := 0.920 delMax_EU10Y := 1.951 delMax_CA10Y := -0.096 delMax_JP10Y := 3.336 else if (timeframe.period == "120") // 6 months delMin_CN10Y := -0.664 delMin_EU10Y := 1.455 delMin_CA10Y := -1.254 delMin_JP10Y := 1.946 delMax_CN10Y := 0.910 delMax_EU10Y := 2.084 delMax_CA10Y := -0.096 delMax_JP10Y := 3.338 else if (timeframe.period == "D") // 1 year delMin_CN10Y := -1.559 delMin_EU10Y := 1.483 delMin_CA10Y := -1.177 delMin_JP10Y := 1.261 delMax_CN10Y := 0.815 delMax_EU10Y := 2.029 delMax_CA10Y := -0.126 delMax_JP10Y := 3.252 else if (timeframe.period == "W") // 5 years delMin_CN10Y := -0.397 delMin_EU10Y := -0.854 delMin_CA10Y := -1.845 delMin_JP10Y := -0.371 delMax_CN10Y := 1.041 delMax_EU10Y := 2.374 delMax_CA10Y := -0.198 delMax_JP10Y := 1.034 else if (timeframe.period == "M") // ALL years delMin_CN10Y := 0. delMin_EU10Y := 0. delMin_CA10Y := 0. delMin_JP10Y := 0. delMax_CN10Y := 1. delMax_EU10Y := 1. delMax_CA10Y := 1. delMax_JP10Y := 1. //+-----------------------------------------------------------------+ //+-----------------------------------------------------------------+ // Code adapted from my previous PineScript v_TNX = security("TVC:TNX", timeframe.period, close) v_CA10Y = security("TVC:GB10Y", timeframe.period, close) v_CN10Y = security("TVC:CN10Y", timeframe.period, close) v_EU10Y = security("TVC:EU10Y", timeframe.period, close) v_JP10Y = security("TVC:JP10Y", timeframe.period, close) del_CA10Y = v_TNX - v_CA10Y del_CN10Y = v_TNX - v_CN10Y del_EU10Y = v_TNX - v_EU10Y del_JP10Y = v_TNX - v_JP10Y // 20Sep2022 Cannot use - give wrong results : // delMin_CN10Y = smalest(del_CN10Y,n_bars) // delMin_EU10Y = smalest(del_EU10Y,n_bars) // delMin_CA10Y = smalest(del_CA10Y,n_bars) // delMin_JP10Y = smalest(del_JP10Y,n_bars) // // delMax_CN10Y = biggest(del_CN10Y,n_bars) // delMax_EU10Y = biggest(del_EU10Y,n_bars) // delMax_CA10Y = biggest(del_CA10Y,n_bars) // delMax_JP10Y = biggest(del_JP10Y,n_bars) d_CA10Y = (v_TNX - v_CA10Y - delMin_CA10Y)/(delMax_CA10Y - delMin_CA10Y) d_CN10Y = (v_TNX - v_CN10Y - delMin_CN10Y)/(delMax_CN10Y - delMin_CN10Y) d_EU10Y = (v_TNX - v_EU10Y - delMin_EU10Y)/(delMax_EU10Y - delMin_EU10Y) d_JP10Y = (v_TNX - v_JP10Y - delMin_JP10Y)/(delMax_JP10Y - delMin_JP10Y) // 21Sep2022 need regression for each currency to add in oil price effect // for now, just guess // 21Sep2022 eyeballed averages from TradingView charts // not terribly useful, as all script plots go to an un-named axis where they share the same scale // it is best to arrange for all script plots to have the same [range, average] // that way all plots will scale [min, max] the same as each other, // and the same scale (visually) as plots that are not part of the script. x_CNYUSD = ((a_CNYUSD * USOIL_detrend) + (b_CNYUSD * d_CN10Y)) / avg_CNYUSD x_EURUSD = ((a_EURUSD * USOIL_detrend) + (b_EURUSD * d_EU10Y)) / avg_EURUSD x_JPYUSD = ((a_JPYUSD * USOIL_detrend) + (b_JPYUSD * d_JP10Y)) / avg_JPYUSD x_CADUSD = ((a_CADUSD * USOIL_detrend) + (b_CADUSD * d_CA10Y)) / avg_CADUSD // standard named colors : // https://www.tradingview.com/pine-script-reference/v5/#var_color{dot}black // "see also" list of named colors // color.[black, silver, gray, white, red, purple, fuchsia, green, lime, olive, yellow, navy, blue, teal, aqua, orange] // 21Sep2022 is there some way to plot against the corresponding currency exchange rate axis? plot(x_CADUSD, color=color.aqua, linewidth=1, title="d_CA10Y") // blue plot(x_CNYUSD, color=color.lime, linewidth=1, title="d_CN10Y") // green plot(x_EURUSD, color=color.fuchsia, linewidth=1, title="d_EU10Y") // purple plot(x_JPYUSD, color=color.yellow, linewidth=2, title="d_JP10Y") // orange // endcode