Hello,
I’m trying to understand better the use of array, and for example I read the indicator at this link made by Nicolas: https://www.prorealcode.com/topic/array-variables-availability-in-prorealtime/
If I Want to make a strategy using midlevel,is it correct this way?
//defparam drawonlastbaronly=true
TIMEFRAME(1 Days, UPDATEONCLOSE )
// --- settings
fractalP = 10
percent = 0.5
barlimit = 200
// --- end of settings
//fractals
cp=fractalP
if high[cp] >= highest[(cp)*2+1](high) then //new fractal high found
$TOPy[lastset($TOPy)+1] = high[cp] //store fractal value
$TOPx[lastset($TOPx)+1] = barindex[cp] //store fractal barindex
endif
if low[cp] <= lowest[(cp)*2+1](low) then //new fractal low found
$BOTy[lastset($BOTy)+1] = low[cp] //store fractal value
$BOTx[lastset($BOTx)+1] = barindex[cp] //stire fractal barindex
endif
if(islastbarupdate and isset($topy[0]) and isset($boty[0])) then
//check points in a range of X percent
for i = 0 to lastset($TOPy) do //loop through the tops
for y = 0 to lastset($TOPy) do //check first top with other tops
change=abs(($topy[y]-$topy[i])/$topy[i]) //percent range between the 2 tops
if change<=percent/100 and barindex-$TOPx[y]<barlimit and $topx[i]<>$topx[y] then
if close>min($topy[y],$topy[i]) then //define the color
r=0
g=255
else
r=255
g=0
endif
//plot points at each tops
//DRAWPOINT($topx[i],$topy[i],2) COLOURED (r,g,0) BORDERCOLOR (r,g,0)
//DRAWPOINT($topx[y],$topy[y],2) COLOURED (r,g,0) BORDERCOLOR (r,g,0)
midlevel=($topy[i]+$topy[y])/2
//display the mid level price
//DRAWTEXT("#midlevel#", barindex+8, midlevel, monospaced, standard, 14)
//plot the zone
//drawrectangle(min($topx[y],$topx[i]),$topy[y],barindex,$topy[i]) coloured(r,g,50,50) bordercolor(r,g,0)
endif
next
next
for i = 0 to lastset($BOTy) do //loop through the bottoms
for y = 0 to lastset($BOTy) do //check first bottom with other bottoms
change=abs(($boty[y]-$boty[i])/$boty[i]) //percent range between the 2 bottoms
if change<=percent/100 and barindex-$BOTx[y]<barlimit and $BOTx[i]<>$BOTx[y] then
if close<max($boty[y],$boty[i]) then //define the color
//DRAWPOINT($botx[i],$boty[i],2) COLOURED (r,g,0) BORDERCOLOR (r,g,0)
//DRAWPOINT($botx[y],$boty[y],2) COLOURED (r,g,0) BORDERCOLOR (r,g,0)
midlevel=($boty[i]+$boty[y])/2
endif
//DRAWTEXT("#midlevel#", barindex+8, midlevel, monospaced, standard, 14)
//drawrectangle(min($botx[y],$botx[i]),$boty[y],barindex,$boty[i]) coloured(r,g,50,50) bordercolor(r,g,0)
endif
next
next
endif
TIMEFRAME(5 minutes)
C1= close < (midlevel +(percent/100)*midlevel)
c2=close> (midlevel -(percent/100)*midlevel)
if not LONGONMARKET and C1 and c2 then
buy 1 SHARES AT MARKET
endif
Set Stop loss 30
Set Target profit 60
It works, of course no good, but I’m not sure that this indicator is configured to work with timeframe (1 day) updateonclose. Buying share at midlevel, probably I’d have to use an array also for midlevel?
thank’s in advance to everyone can help me understand
Alessio