Varying Scenario Time Frame with Analyzer Macro

« Go Back

Information

 
Requirements and Setup
Scenario Setup:
Each STK scenario has an Epoch time property which by default will be the same time as the scenario analysis start time. Keep in mind that if you use Analyzer to vary the scenario start time then your scenario Epoch time will vary with it as well. If you want the scenario Epoch time to remain fixed on a particular time then open the scenario properties, navigate to the Basic -> Time page, and click the drop-down arrow to the right of Epoch Time under Analysis Period and select "Replace with Time". This will allow you to specify a fixed scenario Epoch time.
Instructions
1) To add the macro scripts to Analyzer, select the "Create custom variables, macros..." icon (User-added image) in the main STK Analyzer window.
2) Click on "Init" under Current STK Scenario on the left. Copy all the VBScript text from the file "AnalyzerMacroTimeOffsetInitvbs.txt" located within the zip folder attached to this article and paste into the macro window.
3) Click on "PreRun" under Current STK Scenario. Copy all the VBScript text from the file "AnalyzerMacroTimeOffsetPreRunvbs.txt" and paste into the macro window.
4) Click OK to close the Macro window.
5) Now when you open a trade study tool you will see a custom TimeOffset variable that can be used as a design variable.

User-added image

Final things to note:
1) You will see the TimeOffset variable is initialized with a value of zero. This is set on line 14 of the Init macro if you'd like to change it.
2) The TimeOffset variable is using Epoch Seconds as its unit. This is set on line 17 of the Init macro if you'd like to change it.
3) As the analysis start time of the scenario is incremented, the PreRun macro makes sure that the analysis stop time also increments forward. The scenario duration (time between scenario start and scenario stop) is set on line 16 of the PreRun macro.