Is it possible to add a look-back period to scanner?
p1=9
p2=26
REM Tenkan-Sen = (Highest High + Lowest Low) / 2, for the past 9 days
Upper1 = HIGHEST[p1](HIGH)
Lower1 = LOWEST[p1](LOW)
Tenkan = (Upper1 + Lower1) / 2
REM Kijun-Sen = (Highest High + Lowest Low) / 2, for the past 26 days
Upper2 = HIGHEST[p2](HIGH)
Lower2 = LOWEST[p2](LOW)
Kijun = (Upper2 + Lower2) / 2
TENLESSKIJUN = (Tenkan < Kijun)
//TENGREATKIJUNPAST = Tenkan[7] > Kijun[7]
CLOSEVAL = (close < 1100 AND close > 50)
VOL = (volume > 1000000)
//Screener((TENLESSKIJUN AND TENGREATKIJUNPAST AND CLOSEVAL AND VOL))
Screener[TENLESSKIJUN AND CLOSEVAL AND VOL ]
Above is a very simple TK cross over detection screener, however , this will output anything where a TK cross has taken place (and valid). Is it possible to bracket this by only running the script for a time period i.e last 7 days?
Secondly is it possible to have the results of screener sorted by the time? By time , i mean , not the scan time , but rather , if asset_1 had a TK-cross on 1st October and asset_2 on 2nd October , is there a way i can list asset_2 before asset_1 in sorting criteria?
Thanks!
In this version of the code, i’m checking if a crosses have occurred in the last 7 periods:
p1=9
p2=26
REM Tenkan-Sen = (Highest High + Lowest Low) / 2, for the past 9 days
Upper1 = HIGHEST[p1](HIGH)
Lower1 = LOWEST[p1](LOW)
Tenkan = (Upper1 + Lower1) / 2
REM Kijun-Sen = (Highest High + Lowest Low) / 2, for the past 26 days
Upper2 = HIGHEST[p2](HIGH)
Lower2 = LOWEST[p2](LOW)
Kijun = (Upper2 + Lower2) / 2
TENLESSKIJUN = (Tenkan crosses under Kijun)
if TENLESSKIJUN then
lastcross = barindex //save the barindex of the event
endif
CLOSEVAL = (close < 1100 AND close > 50)
VOL = (volume > 1000000)
last = barindex-lastcross <=7 //last cross was less than 7 periods from now
Screener[last AND CLOSEVAL AND VOL](barindex-lastcross as "x bars ago")
I also added the bars difference for the sorting criteria, as you required. This code has not been tested.
thanks! i’ll give it a spin!