Weekly version of envelope Top and bottom

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #256910 quote
    oyinloyea
    Participant
    Veteran

    I need help with programming the weekly version of the code shown below without using “Timeframe (weekly)”


    DEFPARAM CalculateOnLastBars = 1000

    defparam drawonlastbaronly=true

    Voffset = -0*pipsize


    H1 = DHigh(1)

    L1 = DLow(1)

    C1 = DClose(1)

    H2 =DHigh(2)

    L2 = DLow(2)

    C2 = DClose(2)

    H3 = DHigh(3)

    L3 = DLow(3)

    C3 = DClose(3)

    PLdotDay= ((H1+L1+C1)/3 + (H2+L2+C2)/3 + (H3+L3+C3)/3)/3





    // Envelope Top and Bottom

    envelopeTopDay= (H1 + H2 + H3) / 3

    envelopeBottomDay= (L1 + L2 + L3) / 3


    Timeframe (Default)

    drawtext(“envelopeTopDay”,barindex,envelopeTopDay+Voffset,SansSerif,Bold,10)

    DRAWSEGMENT(barindex, envelopeTopDay, barindex+10, envelopeTopDay)


    drawtext(“envelopebottomday”,barindex,envelopebottomday+Voffset,SansSerif,Bold,10)

    DRAWSEGMENT(barindex, envelopebottomday, barindex+10, envelopebottomday)


    drawtext(“pldotday”,barindex,pldotday +Voffset,SansSerif,Bold,10)

    DRAWSEGMENT(barindex, pldotday, barindex+10, pldotday)

    Return envelopetopDay as “envelopetopDay”, envelopebottomday as “envelopebottomday”,pldotday as “pldotday”

    #256913 quote
    Iván González
    Moderator
    Master

    maybe this helps you

    // --- Manual Weekly Data Calculation ---
    defparam drawonlastbaronly=true
    ONCE weekIndex = 0
    // Current week tracking variables
    ONCE currentWeekHigh = High
    ONCE currentWeekLow = Low
    // Historical weekly values (W1 = last week, W2 = 2 weeks ago, W3 = 3 weeks ago)
    ONCE weekHigh1 = 0
    ONCE weekLow1 = 0
    ONCE weekClose1 = 0
    
    ONCE weekHigh2 = 0
    ONCE weekLow2 = 0
    ONCE weekClose2 = 0
    
    ONCE weekHigh3 = 0
    ONCE weekLow3 = 0
    ONCE weekClose3 = 0
    
    IF DayOfWeek < DayOfWeek[1] THEN
       // A new week has started: Shift historical values
       weekHigh3 = weekHigh2
       weekLow3 = weekLow2
       weekClose3 = weekClose2
       
       weekHigh2 = weekHigh1
       weekLow2 = weekLow1
       weekClose2 = weekClose1
       
       weekHigh1 = currentWeekHigh
       weekLow1 = currentWeekLow
       weekClose1 = Close[1]
       
       // Reset trackers for the new week
       currentWeekHigh = High
       currentWeekLow = Low
       weekIndex = weekIndex + 1
    ELSE
       // Update high and low during the current week
       IF High > currentWeekHigh THEN
          currentWeekHigh = High
       ENDIF
       
       IF Low < currentWeekLow THEN
          currentWeekLow = Low
       ENDIF
    ENDIF
    
    // --- Indicator Logic ---
    
    // Only calculate if we have at least 3 full weeks of data
    IF weekIndex >= 3 THEN
       // PL Dot calculation
       plDotW1 = (weekHigh1 + weekLow1 + weekClose1) / 3
       plDotW2 = (weekHigh2 + weekLow2 + weekClose2) / 3
       plDotW3 = (weekHigh3 + weekLow3 + weekClose3) / 3
       
       plDotWeekly = (plDotW1 + plDotW2 + plDotW3) / 3
       
       // Envelope Top and Bottom
       envelopeTopWeekly = (weekHigh1 + weekHigh2 + weekHigh3) / 3
       envelopeBottomWeekly = (weekLow1 + weekLow2 + weekLow3) / 3
       
       // Offset for text
       vOffset = 0 * PipSize
       
       // Drawing elements
       DRAWTEXT("EnvTop Weekly", barindex, envelopeTopWeekly + vOffset, SansSerif, Bold, 10)
       DRAWSEGMENT(barindex, envelopeTopWeekly, barindex + 10, envelopeTopWeekly)
       
       DRAWTEXT("EnvBottom Weekly", barindex, envelopeBottomWeekly + vOffset, SansSerif, Bold, 10)
       DRAWSEGMENT(barindex, envelopeBottomWeekly, barindex + 10, envelopeBottomWeekly)
       
       DRAWTEXT("PL Dot Weekly", barindex, plDotWeekly + vOffset, SansSerif, Bold, 10)
       DRAWSEGMENT(barindex, plDotWeekly, barindex + 10, plDotWeekly)
    ENDIF
    
    RETURN envelopeTopWeekly AS "Envelope Top Weekly", envelopeBottomWeekly AS "Envelope Bottom Weekly", plDotWeekly AS "PL Dot Weekly"
    


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

Weekly version of envelope Top and bottom


Platform Support: Charts, Data & Broker Setup

New Reply
Author
author-avatar
oyinloyea @oyinloyea Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
2 weeks, 5 days ago.

Topic Details
Forum: Platform Support: Charts, Data & Broker Setup
Language: English
Started: 01/26/2026
Status: Active
Attachments: No files
Logo Logo
Loading...