Stochastic with a custom lookback period

I wasn't sure if the built in stoch lets you modify the lookback period so I made one that calculates every part of the stochastic straight from the original equation.

The only relevant information is in the examplee function

How to change window length
Enter desired time length in the excel document under the highlighted cells
All you need to do is change the window length on the H and L data.history (to the numbers under the Safe lookback length cell)
Window length that is to be changed is found here

            H = data.history(positionz, 'high', 3785, '1m')
L = data.history(positionz, 'low', 3785, '1m')

  enter the values under the start:end:step rows in the slice functions under hii, hii2, hii3, hii4, and hii5
do the same to the loo, loo1, loo2, loo3, loo4, and loo5 slice functions


Found here..

            hii = H[-2941 : -1 : 210]
hii2 = H[-3150 : -210 : 210]
hii3 = H[-3360 : -420 : 210]
hii4 = H[-3570 : -630 : 210]
hii5 = H[-3780 : -840 : 210]


and

            loo = L[-2941 : -1 : 210]
loo2 = L[-3150 : -210 : 210]
loo3 = L[-3360 : -420 : 210]
loo4 = L[-3570 : -630 : 210]
loo5 = L[-3780 : -840 : 210]


Here is the excel document calculating the requested time values
^That is to be used in the slice functions between 'hii-hii5' and 'loo-loo5'^

The H and L window length is calculated in the excel document as well... It can be found under "Safe lookback length"

24
Backtest from to with initial capital
Total Returns
--
Alpha
--
Beta
--
Sharpe
--
Sortino
--
Max Drawdown
--
Benchmark Returns
--
Volatility
--
 Returns 1 Month 3 Month 6 Month 12 Month
 Alpha 1 Month 3 Month 6 Month 12 Month
 Beta 1 Month 3 Month 6 Month 12 Month
 Sharpe 1 Month 3 Month 6 Month 12 Month
 Sortino 1 Month 3 Month 6 Month 12 Month
 Volatility 1 Month 3 Month 6 Month 12 Month
 Max Drawdown 1 Month 3 Month 6 Month 12 Month
# Backtest ID: 59554278c376e24dd95ba27d
There was a runtime error.
3 responses

This is also just a concept, the algo itself was not made for live trading. It also has a few lines of noise from the poor copy & paste job from some other algorithm I was working on

Update:

• Slice function is a period behind
• some numbers in the slice function are returning as numpy 'nan' values because it is slicing from after market close, ill place a safeguard that self corrects this when it is happening

Fixes
Change slice function to look similar to this...

                hii = H[-2940 :: 1]
hii2 = H[-3149 : -209 : 1]
hii3 = H[-3359 : -419 : 1]
hii4 = H[-3569 : -629 : 1]
hii5 = H[-3779 : -839 : 1]


adjust numbers to be 1 min behind original values & change the slice 'step' to be 1 rather than 210