How to loop through OHLC DataSeries in Optimization?
Author: emskiphoto
Creation Date: 5/19/2017 8:32 PM
profile picture

emskiphoto

#1
In the line of code from the script below I would like to be able to substitute the term "Low" with a StrategyParameter that would enable analysis of either the O, H, L, or C of a price series in the optimization process. In other words, I wish to leverage the automated optimization process to evaluate the effectiveness of the strategy on all four of the OHLC time series for a given ticker symbol.

CODE:
Please log in to see this code.


I imagine this requires 'enumerating' the different time series and then defining Strategy Parameters as shown below. This is beyond my coding abilities - please help.

Open = 1
High = 2
Low = 3
Close = 4

CODE:
Please log in to see this code.


// for example if slider5=2, then the CrossUnder series would use the bar "High" price of the data series.


WHOLE SCRIPT (FYI):

CODE:
Please log in to see this code.
profile picture

Eugene

#2
Hi Matt,

There's always more than one way to skin a cat but the natural choice here is to use the switch keyword like shown below. Hope this is intuitive enough:

CODE:
Please log in to see this code.
profile picture

emskiphoto

#3
Excellent! Thanks Eugene
profile picture

emskiphoto

#4
Hello Eugene,

Your solution successfully enables alternating through the OHLC data series that is the reference for the CrossUnder test.

Can you propose an additional solution that will enable a similar (but independent) variation of the OHLC series to be used for the EMA.series used in the DataSeriesCrossBelow data series?

In other words, during an optimization run I would like to be able to test each of the O H L C time series as the basis for the EMA calculation (the version of the code in the previous post can consider only the "Close" series). Additionally, it's important that the possible choices of OHLC series for the CrossUnder test are not required to be the same as the OHLC choices for the EMA.series used in the DataSeriesCrossBelow data series. For example, in any given run of an optimization it would be possible to have the CrossUnder test reference "H" and the EMA.series used in the DataSeriesCrossBelow data series reference "C".


See following unsuccessful attempt at coding this:

CODE:
Please log in to see this code.
profile picture

Eugene

#5
Hi Matt,

This should get the job done.

CODE:
Please log in to see this code.


P.S. Make sure to load enough data because of this:
CODE:
Please log in to see this code.

Explanation: WealthScript Programming Guide > Indicators > Stability of Indicators