Calling all AFL Experts!!

throwawayacc123

Well-Known Member
#1
Hi,

My requirement is to plot a simple horizontal THIN line(less distracting) for previous day's MCX morning sessions High lows and evening sessions high lows and current days morning sessions high lows when evening session starts.

I have started with the AFL, but 4hr doesn't display the levels correctly. May be some AFL expert can help fix this.

Thanks.

Code:
/* Indicator will plot Previous day Session highs and lows and current day session morning session. 
MCX Morning session - 10 a.m to 5 p.m
MCX Evening session - 5 p.m to 11.30/11.55 p.m

For current day we plot only morning session , as this helps to trade during evening sessions. 

BUGS : 
  12/6/2014 : Issue with 4h TF - Session hi/lo don't show correctly. 1H and 2H Timeframe shows hi/lo correctly. 


TODO:
 - Plot Previous day Morning & Evening Session Hi/lo.
*/

function plotSessionHiLo( MorningSession, EveningSession , color )
{
 PlotGrid(MorningSession, colorYellow);
 PlotGrid(EveningSession, colorYellow);
}


//get todays morning session
isCurrentDay = 0;
isPreviousDay = 0;
isTodayMorningSession = 0;
isTodayEveningSession = 0;

isCurrentDay = IIf( DateNum() == LastValue(DateNum(),1) ,1,0); //check if current day
isPreviousDay = IIf( DateNum()-1 == LastValue(DateNum()-1,1) ,1,0);; // check for previous day

printf("\n Current day = %f",isCurrentDay);
printf("\n isPreviousDay day = %f",isPreviousDay);

MorningSessionTR = TimeNum() >= 100000 AND TimeNum() <= 170000;  //  Morning Session 
EveningSessionTR = TimeNum() >= 170000 AND TimeNum() <= 235900;  //  Evening Session
isTodayMorningSession = IIf(isCurrentDay AND MorningSessionTR AND NOT EveningSessionTR ,1,0);
isTodayEveningSession = IIf(isCurrentDay AND NOT MorningSessionTR AND EveningSessionTR ,1,0);
printf("\n isTodayMorningSession = %f",isTodayMorningSession);
printf("\n isTodayEveningSession = %f",isTodayEveningSession);

//Get Current day morning Session H/L
aCurrentDayMorningHighs = IIf(isTodayMorningSession  , H, Null);
aCurrentDayMorningLows = IIf(isTodayMorningSession , L, 1000000);

// if evening session , then plot the current day morning session H/L
if (LastValue(isTodayEveningSession,1)) 
{

  printf("\n Plotting MorningSession H/L...");
 morningSessionHi = LastValue( Highest( TimeFrameExpand(aCurrentDayMorningHighs,inHourly,expandfirst)) , 1 );
 morningSessionLo = LastValue( Lowest(aCurrentDayMorningLows) , 1 );
  printf("\n Morning Hi = %f",morningSessionHi);
  printf("\n Morning Lo = %f",morningSessionLo);
  plotSessionHiLo(morningSessionHi,morningSessionLo,colorYellow);

  
}





// Get Previous day Morning & Evening Session H/L
// how to get previous day morning high lows and evening high lows?
 
Last edited:

yusi

Well-Known Member
#5
My requirement is to plot a simple horizontal THIN line(less distracting) for previous day's MCX morning sessions High lows and evening sessions high lows and current days morning sessions high lows when evening session starts.
Not my forte, but if it helps take this a step forward

Code:
// Ms is Morning Session, Es is Evening Session

IsMsBar = TimeNum() >= 100000 AND TimeNum() <= 170000;
IsEsBar = NOT IsMsBar;

IsFirstMsBar = ExRem(IsMsBar, IsEsBar);
IsFirstEsBar = ExRem(IsEsBar, IsMsBar);

HighMs = High * IsMsBar;
HighestMs = HighestSince(IsFirstMsBar, HighMs) * IsEsBar;

HighEs = High * IsEsBar;
HighestEs = HighestSince(IsFirstEsBar, HighEs) * IsMsBar;

HighestPrevDayMs = Ref(HighestMs, -1);
HighestPrevDayMs = AMA2(HighestPrevDayMs, IsFirstMsBar, NOT IsFirstMsBar);

HighestPrevDayEs = Ref(HighestEs, -1);
HighestPrevDayEs = AMA2(HighestPrevDayEs, IsFirstEsBar, NOT IsFirstEsBar);


/* 
Will leave the low code, as well as the plot, to the way it suits you.

Ami settings of Align minute bars, and First / Last time stamp may affect results
*/
 

throwawayacc123

Well-Known Member
#7
Thanks Yusi.

Is there any way to plot the lines using the thickness of gridlines. Similar to plotGrid function.

Plot function doesn't let me control the thickness of the lines drawn. default thickness is 1 , but i want it less than that.

Plotgrid does the job , but doesn't take array or allow me to plot in a range like plot function does. :(
 

Similar threads