Best practice: How to apply timeframe overrides to imported scripts

Optuma Forums Optuma Scripting Is it possible to use a timeframe override on an imported script? Best practice: How to apply timeframe overrides to imported scripts

#53965
Avatar
Dean
  • Topics: 10
  • Replies: 18
  • Posts: 28

Best practice: How to apply timeframe overrides to imported scripts

In reference to the original post and the first reply, there is an even better outcome, which could even be considered ‘best practice’.

Do not set the timeframe override within the imported script. Set the timeframe override only when it is imported with the SCRIPT function.

To explain, let’s go back to the original case study:

Script_A has the following formula to calculate the value of the Bollinger Band upper line:

BB(BARS=9, DEFAULT=UpperLine, CALC=Close, STDDEV=2.000000);

Script_B imports Script_A:

BBWeeklyUpperLine = SCRIPT(Week(PERIODAMOUNT=1), SCRIPTNAME=Script_A);
BBWeeklyUpperLine

Now, the only time the timeframe override is used is when Script_A is imported using the SCRIPT function.

Why is this good or ‘best practice’? Because now Script_A can be used to provide daily, weekly, monthly or yearly data, without changing its code.

To illustrate, try this:

Script_A remains the same, with no timeframe override within it.

BB(BARS=9, DEFAULT=UpperLine, CALC=Close, STDDEV=2.000000);

Script_B imports Script_A:

Plot1 = SCRIPT(SCRIPTNAME=Script_A);
Plot2 = SCRIPT(Week(PERIODAMOUNT=1), Script_A);
Plot3 = SCRIPT(Month(PERIODAMOUNT=1), Script_A);
Plot4 = SCRIPT(Year(PERIODAMOUNT=1), Script_A);

If you plot Script_B on a daily chart, you will see daily, weekly, monthly and yearly plots of the Bollinger Band Upper line, without changing anything in Script_A.

While Script_A is a trivial formula in this case study, imagine if was several or many lines of code. Imagine how using imported scripts like this can reduce the amount of repeated code. ‘Write once and use many times’ is the mantra of computer software systems.

With this powerful capability you can build well-structured, re-useable, modular, highly efficient code for your trading strategies.

1 user thanked author for this post.

Pin It on Pinterest

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close