// 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="Howell - exchange rate CNYUSD", 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_CNYUSD = 0.1508 // 01May2007 oil_CNYUSD = 1. intRatio_CNYUSD = 0. delMin_CN10Y = 0. delMax_CN10Y = 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... // Note that time.periods [1D, 5D, 1M, All] are NOT included and those timescales don't work // time.periods [3M, 6M, 1Y, 5Y] do work if (timeframe.period == "60") // 3 months delMin_CN10Y := -0.158 delMax_CN10Y := 0.920 else if (timeframe.period == "120") // 6 months delMin_CN10Y := -0.664 delMax_CN10Y := 0.910 else if (timeframe.period == "D") // 1 year delMin_CN10Y := -1.559 delMax_CN10Y := 0.815 else if (timeframe.period == "W") // 5 years delMin_CN10Y := -0.397 delMax_CN10Y := 1.041 //+-----------------------------------------------------------------+ //+-----------------------------------------------------------------+ // Code adapted from my previous PineScript, only using one symbol! // simple search (same case!) replace CN with OR[CA, EU, JP] in this section ONLY v_TNX = security("TVC:TNX", timeframe.period, close) v_CN10Y = security("TVC:CN10Y", timeframe.period, close) intDiff_CN10Y = v_TNX - v_CN10Y intRato_CN10Y = (v_TNX - v_CN10Y - delMin_CN10Y)/(delMax_CN10Y - delMin_CN10Y) // 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. oil_CNYUSD := -10. intRatio_CNYUSD := 10. x_CNYUSD = avg_CNYUSD / ((oil_CNYUSD * USOIL_detrend) + (intRatio_CNYUSD * intRato_CN10Y) + 1) * 1.1 // 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_CNYUSD, color=color.lime, linewidth=1, title="d_CN10Y") // green // endcode