No se como usar el bucle FOR, en un proscreener si, pero en backtest no.
En el proscreener le suelo poner de 0 a 251. En el backtest como seria? BarIndex?
Las condiciones que quiero hacer es:
Quiero detectar que las medias de 20 y 40 esten por debajo de la media de 200.
Antes de que el precio cruce la media de 200, quiero que tenga 2 maximos relevantes crecientes (lo que te marco con las flechas rojas).
Una vez, el precio cruza la media de 200, en el momento que la cruza hacia abajo es cuando buscaria la compra.
En la imagen, las flechas rosas, es un indicador que me cree para detectar los maximos relevantes (que los 3 maximos a su izquierda sean menor y que los 3 maximos de su derecha tambien).
Te añado el codigo del indicador por si sirve.
Te adjuntare el codigo proscreener que uso.
//maximo mimino relevante.
m20 = average[20]
centro=3
maximo = high[centro]
minimo = low [centro]
maxrelevante= 1
minrelevante= 1
//vela verde max y roja inhalacion
rangoCuerpoME2=close[centro]-open[centro]
rangoCuerpoE2=open[2]-close[2]
cumpleE2Inhalacion=rangoCuerpoME2>0 and rangoCuerpoE2>0
rcE2=0
if (close[2] < close[centro] and cumpleE2Inhalacion) then
rcE2=1
endif
//vela verde y roja max y inhalacion
rangoCuerpoME2=close[centro+1]-open[centro+1]
rangoCuerpoE2=open[centro]-close[centro]
cumpleE2Inhalacion=rangoCuerpoME2>0 and rangoCuerpoE2>0
rcE2a=0
if (rcE2=0 and close[centro]<close[centro+1] and cumpleE2Inhalacion) then
rcE2a=1
endif
//vela roja min y verde inhalacion
rangoCuerpoME4=open[centro]-close[centro]
rangoCuerpoE4=close[2]-open[2]
cumpleE4Inhalacion=rangoCuerpoME4>0 and rangoCuerpoE4>0
rcE4=0
if (close[2] > close[centro] and cumpleE4Inhalacion) then
rcE4=1
endif
//vela roja y verde min y inhalacion
rangoCuerpoME4=open[centro+1]-close[centro+1]
rangoCuerpoE4=close[centro]-open[centro]
cumpleE4Inhalacion=rangoCuerpoME4>0 and rangoCuerpoE4>0
rcE4a=0
if (rcE4=0 and close[centro]>close[centro+1] and cumpleE4Inhalacion) then
rcE4a=1
endif
for i=0 to centro*2
if i<>centro then
if low[i] < minimo then
minrelevante=0
endif
if high[i] > maximo then
maxrelevante=0
endif
endif
next
IF minrelevante=1 THEn
DRAWARROWUP (barindex-centro,minimo-(minimo*0.01)) coloured(231, 155, 208)
m20bajista=(m20[centro]-m20)>0
if rcE4 and m20bajista then
//DRAWELLIPSE(barindex-centro-1, low[centro]-(low[centro]*0.01), barindex-1, high[centro-1]+(high[centro-1]*0.01)) coloured(102, 178, 255)
endif
if rcE4a and m20bajista then
//DRAWELLIPSE(barindex-centro-2, high[centro+1]+(high[centro+1]*0.01), barindex-centro+1, low[centro]-(low[centro]*0.01)) coloured(102, 178, 255)
endif
ENDIF
IF maxrelevante=1 THEn
m20alcista=(m20-m20[centro])>0
DRAWARROWDOWN (barindex-centro,maximo+(maximo*0.01)) coloured(231, 155, 208)
if rcE2 and m20alcista then
//DRAWELLIPSE(barindex-centro-1, maximo+(maximo*0.01), barindex-1, low[2]-(low[2]*0.01)) coloured(231, 155, 208)
endif
if rcE2a and m20alcista then
//DRAWELLIPSE(barindex-centro-2, low[centro]-(low[centro]*0.01), barindex-centro+1, high[centro]+(high[centro]*0.01)) coloured(231, 155, 208)
endif
//if (open[2] > close[centro]) and (range[2] > range[centro]*0.5) then
//DRAWARROWDOWN (barindex-2,maximo+(maximo*0.01)) coloured(255, 255, 255)
//endif
ENDIF
return
patron=0
TIMEFRAME(daily)
avgv5 = average[5](volume)
avgv20 = average[20](volume)
avgv50 = average[50](volume)
avgv100 = average[100](volume)
avgv200 = average[200](volume)
minimoVolumen = avgv5>VolumenK*1000 and avgv20>VolumenK*1000 and avgv50>VolumenK*1000 and avgv100>VolumenK*1000 and avgv200>VolumenK*1000
TIMEFRAME(weekly)
if close>1 and open>1 and minimoVolumen then
min1=0
min2=0
for mini=0 to 251
if mini>=3 then
EsMini=(low[mini]<=low[mini-3]) AND (low[mini]<=low[mini-2]) AND (low[mini]<=low[mini-1]) AND (low[mini]<=low[mini+1]) AND (low[mini]<=low[mini+2]) AND (low[mini]<=low[mini+3])
if EsMini then
if min1=0 then
min1=low[mini]
elsif min2=0 then
min2=low[mini]
break
endif
endif
endif
next
if min1<min2 then
distanciaRentabilidad=((close-min1)/close)*100
if distanciaRentabilidad>rentabilidad then
patron=1
endif
endif
endif
if patron then
patron=0
TIMEFRAME(daily)
m200 = average[200](close)
if close<m200 then
c1M200=0
c2M200=0
c3M200=0
max1=0
max2=0
for maxi=0 to 251
if maxi>=3 then
maxRel=(high[maxi]>=high[maxi-3]) AND (high[maxi]>=high[maxi-2]) AND (high[maxi]>=high[maxi-1]) AND (high[maxi]>=high[maxi+1]) AND (high[maxi]>=high[maxi+2]) AND (high[maxi]>=high[maxi+3])
if maxRel then
if max1=0 then
max1=high[maxi]
c1M200=high[maxi]<m200
elsif max2=0 then
max2=high[maxi]
c2M200=high[maxi]<m200
break
endif
endif
endif
next
min1t=0
min2t=0
for minit=0 to 251
if minit >=3 then
EsMinit = (low[minit]<=low[minit-3]) AND (low[minit]<=low[minit-2]) AND (low[minit]<=low[minit-1]) AND (low[minit]<=low[minit+1]) AND (low[minit]<=low[minit+2]) AND (low[minit]<=low[minit+3])
if EsMinit then
if min1t=0 then
min1t=low[minit]
c3M200=low[minit]<m200
elsif min2t=0 then
min2t=low[minit]
break
endif
endif
endif
next
if (max1>max2 and c1M200 and c2M200 and min1t>min1t and c3M200) or (close>max1 and close>max2 and c1M200 and c2M200 and c3M200) then
maximo=0
minimo=9999
for i=0 to 3
if maximo<high[i] then
maximo=high[i]
endif
if minimo>low[i] then
minimo=low[i]
endif
next
if m200>minimo and m200<maximo then
patron=1
endif
endif
endif
endif
screener[patron]