TradingView
allanster
٢٠ شباط فبراير ٢٠٢٣ ١٦:٠٠

How To Import And Offset CSV Data 

Bitcoin / United States DollarCoinbase

الوصف

Example method of how to import, offset, and plot ‎CSV data using an array.

NOTICE: This is an example script and not meant to be used as an actual strategy. By using this script or any portion thereof, you acknowledge that you have read and understood that this is for research purposes only and I am not responsible for any financial losses you may incur by using this script!
التعليقات
KioseffTrading
When do I buy?!

Joking of course - great contribution allan!
allanster
@KioseffTrading, thank you for the encouragement and gift!
spiritedMaster43205
Thank you for your script, it was helpful.
I have a dataset that is bigger than the 999 datapoints allowed in the array. Any idea how to solve this?
spiritedMaster43205
@spiritedMaster43205, I found a solution, thanks.
sVm88
@spiritedMaster43205, what was the solution you found plot a dataset bigger than 999 datapoints? Thanks in advance!
cosmicjoker
@sVm88, yes would be very interested in your solution.
allanster
@spiritedMaster43205, @sVm88, @cosmicjoker, apologies for delayed response, I have been away for some time.

The function array.from(arg0, arg1, ...) can accept up to 4,000 'int', 'float', 'bool', or 'color' arguments. For all other types, including user-defined types, the limit is 999. If your number of data points exceed these limitations then one solution would be to create individual subsets of arrays.

The function array.concat(id1, id2) could then be used to chain each of the aforementioned subset arrays into a larger superset array, as shown in the example below:

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © allanster //@version=5 indicator("How To Import And Offset Sets Of CSV Data") bump = input(true, '', inline = '1') // Enable/Disable offset of origin bar. date = input.time(timestamp("15 May 2024 00:00 +0000"), "Shift Origin To", tooltip = 'When enabled use this offset for origin bar of data range.', inline = '1') indx = not bump ? 0 : ta.valuewhen(time == date, bar_index, 0) // Origin bar index. var setA = array.new_float() // Create a subset array of data points. var setB = array.new_float() // Create a subset array of data points. var data = array.new_float() // Create a superset array of data points. if bar_index == indx // If current bar is origin of data range populate the arrays. // Paste subsets of CSV 👇 normalized data into subset arrays. setA := array.from(0.0, 1.4, 0.7) setB := array.from(3.5, 2.8, 4.9) // Combine subsets 👇 of CSV normalized data into superset array. array.concat(data, setA) array.concat(data, setB) // Garbage removal of subset arrays. array.clear(setA) array.clear(setB) array.reverse(data) // Reverse index the superset array so that pop may be used instead of shift. plot(array.size(data) < 1 ? na : array.pop(data), 'csv', #ffff00) // Plot and shrink dataset for bars within data range. // End of example. //
A_Traders_Edge
Being as though it has a LOT better chance of being seen if it came from you, I will make a request for a script to solve a problem that Ive run into many the time. Using varip(obv) only allows you to see passing data and not historical but to see how well triggers are performing for a script using varip is impossible.....unless.....you can get the trigger of an alert to add the UNIX time of the trigger to a list that can then be pasted into an input to be populated into an array to allow historical signals to be shown to determine how well a varip script's triggers are historically performing. Could obv be extended to populate the historical data of an indicator that uses varip without having to watch the whole thing play out on the chart. idk....maybe its just me that has run into the issue multiple times, but if not, im sure many would find the information helpful.
allanster
@chasinalts, will consider when time permits.
Snifky
Thanks very much for the script, I haven't found any alternative yet.
Is it possible to use float values for input?
المزيد