Code vertical lines on 3rd fridays  [SOLVED]

Questions about MultiCharts and user contributed studies.
paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Code vertical lines on 3rd fridays

Postby paul.robillard » 20 Nov 2015

To draw a vertical line on the 3rd friday of every month on an historical graph I have come up with the following code. Given MC calculates for ever, i believe i may have an infinite loop.

Code: Select all

while (count < 3) begin
if (month(date) = month(date[1])) and (dayofweek(date) = 5) and (count = 3) then
begin
thirdfriday = date;
print(thirdfriday);
TLID =
tl_new(thirdfriday,900,0,thirdfriday,900,low-100);
tl_SetColor(TLID, green);
tl_setstyle(TLID, 1);
count = 0;
// txtID = Text_New(thirdfriday, Time, low-50, text(thirdfriday));
end
else if ( (month(date) = month(date[1])) and (dayofweek(date) = 5) and (count < 3) ) then
count = (count + 1);
end;
Thank you for your help

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: Code vertical lines on 3rd fridays

Postby paul.robillard » 22 Nov 2015

Finally i read somewhere that 3rd fridays are allways between the 15 and 21st of the month, given the comment (overthinking it) sank in, i came up with this :

Code: Select all

{assuming 3rd friday's are allways between the 15th and 21st}

if dayofmonth(date)>14 and dayofmonth(date)<22 and dayofweek(date)=5 then
begin
thirdfriday = date;
// print(thirdfriday);
TLID =
tl_new(thirdfriday,900,0,thirdfriday,900,low-100);
tl_SetColor(TLID, green);
tl_setstyle(TLID, 1);
end;
and the result seems pretty good.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Code vertical lines on 3rd fridays  [SOLVED]

Postby TJ » 22 Nov 2015

You had previously asked about the Next3rdFriday function.

Code: Select all


if Next3rdFriday(0)=0
and Next3rdFriday(0)[1]<>0
then begin

There is more than one way to skin a cat... not necessary this way is better than the other; as long as the code gets the job done, it is ok.

paul.robillard
Posts: 30
Joined: 22 Mar 2012
Location: Western Europe
Has thanked: 6 times

Re: Code vertical lines on 3rd fridays

Postby paul.robillard » 23 Nov 2015

As i am backtesting some i figured next3rdfriday (wrongly ?) would not do the job.

Thanks.


Return to “MultiCharts”