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

#1
AFL Gurus,

I have zero coding experience in AFL.

I need a simple AFL that will plot vertical lines on the day of futures expiry dates every month on the daily price chart. I have the list of past expiry dates as .csv file for 2011.

I can also manually enter the dates in the AFL if needed so. So, no direct reading from csv is required.

I tried google to find similar AFL and I could not. Please help.

Thanks in Advance
 

john302928

Well-Known Member
#3
Does anyone have this afl. If so please help. Thanks
 

sr114

Well-Known Member
#4
put this code and u will get what u want

Code:
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 )
}
rgds
 

john302928

Well-Known Member
#5
put this code and u will get what u want

Code:
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 )
}
rgds
Hi, Thank you . But it is not displaying any lines for last thursdays. I changed the parameter to "Yes".But still it is not showing. Even I change the color to blue since my background is white. But still no display. Could you please check.

And one more thing, There are sometimes when expiry doesnt happen on thursday and it happens in wednesday or tuesday if the thursday is holiday. So how can i add those dates so that expiry lines are shown correctly.
 

sr114

Well-Known Member
#6
Hi, Thank you . But it is not displaying any lines for last thursdays. I changed the parameter to "Yes".But still it is not showing. Even I change the color to blue since my background is white. But still no display. Could you please check.

And one more thing, There are sometimes when expiry doesnt happen on thursday and it happens in wednesday or tuesday if the thursday is holiday. So how can i add those dates so that expiry lines are shown correctly.
It will display a small circle colored white below the bar having expiry on last Thursday. If u want some other color change the color in the plot statement.

for other than last thursday , as we have in jan 2017 series it was on wednesday, try the logic and put the logic for last wednesday and it will display that also.

rgds
 

john302928

Well-Known Member
#7
I feel it would be simple if i just have all the expiry dates in the afl and it would draw vertical lines for those dates. Kindly help for that.
 
Last edited:
#9
i tried to modify . to get vertical lines on expiry day closing

but nothning comes
please AFL experts help me in this .
_SECTION_BEGIN("Expiry Day");

function IsExpiryDay(dow)
{// -- by mastermind007 - origin IsSelectedDateLastThursday()
DaysinMonth = IIf((Month()==9 OR Month()==4 OR Month()==6 OR Month()==11), 30, IIf(Month()==2, 28 + (Year()%4 == 0 AND Year()%100!=0), 31));
return (DaysinMonth - Day() < 7) AND (DayOfWeek() == dow);
}

LastDay = ParamList("Last Day of the Month", "Mon|Tue|Wed|Thu|Fri", 3);
ColorExpiry = ParamColor("Expiry Color", colorYellow);

switch (LastDay)
{
case "Mon": dow=1; break;
case "Tue": dow=2; break;
case "Wed": dow=3; break;
case "Thu": dow=4; break;
case "Fri": dow=5; break;
}

Color = IIf(IsExpiryDay(dow), ColorExpiry,
IIf(C,colorGreen,
IIf(C, colorRed, colorWhite) ));
Plot( C, "Close", Color , styleNoTitle | styleThick | GetPriceStyle() );
Plot( Color, "Close", colorDefault, styleLine|styleThick );


Plot(C, "Price", colorBlack, styleLine );
Color = Study("SU", GetChartID() );
Color = Study("RE", GetChartID() );
PlotOHLC( Color, Color, Color, Color, "", colorYellow,styleLine );
Mark1 = TimeNum()==Color ;
Mark2 = TimeNum()==Color ;
Plot(mark1,"",12,styleLine|styleThick|styleNoLabel|styleOwnScale,0,1);
Plot(mark2,"",12,styleLine|styleThick|styleNoLabel|styleOwnScale,0,1);
_SECTION_END();
 

Similar threads