generating a support and resistance array

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #230462 quote
    juld63
    Participant
    New

    Hi everyone,

    I am trying to generate a support and resistance array that updates daily at 10PM by taking the highest and lowest of the past 24hours and weeding out the past lines that are comprised between those two. Here is the code I’ve managed so far:

    
    //past values stored for testing
    $res[0]=16648
    $res[1]=16787.7
    $res[2]=16960.2
    $res[3]=17003.9
    $res[4]=16443.6
    $res[5]=16390.6
    $res[6]=16250
    $res[7]=15987.8
    $res[8]=15913
    $res[9]=15880.7
    $res[10]=15701.4
    $res[11]=15638.9
    $res[12]=15480.9
    $res[13]=15333
    $res[14]=15236.7
    $res[15]=15170.1
    $res[16]=15075
    $res[17]=15048.9
    $res[18]=14990.1
    $res[19]=14928.9
    $res[20]=14785.4
    $res[21]=14691.5
    $res[22]=14633.1
    $res[23]=14589.2
    $res[24]=14460
    
    $sup[0]=16648
    $sup[1]=16787.7
    $sup[2]=16960.2
    $sup[3]=17003.9
    $sup[4]=16443.6
    $sup[5]=16390.6
    $sup[6]=16250
    $sup[7]=15987.8
    $sup[8]=15913
    $sup[9]=15880.7
    $sup[10]=15701.4
    $sup[11]=15638.9
    $sup[12]=15480.9
    $sup[13]=15333
    $sup[14]=15236.7
    $sup[15]=15170.1
    $sup[16]=15075
    $sup[17]=15048.9
    $sup[18]=14990.1
    $sup[19]=14928.9
    $sup[20]=14785.4
    $sup[21]=14691.5
    $sup[22]=14633.1
    $sup[23]=14589.2
    $sup[24]=14460
    
    
    //periode is defined as 24hours or 97 quarter-hour candles
    period = 97
    ONCE myindexres=25
    ONCE myindexsup=25
    
    //10PM is when we fill and filter the arrays
    if time=220000  Then
    
    //add highest and lowest since yesterday 10PM and draw them as lines
    $res[myindexres] = highest[period](high)
    DRAWHLINE($res[myindexres]) COLOURED ("RED")
    $sup[myindexsup] = lowest[period](low)
    DRAWHLINE($sup[myindexsup]) COLOURED ("BLUE")
    
    //reset all past resistance values that are engulfed by the last 24h highest and lowest
    FOR a=0 to myindexres-1 DO
    IF $res[a]<$res[myindexres] AND $res[a]>$sup[myindexsup] THEN
    $res[a]=0
    CONTINUE
    ENDIF
    //only draw the resistance lines when they are not engulfed
    IF IsSet($res[a])=1 THEN
    DRAWHLINE($res[a]) COLOURED ("ORANGE") STYLE (Dottedline1)
    CONTINUE
    ENDIF
    NEXT
    
    //reset all past support values that are engulfed by the last 24h highest and lowest
    FOR a=0 to myindexsup-1 DO
    IF $sup[a]<$res[myindexres] AND $sup[a]>$sup[myindexsup] THEN
    $sup[a]=0
    CONTINUE
    ENDIF
    //only draw the resistance lines when they are not engulfed
    IF IsSet($sup[a])=1 THEN
    DRAWHLINE($sup[a]) COLOURED ("CYAN") STYLE (Dottedline2)
    CONTINUE
    ENDIF
    NEXT
    
    //reset the index count for the next day
    IF IsSet($res[myindexres])=1 THEN
    myindexres=myindexres+1
    ENDIF
    
    IF IsSet($sup[myindexsup])=1 THEN
    myindexsup=myindexsup+1
    endif
    ENDIF
    
    
    
    RETURN
    

    My problem is the following:

    If I ask to calculate only on the last 100 bars, i. e. on the 24hours (I’m working on 15mn candles) it will only work on the previous 10PM occurrence.

    If do not put “DefParam CalculateOnLastBars=x” it displays all the past results of all the past occurrences of 10PM simultaneously, which kinda defeats the purpose. For example, say we are on day 4: day 1 highest is not comprised between highest and lowest of day 2 but is comprised between highest and lowest of day 3. So it disappears on day 3 but since the graphics displays all the daily results it still shows up as a day 2 result. I know I’m not being utterly clear but you get the idea.

    If I ask “DefParam ShowOnLastBarOnly=true” it doesn’t display anything unless the last bar is indeed the 10PM bar.

    So the question is: who can I get it to show the last state of the array while having it calculate all the previous states?

     

    Thanks a lot !

    #237550 quote
    robertogozzi
    Moderator
    Master

    Can you post the value of the missing variables (or the ITF file)?

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

generating a support and resistance array


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
juld63 @juld63 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by robertogozzi
1 year, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/26/2024
Status: Active
Attachments: No files
Logo Logo
Loading...