Hi am trying to create a screener where it identifies the following on CCI:
in past x bars
CCI crosses above -100 then crosses above 100 crosses below 100 then crosses above 100 (without going lower than -100)
or
CCI crosses below 100 then crosses below -100 then crosses above -100 then crosses below -100 (without going higher than 100)
normally I would use a loopback over x bars and write each cross over event to an array. Then I would test the array for that specific pattern.
But it seems like ProScreener does not let me create my own arrays.
Thanks 🙂
Please update your country flag in your profile. Thank you 🙂
Hi Philip, you don’t need arrays to store your tests. We can make a loop or a summation of boolean over the last X periods to test if all your conditions were met.
timeframe (4 hours)
bars=20
//codes for nl nextlevel
//1 = over 100 1st time
//2 = over 100 2nd time
//-1 = under -100 1st time
//-2 = under -100 2nd time
nl = 0
//nextlevel = 0 open to anything
// set conditions
clong=0 //long
cshort=0 //short
FOR i = 0 TO 50 DO
c1=cci[i](bars) crosses over -100
c2=cci[i](bars) crosses under 100
c3=cci[i](bars) crosses over 100
c4=cci[i](bars) crosses under -100
if c1 and nl=0 then
nl = 1
continue
endif
if nl=1 and c3 then
nl=2
continue
endif
if nl=2 and c3 then
clong=1
break
endif
NEXT
SCREENER[(clong) OR (cshort)] ((close/DClose(1)-1)*100 AS "%Chg yest.")
Hi Nicolas, I have tried to imagine what you mean and created a fragment of code which I believe would catch the condition where CCI crosses first over -100 then subsequently through 100 and then again through 100.
If I can get it working for one direction then the others will follow easily.
But Pro Screener tells me that The program “MyScreener(7)” does not contain code 😀 so obviously it doesn’t understand something. But I don’t see what is wrong. It all looks syntactically ok, no yellow triangles. Any way to debug or to see what is causing the problem for ProScreener? I would not like to bother you every time I try to code:)
So is this the kind of structure you meant?
Please update your profile with your country.
This is a test quickly coded during lunch, screener take long time because of many loops. Didn’t test it much, so please stay calm and have a beer, I’ll get back here asap if you need more assistance 🙂
// in past x bars CCI crosses above -100 then crosses above 100 crosses below 100 then crosses above 100 (without going lower than -100)
// or
// CCI crosses below 100 then crosses below -100 then crosses above -100 then crosses below -100 (without going higher than 100)
lookback = 100
mycci = cci[20]
for a = lookback downto 0 do
if mycci[a] crosses over -100 then
nextlookback = a
break
endif
next
for b = nextlookback downto 0 do
if mycci[b] crosses over 100 then
nextlookback = b
break
endif
next
for c = nextlookback downto 0 do
if mycci[c] crosses under 100 then
nextlookback = c
break
endif
next
for d = nextlookback downto 0 do
if mycci[d] crosses over 100 then
result = 1
when = d
break
else
result = 0
endif
next
SCREENER [result] (when as "When?")
Hi Nicolas, thanks at least the for loops are not nested… time for a beer.
country updated (I thought I did that yesterday..)
Thanks again