Limiting Script Calculation to a Range of Bars

Hi Guys,

I have a Watchlist with 20 columns, each with attendant scripts which must be calculated for each market in the Watchlist, in my case 22 of them, thus there are 20 x 22 = 440 scripts to be run. Many of those markets go back to the early 1900’s, so the calculation time is very long when opening the Workbook, well over 2 minutes. As I’m only interested in the most recent, say 300 bars, is the a way of coding the scripts to limit the calculation period range of the scripts?

There is a similar function for SHOWBARs, ie the “Start Date” property, although rather than specifying a date, I’d prefer to set the number of Bars back from the Last Bar. Ideally this could be a Watchlist Column Property, but able to be set as a date or number of Bars.

I also note there is a “Look Back Period” for some functions, eg ACC(), but I haven’t found an equivalent function that can be applied to a complete script.

I hope there is a simple solution and that its simply that I haven’t found it.

Cheers

Trevor

 

Hi Trevor,

In the Watchlist properties there is a Date Range option you can use to limit the amount of data that is loaded. However, please note that there are several tools and script functions that will override this setting as without the full historical data the values produced by the script can differ from those on the chart (as historical data is used the in calculation).

Chaikin ADLine
Ichimoku Cloud
MACD
Oscilator
Gartley Patterns
OSOB
BreadthData
Derivative Oscillator
Count Match SinceSignal
Pivot Label
Trough
Barros Swing Function
Chart Pattern Function
Chart Pattern Overlay
COT Data
Hart Swing Function
Olivers Wedge
Point Figure Swing Function
Relative Index Comparison
Time Adjust
Time frame Function
DVAN TOols
NumberSearcher
All HomeTrader Tools
Pivots
Pattern Matcher
Risk Reward
ADX
Chandelier Stop
Demand Index
PSAR
Range From Extreme
RSI
Wilson Rel Price
Midos SI
Rel Volatility
Wilder Vol Stop
Accumulation Distribution
On Balance Volume
MPA / VAD

If your scripts contain any of these tools / functions the full history is loaded.

Hi Matthew,

Thanks for the quick response.

From my testing you can add PIVOT(), which I’m using, to the above list. My tests all result in exactly the same run time on change of Date Range in the Watchlist properties☹

The Watchlist properties require the setting of a Date Range which applies across all Timeframes (which sets the Bar period to 1 Day, 1 Week, 1 Month, etc), whereas the script I’m using is only interested in the most recent 300 Bars, regardless of Timeframe.

So, I’d like to be able to define the number of Bars look-back period from the Last bar in the script, then allow the user to set the Timeframe they are interested in via the Watchlist properties.

Cheers

Trevor

Hi Trevor,

There is a DATATOLOAD function (example here) which may do what you need. It can be set to Bars as well as a lookback period:

Capture

Thanks Darren. A perfect solution.

 

 

Hi Darren,

Wow. Did I ever respond too soon☹

I’d only checked using DATATOLOAD() on some SHOWBARS and it looked to speed things up and limit the data range as expected.

But then I modified the twenty (20) scripts in my Watchlist with 20 markets to each be limited to 500 Bars ( on 1 Day chart) and the load time of the Workbook TRIPLED from about 2 minutes for loading everything to over 6½ minutes with the restricted load range☹

My 20 scripts using the DATATOLOAD() function follow this pattern, just with different OFFSET=# parameters:

// Bar since Pivot 11 High 2

DataRange = DATATOLOAD(RANGE=Bars, AMOUNT=500);

S = PIVOT(DataRange, MIN=11, TYPE=High);
//Get the bar date of the signal before last
P1 = BARDATE(DataRange);
P2 = LAST(BARDATE(NONZERO(S), OFFSET=1));
Signal = P1 == P2;
//Count the bars since the signal
TIMESINCESIGNAL(signal, UNIT=Bars)

Prior to adding the DATATOLOAD() function my scripts were simply:

// Bar since Pivot 11 High 2

S = PIVOT(MIN=11, TYPE=High);
//Get the bar date of the signal before last
P1 = BARDATE();
P2 = LAST(BARDATE(NONZERO(S), OFFSET=1));
Signal = P1 == P2;
//Count the bars since the signal
TIMESINCESIGNAL(signal, UNIT=Bars)

Have I missed something in my application of DATATOLOAD()? If I have I’m darned if I can figure out what☹

Any suggestions to speed up the scripts will be very much appreciated, in the meantime I’ll go back to my original simpler scripts.

Cheers

Trevor

 

 

OK thanks - I thought it would be worth a shot. I’m guessing with PIVOT function (and the other ones mentioned by Matthew when changing the Date Range property) doesn’t work because it needs all the data for them to be calculated correctly rather than from an arbitrary starting point.

So I think the only way to speed it up would be to reduce the size of the watchlist or the number of columns being calculated.

Hi Darren,

Thanks for the update.

Unfortunately reducing the number of columns or the markets rather defeats the purpose of the Watchlist.

Looks like I’ll have to put up with the long load times until such time as you smart guys work out a way to speed up all the functions when using the DATATOLOAD function.

One alternative would be for me to develop a Custom Tool as in Pascal its pretty easy to limit the data range, but then I’ve never tried using Custom Tools in Watchlists that have user settable properties appear in the Watchlist column properties, is that possible?

Cheers

Trevor