// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("DeMarker Indicator");
// Last edited: VIMALRAJ (vimal.raaj@yahoo.com) on 17/07/2015
// The DeMarker indicator is an attempt to overcome the shortcomings of classical overbought / oversold indicators. 
// The DeMarker Indicator identifies potential price bottoms and tops. 
// It accomplishes this by making price comparisons from one bar to the next and measuring the level of price demand. 
// DeMarker should be interpreted as other overbought / oversold indicators such as RSI with the levels of 30 and 70. 
// Compared to RSI it is smoother but still able to detect tops and bottoms a little bit better.
// For more information please check AmiBroker Tips newsletter http://www.amibroker.com/newsletter/02-2000.html

dmPeriods 			= Param( "Periods", 13, 1, 200, 1 );
dmColor				= ParamColor( "Color", colorBlueGrey );
dmStyle				= ParamStyle( "Style", styleLine );
plotLevels			= ParamToggle( "Plot OB/OS Levels", "No|Yes", 1 );
dmOverBoughtLevel 	= Param( "Over Bought Level", 80, 50, 100 );
dmOverSoldLevel 	= Param( "Over Sold Level", 20, 0, 50 );
dmOverBoughtColor	= ParamColor( "OB Level Color", colorRed );
dmOverSoldColor		= ParamColor( "OS Level Color", colorGreen );

DeMax = IIf( H > Ref( H, -1 ), H - Ref( H, - 1), 0 );
DeMin = IIf( L < Ref( L, -1 ), Ref( L, - 1 ) - L, 0 );
DeMarker = 100 *  Sum( DeMax, dmPeriods )/( Sum( DeMax, dmPeriods ) + Sum( DeMin, dmPeriods ) );

Plot( DeMarker, "DeMarker", dmColor, dmStyle );
if( plotLevels ) {
	PlotGrid( dmOverBoughtLevel, dmOverBoughtColor );
	PlotGrid( dmOverSoldLevel, dmOverSoldColor );
}
_SECTION_END();