Determine a specific day

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #42471 quote
    Business Trader Pro
    Participant
    New

    Hi guys,

    is there a way to retrieve a specific day of the year? For example: My indicator should show me the 01.04.2017 and the 02.07.2017 with backgroundcolor.

    I need this because my trading system should rebalance my positions quarterly.

     

    Thanks in advance

    Business Trader

    #42481 quote
    robertogozzi
    Moderator
    Master

    You may try this piece of code (I tested it, but I am not sure that’s what you want):

    IF Month = 1 OR Month = 4 OR Month = 7 OR Month = 10 THEN  //only 1st month of each quarter
       FOR I = 0 TO 6                                          //scan a whole week to check it's FOREX time
          IF Day = i AND DayOfWeek = 2 THEN                    //only color the first Monday
             backgroundcolor(173,255,47,128)                   //Green Yellow (255,128,64,32 or 0 in the 4th group of numbers is the FADE gradient, 255=max 0=invisible)
             break                                             //if found then skip any further check
          ENDIF
       NEXT
    ENDIF
    RETURN
    #42938 quote
    Business Trader Pro
    Participant
    New

    Thx Roberto,

    il will give it a try and let you know about the results.

     

    Greets from Italy to Italy 😉

    #42946 quote
    Business Trader Pro
    Participant
    New

    I tried your code with following results:

    It shows me (plus/minus) the first monday of each month. The goal should be to fetch every first trading day (not saturday or sunday) of the quarter.

    Any solutions?

     

    Many regards

    Tradewolf

    #42952 quote
    robertogozzi
    Moderator
    Master

    I tried this one:

    ONCE DayFound = 1
    IF Month <> Month[1] THEN
       DayFound = 0
    ENDIF
    IF Month = 1 OR Month = 4 OR Month = 7 OR Month = 10 THEN
       IF ((DayOfWeek = 1) OR (DayOfWeek = 2) OR (DayOfWeek = 3) OR (DayOfWeek = 4) OR (DayOfWeek = 0)) AND (DayFound = 0) THEN
          backgroundcolor(173,255,47,255)
          DayFound = 1
       ENDIF
    ENDIF
    RETURN
    

    But it does not work as expected. I still cannot understand, for DAILY bars, what is returned bu DayOfWeek when the indicator is executed, the DAY of the closed BAR or the DAY of the bar which is opening?!

    And If I want to change the background it changes the nackground color of the opening bar, since the bar that is close has already been displayed on video, is it true?

    Only Nicolas can help us out! Thanks a lot!!!

    #42958 quote
    JC_Bywan
    Moderator
    Master

    The following code should work, not just for standard quarters, but also even with a January 1st on a friday the code should/would pick monday Jan.4th instead of friday Jan.1st:

    If (OpenMonth=1 or Openmonth=4 or Openmonth=7 or Openmonth=10) and OpenDay<=4 and OpenDayOfWeek>=1 and OpenDayOfWeek<=5 and opendate-firstdayofquarter>3 then
      backgroundcolor(0,0,255)
      firstdayofquarter=OpenDate
    endif
    
    // choose only one of the following 2 return lines:
    // - the empty return line if wanting only backgroundcolor,
    // - or the second return line if wanting to read dates data in yyyymmdd format
    
    return
    //return firstdayofquarter as "first day of quarter"
    Derek, Business Trader Pro, robertogozzi and Bel thanked this post
    #43026 quote
    Business Trader Pro
    Participant
    New

    Thanks Noobywan, this did the trick. “OpenDay” was new to me. Never used it.

    Regards

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

Determine a specific day


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Business Trader Pro
8 years, 6 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/04/2017
Status: Active
Attachments: No files
Logo Logo
Loading...