Array support Resistance buy on Midlevel

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #213645 quote
    Aragorna
    Participant
    Junior

    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

    #213653 quote
    robertogozzi
    Moderator
    Master

    Firstly, 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?

    #213681 quote
    Aragorna
    Participant
    Junior

    hi 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?

    #213682 quote
    Aragorna
    Participant
    Junior
    //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 
    midlevel=($topy[i]+$topy[y])/2
    endif
    
    
    
    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

    you’re right, midlevel should be in the same place.

    #213701 quote
    Aragorna
    Participant
    Junior

    If 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! 🙂

    #213702 quote
    Aragorna
    Participant
    Junior

    I’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.

    //defparam drawonlastbaronly=true
    //TIMEFRAME(1 Days, UPDATEONCLOSE )
    // --- settings
    fractalP = 6
    percent = 0.5
    barlimit = 500
    // --- end of settings
    TIMEFRAME( 1 days,UPDATEONCLOSE) 
    //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
    
    $midlevelT[lastset($midlevelT)+1]=($topy[i]+$topy[y])/2
    
    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
    $midlevelB[lastset($midlevelB)+1]=($boty[i]+$boty[y])/2
    endif
    next
    next
    endif
    TIMEFRAME(5 minutes)
    if(islastbarupdate) then
    for Z = 0 to lastset($midlevelT) do //loop through the MiddlelevelT
    for K = 0 to lastset($midlevelB) do //loop through the MiddlelevelB
    C1= 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])
    next
    next
    endif
    if not LONGONMARKET and (C1 and c2) or (C3 and C4) then
    buy 1 SHARES AT MARKET
    endif
    Set Stop loss 30
    Set Target profit 60

    should be correct. I don’t understand. Please Roberto if you can help me would be great.

    Alessio

    #213937 quote
    robertogozzi
    Moderator
    Master

    You 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 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Array support Resistance buy on Midlevel


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Aragorna @aragorna Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by robertogozzi
2 years, 9 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/24/2023
Status: Active
Attachments: No files
Logo Logo
Loading...