Monthly range and january/july range

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

    Good morning,

    i’d like to code an indicator which shows two different ranges:

    • the first draws two parallel dotted lines corresponding to the high and the low of the first candle of each month, so the lines are one month long.
    • the second draws two parallel dotted lines corresponding to the high and the low of the first ten days of january and july, so the lines are one year long.

    Please, see the attached picture for a better understanding.

     

    Is this possible to code??

    Thank you and have a nice day.

    monthly-range-jan-jul-range.jpg monthly-range-jan-jul-range.jpg
    #116624 quote
    robertogozzi
    Moderator
    Master

    There you go.

    This is for v10.3 (no dotted lines):

    DEFPARAM DrawOnLastBarOnly = true
    ONCE MonthLO    = low
    ONCE MonthHI    = high
    ONCE JanLO      = low
    ONCE JanHI      = high
    ONCE JulLO      = low
    ONCE JulHI      = high
    ONCE MonthStart = 0
    ONCE JanStart   = 0
    ONCE JulStart   = 0
    //
    IF OpenMonth <> OpenMonth[1] THEN
       MonthLO    = low
       MonthHI    = high
       MonthStart = barindex
    ENDIF
    //
    IF OpenMonth = 1 THEN
       IF OpenDay >= 1 AND OpenDay <= 10 THEN
          IF OpenMonth <> OpenMonth[1] THEN
             JanStart = barindex
             JanLO    = low
             JanHI    = high
          ENDIF
          JanLO  = min(low,JanLO)
          JanHI  = max(high,JanHI)
       ENDIF
    ENDIF
    //
    IF OpenMonth = 7 THEN
       IF OpenDay >= 1 AND OpenDay <= 10 THEN
          IF OpenMonth <> OpenMonth[1] THEN
             JulStart = barindex
             JulLO  = low
             JulHI  = high
          ENDIF
          JulLO  = min(low,JulLO)
          JulHI  = max(high,JulHI)
       ENDIF
    ENDIF
    //
    DRAWSEGMENT(MonthStart,MonthHI,barindex,MonthHI) COLOURED(0,255,0,255)       //GREEN
    DRAWSEGMENT(MonthStart,MonthLO,barindex,MonthLO) COLOURED(255,0,0,255)       //RED
    //
    DRAWSEGMENT(JanStart,JanHI,barindex,JanHI)       COLOURED(0,0,255,255)       //BLUE
    DRAWSEGMENT(JanStart,JanLO,barindex,JanLO)       COLOURED(148,0,211,255)     //DARKVIOLET
    //
    DRAWSEGMENT(JulStart,JulHI,barindex,JulHI)       COLOURED(255,215,0,255)     //GOLD
    DRAWSEGMENT(JulStart,JulLO,barindex,JulLO)       COLOURED(169,169,169,255)   //DARKGREY
    RETURN

    If you have version 11 and want to plot dotted lines, then replace the DRAWSEGMENT lines with:

    DRAWSEGMENT(MonthStart,MonthHI,barindex,MonthHI) COLOURED(0,255,0,255)     STYLE(dottedline,2)  //GREEN
    DRAWSEGMENT(MonthStart,MonthLO,barindex,MonthLO) COLOURED(255,0,0,255)     STYLE(dottedline,2)  //RED
    //
    DRAWSEGMENT(JanStart,JanHI,barindex,JanHI)       COLOURED(0,0,255,255)     STYLE(dottedline,2)  //BLUE
    DRAWSEGMENT(JanStart,JanLO,barindex,JanLO)       COLOURED(148,0,211,255)   STYLE(dottedline,2)  //DARKVIOLET
    //
    DRAWSEGMENT(JulStart,JulHI,barindex,JulHI)       COLOURED(255,215,0,255)   STYLE(dottedline,2)  //GOLD
    DRAWSEGMENT(JulStart,JulLO,barindex,JulLO)       COLOURED(169,169,169,255) STYLE(dottedline,2)  //DARKGREY
    FabiusMor thanked this post
    x-2.jpg x-2.jpg
    #116637 quote
    FabiusMor
    Participant
    Junior

    Awesome! Thank you very much Roberto!

    Just one little thing: it looks like that for the january/july range it takes into consideration just the first six candles ( instead of ten) to estabilish the high and the low.

     

    I gave a look at the code but can’t find anything that could lead to that.

    #116638 quote
    robertogozzi
    Moderator
    Master

    You wrote the first 10 days, not the first 10 trading days.

    I’ll add a counter to achieve that, asap.

    #116640 quote
    FabiusMor
    Participant
    Junior

    Oops, sorry for the imprecision!

    #116653 quote
    robertogozzi
    Moderator
    Master

    This is the version for the first 10 trading days:

    DEFPARAM DrawOnLastBarOnly = true
    ONCE MonthLO    = low
    ONCE MonthHI    = high
    ONCE JanLO      = low
    ONCE JanHI      = high
    ONCE JulLO      = low
    ONCE JulHI      = high
    ONCE MonthStart = 0
    ONCE JanStart   = 0
    ONCE JulStart   = 0
    //
    IF OpenMonth <> OpenMonth[1] THEN
    MonthLO    = low
    MonthHI    = high
    MonthStart = barindex
    ENDIF
    //
    IF OpenMonth = 1 THEN
    IF OpenDay >= 1 AND OpenDay <= 30 THEN
    IF OpenMonth <> OpenMonth[1] THEN
    JanStart = barindex
    JanLO    = low
    JanHI    = high
    Count    = 1
    ENDIF
    IF Count <= 10 THEN
    JanLO  = min(low,JanLO)
    JanHI  = max(high,JanHI)
    ENDIF
    IF OpenDay <> OpenDay[1] THEN
    Count = Count + 1
    ENDIF
    ENDIF
    ENDIF
    //
    IF OpenMonth = 7 THEN
    IF OpenDay >= 1 AND OpenDay <= 30 THEN
    IF OpenMonth <> OpenMonth[1] THEN
    JulStart = barindex
    JulLO  = low
    JulHI  = high
    Count    = 1
    ENDIF
    IF Count <= 10 THEN
    JulLO  = min(low,JulLO)
    JulHI  = max(high,JulHI)
    ENDIF
    IF OpenDay <> OpenDay[1] THEN
    Count = Count + 1
    ENDIF
    ENDIF
    ENDIF
    //
    DRAWSEGMENT(MonthStart,MonthHI,barindex,MonthHI) COLOURED(0,255,0,255)       //GREEN
    DRAWSEGMENT(MonthStart,MonthLO,barindex,MonthLO) COLOURED(255,0,0,255)       //RED
    //
    DRAWSEGMENT(JanStart,JanHI,barindex,JanHI)       COLOURED(0,0,255,255)       //BLUE
    DRAWSEGMENT(JanStart,JanLO,barindex,JanLO)       COLOURED(148,0,211,255)     //DARKVIOLET
    //
    DRAWSEGMENT(JulStart,JulHI,barindex,JulHI)       COLOURED(255,215,0,255)     //GOLD
    DRAWSEGMENT(JulStart,JulLO,barindex,JulLO)       COLOURED(169,169,169,255)   //DARKGREY
    RETURN

    for v11 you need to replace the same lines as before (they are not affected by modifications).

    FabiusMor thanked this post
    #116655 quote
    FabiusMor
    Participant
    Junior

    Works perfectly, thank you so much Roberto!

     

    Have a nice day!

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

Monthly range and january/july range


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
FabiusMor @fabiusmor Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 01/13/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...