# Need AFL for Plotting vertical lines on futures expiry dates in price chart

#### Aporio

##### New Member
I try to copy the code but it gives me an error. Can you help me? I find the idea very interesting. regards

#### Attachments

• 112.4 KB Views: 13

#### doss186

##### Well-Known Member
I try to copy the code but it gives me an error. Can you help me? I find the idea very interesting. regards
Find below the correct code to plot vertical line on expiry day.

Showthrsday = ParamToggle( "Show Lst Thursday", "No|Yes" );

function Lastthursday ()
{
Daysinmonth = IIf( Month() == 1 OR Month() == 3 OR Month() == 5 OR Month() == 7 OR
Month() == 8 OR Month() == 10 OR Month() == 12, 31, 30 );
Daysinmonthfeb = IIf( Year() % 4 == 0 AND Year() % 100 != 0, 29, 28 );
Daysinmonthfinal = IIf( Month() == 2, Daysinmonthfeb, Daysinmonth );
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 4, 1, 0 );
return returnvalue;
}

if ( Showthrsday )
{PlotShapes( IIf( Lastthursday(), shapeSmallCircle, shapeNone ), colorWhite, 0, L, -20 );
}

Plot(Lastthursday(),"Expiry Day",colorGreen,styleHistogram);

#### Aporio

##### New Member
Excuse me my mistake. I would like to be able to draw on the clandle on the graph the options expiration that is the third Friday of the month. And if you can paint on the bar the day ... better! I repeat, excuse me
Thank you

#### doss186

##### Well-Known Member
Excuse me my mistake. I would like to be able to draw on the clandle on the graph the options expiration that is the third Friday of the month. And if you can paint on the bar the day ... better! I repeat, excuse me
Thank you
For that just use styleownscale and it will do the needfull.

Showthrsday = ParamToggle( "Show Lst Thursday", "No|Yes" );

function Lastthursday ()
{
Daysinmonth = IIf( Month() == 1 OR Month() == 3 OR Month() == 5 OR Month() == 7 OR
Month() == 8 OR Month() == 10 OR Month() == 12, 31, 30 );
Daysinmonthfeb = IIf( Year() % 4 == 0 AND Year() % 100 != 0, 29, 28 );
Daysinmonthfinal = IIf( Month() == 2, Daysinmonthfeb, Daysinmonth );
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 4, 1, 0 );
return returnvalue;
}

if ( Showthrsday )
{PlotShapes( IIf( Lastthursday(), shapeSmallCircle, shapeNone ), colorWhite, 0, L, -20 );
}

Plot(Lastthursday(),"Expiry Day",colorGreen,styleHistogram|styleOwnScale);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

#### Aporio

##### New Member
It´s very good the styleownscale!!!!! thank you
but I need change the day thursday for third friday of month , day expiring option. And how I plot the date over the graph?.
I try change thrsday and write Friday baut "error"
Can you help me?
Regards

#### Attachments

• 103.2 KB Views: 7

#### sr114

##### Well-Known Member
function Lastthursday ()
{
Daysinmonth = IIf( Month() == 1 OR Month() == 3 OR Month() == 5 OR Month() == 7 OR
Month() == 8 OR Month() == 10 OR Month() == 12, 31, 30 );
Daysinmonthfeb = IIf( Year() % 4 == 0 AND Year() % 100 != 0, 29, 28 );
Daysinmonthfinal = IIf( Month() == 2, Daysinmonthfeb, Daysinmonth );
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 4, 1, 0 );
return returnvalue;
}

modified code
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 5, 1, 0 );

Thursday = 4, Friday = 5 .
Make this change.

#### GMeyyl

##### Member
function Lastthursday ()
{
Daysinmonth = IIf( Month() == 1 OR Month() == 3 OR Month() == 5 OR Month() == 7 OR
Month() == 8 OR Month() == 10 OR Month() == 12, 31, 30 );
Daysinmonthfeb = IIf( Year() % 4 == 0 AND Year() % 100 != 0, 29, 28 );
Daysinmonthfinal = IIf( Month() == 2, Daysinmonthfeb, Daysinmonth );
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 4, 1, 0 );
return returnvalue;
}

modified code
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 5, 1, 0 );

Thursday = 4, Friday = 5 .
Make this change.
Glad to see you back Subroto ji .

#### Aporio

##### New Member
Thanks for your help. I try to rewrite the code but I am very clumsy !!!

function Lastfriday ()
{
Daysinmonth = IIf( Month() == 1 OR Month() == 3 OR Month() == 5 OR Month() == 7 OR
Month() == 8 OR Month() == 10 OR Month() == 12, 31, 30 );
Daysinmonthfeb = IIf( Year() % 4 == 0 AND Year() % 100 != 0, 29, 28 );
Daysinmonthfinal = IIf( Month() == 2, Daysinmonthfeb, Daysinmonth );
returnvalue = IIf( Daysinmonthfinal - Day() < 7 AND DayOfWeek() == 5, 1, 0 );
Friday = 5
return returnvalue;
}
if ( Showfriday )
{PlotShapes( IIf( Lastfriday(), shapeSmallCircle, shapeNone ), colorWhite, 0, L, -20 );
}

Plot(Lastfriday(),"Expiry Day",colorGreen,styleHistogram|styleOwnScale);
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

.

#### Attachments

• 104.9 KB Views: 6

#### Aporio

##### New Member
One more thing, can I paint/plot the expiration options third Friday from month to future? Could you make an annual calendar indicator and select the days I want to plot?
thanks

#### Aporio

##### New Member
Hello, I have not been able to write the code to draw vertical lines that paint their date at the base of the vertical line and to be able to put them to the right of the graph. So I can mark the future maturities of the year of options.
regards