Array support Resistance buy on Midlevel
Forums › ProRealTime English forum › ProOrder support › Array support Resistance buy on Midlevel
 This topic has 6 replies, 2 voices, and was last updated 1 year ago by robertogozzi.


04/24/2023 at 3:07 AM #213645
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/arrayvariablesavailabilityinprorealtime/
If I Want to make a strategy using midlevel,is it correct this way?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768//defparam drawonlastbaronly=trueTIMEFRAME(1 Days, UPDATEONCLOSE )//  settingsfractalP = 10percent = 0.5barlimit = 200//  end of settings//fractalscp=fractalPif 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 barindexendifif 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 barindexendifif(islastbarupdate and isset($topy[0]) and isset($boty[0])) then//check points in a range of X percentfor i = 0 to lastset($TOPy) do //loop through the topsfor y = 0 to lastset($TOPy) do //check first top with other topschange=abs(($topy[y]$topy[i])/$topy[i]) //percent range between the 2 topsif change<=percent/100 and barindex$TOPx[y]<barlimit and $topx[i]<>$topx[y] thenif close>min($topy[y],$topy[i]) then //define the colorr=0g=255elser=255g=0endif//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)endifnextnextfor i = 0 to lastset($BOTy) do //loop through the bottomsfor y = 0 to lastset($BOTy) do //check first bottom with other bottomschange=abs(($boty[y]$boty[i])/$boty[i]) //percent range between the 2 bottomsif change<=percent/100 and barindex$BOTx[y]<barlimit and $BOTx[i]<>$BOTx[y] thenif 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])/2endif//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)endifnextnextendifTIMEFRAME(5 minutes)C1= close < (midlevel +(percent/100)*midlevel)c2=close> (midlevel (percent/100)*midlevel)if not LONGONMARKET and C1 and c2 thenbuy 1 SHARES AT MARKETendifSet Stop loss 30Set Target profit 60It 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
04/24/2023 at 8:58 AM #213653Firstly, you have placed the two lines where midlevel is calculated in different places. The first one is in between two ENDIFs, while the latter is inside the inner ENDIF. They will behave differently.
Secondly, what do you mean exactly by MIDLEVEL?
04/24/2023 at 3:43 PM #213681hi roberto,
I just wanted to incorporate the array support/resistance in a strategy, I made comments the parts with draw rectangle. for what I understand Midlevel is the middle value between a bottom or a top that overlap with a previous bottom or top before in a range of 0,5 %. the midlevel is the middle point of the range between the two bottoms or two tops identified by this condition, is it right?
what I want is to understand when price is in the range given by the condition of the indicator; for simplicity I’ve used midlevel Because I’d not know how to identify that area of support or resistance. Midlevel is used both for tops and bottoms, so this makes me confuse. Can you enlight me please?
04/24/2023 at 3:49 PM #2136821234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859//defparam drawonlastbaronly=trueTIMEFRAME(1 Days, UPDATEONCLOSE )//  settingsfractalP = 10percent = 0.5barlimit = 200//  end of settings//fractalscp=fractalPif 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 barindexendifif 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 barindexendifif(islastbarupdate and isset($topy[0]) and isset($boty[0])) then//check points in a range of X percentfor i = 0 to lastset($TOPy) do //loop through the topsfor y = 0 to lastset($TOPy) do //check first top with other topschange=abs(($topy[y]$topy[i])/$topy[i]) //percent range between the 2 topsif change<=percent/100 and barindex$TOPx[y]<barlimit and $topx[i]<>$topx[y] thenif close>min($topy[y],$topy[i]) thenmidlevel=($topy[i]+$topy[y])/2endifendifnextnextfor i = 0 to lastset($BOTy) do //loop through the bottomsfor y = 0 to lastset($BOTy) do //check first bottom with other bottomschange=abs(($boty[y]$boty[i])/$boty[i]) //percent range between the 2 bottomsif change<=percent/100 and barindex$BOTx[y]<barlimit and $BOTx[i]<>$BOTx[y] thenif 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])/2endif//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)endifnextnextendifTIMEFRAME(5 minutes)C1= close < (midlevel +(percent/100)*midlevel)c2=close> (midlevel (percent/100)*midlevel)if not LONGONMARKET and C1 and c2 thenbuy 1 SHARES AT MARKETendifSet Stop loss 30Set Target profit 60you’re right, midlevel should be in the same place.
04/24/2023 at 9:59 PM #213701If it’s possible Roberto it’d be great if you can explain me, in afew words without loosing your time, how could be used this code in astrategy. Price closes in the area of support and buy.thank’s in advance! I owe you a coffe! 🙂
04/24/2023 at 11:53 PM #213702I’ve tried to figure out my way, for what I could understand, but backtest don’t gove any rssult, I don’t understand what is wrong.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657//defparam drawonlastbaronly=true//TIMEFRAME(1 Days, UPDATEONCLOSE )//  settingsfractalP = 6percent = 0.5barlimit = 500//  end of settingsTIMEFRAME( 1 days,UPDATEONCLOSE)//fractalscp=fractalPif 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 barindexendifif 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 barindexendifif(islastbarupdate and isset($topy[0]) and isset($boty[0])) then//check points in a range of X percentfor i = 0 to lastset($TOPy) do //loop through the topsfor y = 0 to lastset($TOPy) do //check first top with other topschange=abs(($topy[y]$topy[i])/$topy[i]) //percent range between the 2 topsif change<=percent/100 and barindex$TOPx[y]<barlimit and $topx[i]<>$topx[y] then$midlevelT[lastset($midlevelT)+1]=($topy[i]+$topy[y])/2endifnextnextfor i = 0 to lastset($BOTy) do //loop through the bottomsfor y = 0 to lastset($BOTy) do //check first bottom with other bottomschange=abs(($boty[y]$boty[i])/$boty[i]) //percent range between the 2 bottomsif change<=percent/100 and barindex$BOTx[y]<barlimit and $BOTx[i]<>$BOTx[y] then$midlevelB[lastset($midlevelB)+1]=($boty[i]+$boty[y])/2endifnextnextendifTIMEFRAME(5 minutes)if(islastbarupdate) thenfor Z = 0 to lastset($midlevelT) do //loop through the MiddlelevelTfor K = 0 to lastset($midlevelB) do //loop through the MiddlelevelBC1= close < ($midlevelT[Z] +(percent/100)*$midlevelT[Z])c2=close> ($midlevelT[Z] (percent/100)*$midlevelT[Z])C3= close < ($midlevelB[K] +(percent/100)*$midlevelB[K])c4=close> ($midlevelB[K] (percent/100)*$midlevelB[K])nextnextendifif not LONGONMARKET and (C1 and c2) or (C3 and C4) thenbuy 1 SHARES AT MARKETendifSet Stop loss 30Set Target profit 60should be correct. I don’t understand. Please Roberto if you can help me would be great.
Alessio
05/01/2023 at 3:51 PM #213937You need to post the full details of your entry conditions and explain what you mean by MIDLEVEL.
If you can add some pics with comments it would be beneficial 🙂

AuthorPosts
Find exclusive trading protools on