Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Market Profile
Author/Uploader: noname -
Date/Time added: 2008-06-21 18:19:40
Origin:
Keywords:
Level: basic
Flags: indicator

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Market Profile with Low-level graphics

Formula:

SetChartOptions(3, chartShowDates);
GfxSetOverlayMode( mode = 1 );

nn = StrToNum(ParamList("Days", "1|2|3", 1));
box = Param("step", 10, 1, 100, 1)*TickSize;

NewDay = Day()!= Ref(Day(), -1);
DH = LastValue(HighestSince(NewDay, H, nn));
DL = LastValue(LowestSince(NewDay, L, nn));
Range = DH - DL;
steps = ceil(Range/box);								// linage
height = Status("pxheight") - 50;					// width of the profile (indention
overhand 30 from below 20 pixels)
boxheight = LastValue(height/steps);			// size of the box

width = (Status("pxwidth")-110)/3;				// offset of the profiles

bars = Highest(BarsSince(NewDay));
ColorStep = LastValue(185/bars);

// закрываем внутридневные гэпы
L = IIf(C > Ref(C, -1) AND L > Ref(C, - 1) AND NOT NewDay, Ref(C, -1), L);
H = IIf(C < Ref(C, -1) AND H < Ref(C, - 1) AND NOT NewDay, Ref(C, -1), H);

function GetDayPrice( fild, shift)
{
	DayPrice = LastValue(TimeFrameGetPrice(fild, inDaily, -shift));
	return DayPrice;
}

function pixlev(price)
{
	result = 30 + (DH - price)/box * boxheight;
	return result;
}

procedure PlotProfile(DH, DL, begini, endi, disp)
{
	m = 0;
	for(j = DH; j > DL; j = j-box)
	{
		n = 0;
		for(i = begini; i < endi; i++)
		{
			if(H[i] >= j AND L[i] <= j)
			{
				GfxSelectPen( colorBlack, 1, 0);
				GfxSelectSolidBrush(ColorHSB((i-begini)*ColorStep, 255, 255));
				GfxRectangle( disp+n*boxheight, 30+m*boxheight, disp+(n+1)*boxheight,
30+(m+1)*boxheight);
				n++;
			}
		}
		m++;
	}
}

procedure PlotLine(x1, y1, x2, y2, Color)
{
	GfxSelectPen(Color, 1, 0);
	GfxPolyline( x1, y1, x2, y2);
}

procedure PlotRect(x1, y1, x2, y2, Color)
{
	GfxSelectPen(Color, 0, 5);
	GfxSelectSolidBrush(Color);
	GfxRectangle(x1, y1, x2, y2);
}

procedure PlotPrice(Text, FontName, FontSize, Color, x, y, yAlign, xAlign)
{
	GfxSetBkMode(1);
	GfxSetTextColor(Color);
	GfxSetTextAlign( xAlign|yAlign);
	GfxSelectFont(FontName, FontSize, 600);  // dont work orientation 
	GfxTextOut(Text, x, y);
}

for(q = nn; q > 0; q--)
{ 
	begini = LastValue(ValueWhen(NewDay, BarIndex(), q));
	endi = LastValue(IIf(q == 1, BarCount, ValueWhen(NewDay, BarIndex(), q-1)));
	PlotRect(50 + width*(nn-q), pixlev(GetDayPrice("H", q-1)),							// day range
		50 + width*(nn-q+1), pixlev(GetDayPrice("L", q-1)), colorLightYellow);
	PlotRect(50 + width*(nn-q), pixlev(GetDayPrice("O", q-1)),							// open-close
range
		50 + width*(nn-q+1), pixlev(GetDayPrice("C", q-1)), 
		IIf(GetDayPrice("O", q-1) > GetDayPrice("C", q-1), ColorHSB(15, 40, 255), 
		ColorHSB(80, 40, 255)));
	PlotLine(50 + width*(nn-q), pixlev(GetDayPrice("C", q-1)),							// close
line
		50 + width*(nn-q+1), pixlev(GetDayPrice("C", q-1)), 
		IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), colorRed, colorGreen));
	PlotProfile(DH, DL, begini, endi, 50 + width*(nn-q));
	PlotLine(50 + width*(nn-q), height+40, 50 + width*(nn-q), 0, colorBlack);	//
vertical line
	PlotPrice( " close  " + NumToStr(GetDayPrice("C", q-1))+" ", "Tahoma", 10,	//
plot close price 
		IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), colorRed, colorGreen), 
		50+width*(nn-q+1), pixlev(GetDayPrice("C", q-1)), 
		IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), 0, 8), 2);
	PlotPrice( " open  " + NumToStr(GetDayPrice("O", q-1))+" ", "Tahoma", 10,	//
plot open price
		colorBlack, 50+width*(nn-q+1), pixlev(GetDayPrice("O", q-1)), 
		IIf( GetDayPrice("O", q-1) > GetDayPrice("C", q-1), 8, 0), 2);
	PlotPrice( " "+NumToStr(GetDayPrice("H", q-1)), "Tahoma", 10, 						// plot
high price
		colorBlack, 50+width*(nn-q), pixlev(GetDayPrice("H", q-1)), 8, 0);
	PlotPrice(" "+NumToStr(GetDayPrice("L", q-1)), "Tahoma", 10,						// plot low
price
		colorBlack, 50+width*(nn-q), pixlev(GetDayPrice("L", q-1)), 0, 0);
}

Comments:

123

2008-06-21 20:56:16
GfxSetOverlayMode( mode = 1 );

??????????????????????????
Thomas

2008-06-22 19:12:54
mode declared but not used.
Could be reserved for further used OR
Author did not notice to remove or forgot to remove after few round of script modifications.

No issue. case closed.



Eitan

2008-06-25 14:19:53
I get an error on line 59:
GfxPolyline( x1, y1, x2, y2);

"Number of arguments must be even"

I am using 5.12 beta, I also checked it with 5.10

Eitan

2008-06-25 14:26:15
I get an error on line 59:
GfxPolyline( x1, y1, x2, y2);

"Number of arguments must be even"

I am using 5.12 beta, I also checked it with 5.10

Eitan

2008-06-25 14:26:25
I get an error on line 59:
GfxPolyline( x1, y1, x2, y2);

"Number of arguments must be even"

I am using 5.12 beta, I also checked it with 5.10

Hommy

2008-06-26 11:19:27
I've got the same error message. Is this formula working? Do you have another Market Profile AFL?
AFL in this library didn't show sufficient MP information.
noname

2008-06-26 11:38:59
define per-symbol tick size in the Symbol->Information page
Hommy
homm3r [at] gmail. com
2008-06-29 07:33:17
Hi, Noname, you formula is perfect, thanks!
I have an old complete MP formula+scan (not mine) but didn't work on 5,1 version. Can I share this to you?
Martius

2008-06-29 14:49:13
to Hommy: Did you solve the problem with that error on line 59? I have ver. 5.1. Thanks. M.
Thomas

2008-06-29 21:11:25
Hi Hommy,


There are more problem than just error on line 59. Please solve it
Hommy

2008-06-30 14:51:11
Hi Friends, as Noname said "define per-symbol tick size in the Symbol->Information page". Tick size=1. No problem at all :)
reinsley

2009-02-21 11:59:22
The code to add Y axis :

Modify the first line of Market Profile
SetChartOptions( 0);//3 , chartShowDates );

and add the following at the end.

gridINCR = box;
GridMAX = DH + gridINCR ;
GridMIN = DL - gridINCR ;

steps = ( GridMAX - GridMIN ) / gridINCR ;

SetChartOptions( 1, 0, 0, GridMIN, GridMAX );

for ( i = 0;i < steps;i++ )
//Plot(GridMIN+i*gridINCR, \\\"\\\",ParamColor(\\\"color\\\", colorBlack ),
styleNoTitle | ParamStyle(\\\"style\\\", styleLine | styleNoLabel,
maskHistogram ) );//solid
PlotGrid( GridMIN + i*gridINCR, colorBlack );// dash






Caveat : The new Y scale and the MP scale are not quite the same.
A tiny difference, between one or two ticks, but I cannot find why.
I have to fully understand the gfx mode, I suppose.

I am very close to the solution, if a few passers-by could bring some
light, I will appreciate.
Anil Chawla
anilchawla59 [at] yahoo.co.in
2009-03-17 12:00:54
Hi Reinsley, your addition gives error of too many arguments and syntax error as well. It would be nice to correct it and paste again.


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM