// by trash, vers.1.5
RequestTimedRefresh( 1 );
procedure SayNotTooOften( text, Minperiod )
{ // by Tomasz Janeczko
elapsed = GetPerformanceCounter() / 1000;
Lastelapsed = Nz( StaticVarGet( "lastsaytime" ) );
if ( elapsed - Lastelapsed > Minperiod )
{
StaticVarSet( "lastsaytime" , elapsed );
Say( text );
}
}
procedure GFXBlinkingMsg( Msg, x1, y1, x2, y2, TextColor, FontSize, FontName )
{
// originally by Herman van den Bergen, edited by trash
global FontName;
local BlinkState, textcolor, fontSize, msg;
BlinkState = GetPerformanceCounter() - Nz( StaticVarGet( "~BlinkState" ) );
if ( BlinkState / 1000 > 2 )
{
StaticVarSet( "~BlinkState", GetPerformanceCounter( 1 ) ) ;
}
else
{
GfxSetBkMode( 1 );
GfxSelectFont( FontName, FontSize, 700 );
GfxSetTextColor( TextColor );
GfxDrawText( Msg, x1, y1, x2, y2, 37 );
}
}
SDswitch = ParamToggle( "Supply/Demand Zones", "OFF|ON", 1 );
MTFswitch = ParamList( "Multi TF Support", "OFF|Intra-day|EOD", 0 );
intratmfrm = Param( "Input Intra-day TF of S/D Zones (minutes)", 60, 1, 1440, 1 ) * 60;
EODmode = ParamList( "Choose EOD TF of S/D Zones", "Daily|Weekly|Monthly", 0 );
SDmode = ParamList( "Supply/Demand Mode", "Small|Large|Extra Large", 0 );
Sensitivity = Param( "Sensitivity (%)", 0.4, 0.1, 10, 0.1 );
NumZones = Param( "Number of S/D Zones", 10, 2, 60, 2 ) / 2;
style1 = ParamStyle( "Style 1", styleNoLabel | styleNoRescale ) | styleCloud;
style2 = ParamStyle( "Style 2", styleNoLabel | styleNoRescale | styleThick );
ColorDem = ParamColor( "Blend Color - Demand Zones", colorBlueGrey );
ColFacDem = Param( "Blend Color Factor - Demand Zones", 0.65, 0, 2, 0.01 );
ColorSup = ParamColor( "Blend Color - Supply Zones", colorDarkRed );
ColFacSup = Param( "Blend Color Factor - Supply Zones", 0.65, 0, 2, 0.01 );
Colorline = ParamColor( "Color - Zone Borders", colorGrey50 );
switch( EODmode )
{
case "Weekly": eodtmfrm = inWeekly; break;
case "Monthly": eodtmfrm = inMonthly; break;
default: eodtmfrm = inDaily; break;
}
expandmode = expandFirst;
shift = 0;
switch ( MTFswitch )
{
case "Intra-day":
Close_ = TimeFrameGetPrice( "C", intratmfrm, shift, expandmode );
Open_ = TimeFrameGetPrice( "O", intratmfrm, shift, expandmode );
High_ = TimeFrameGetPrice( "H", intratmfrm, shift, expandmode );
Low_ = TimeFrameGetPrice( "L", intratmfrm, shift, expandmode );
break;
case "EOD":
Close_ = TimeFrameGetPrice( "C", eodtmfrm, shift, expandmode );
Open_ = TimeFrameGetPrice( "O", eodtmfrm, shift, expandmode );
High_ = TimeFrameGetPrice( "H", eodtmfrm, shift, expandmode );
Low_ = TimeFrameGetPrice( "L", eodtmfrm, shift, expandmode );
break;
default:
Close_ = C;
Open_ = O;
High_ = H;
Low_ = L;
break;
}
bi = BarIndex();
selectedBI = SelectedValue( bi );
selectedC = SelectedValue( Close_ );
MinVal = Min( Open_, Close_ );
MaxVal = Max( Open_, Close_ );
if ( selectedC != LastValue( C ) )
{
SayNotTooOften( "Viewing historical Supply Demand zones", 30 );
pxcw = Status( "pxchartwidth" );
pxcb = Status( "pxchartbottom" );
x1 = pxcw / 2;
y1 = pxcb;
GFXBlinkingMsg( "Currently viewing historical Supply/Demand zones!", x1 - 300, y1 - 10, x1 + 300, y1 - 30, colorRed, 12, "Helvetica" );
}
switch( SDmode )
{
case "Large":
ValSup = MinVal;
ValDem = MaxVal;
break;
case "Extra Large":
ValSup = Low_;
ValDem = High_;
break;
default:
ValSup = MaxVal;
ValDem = MinVal;
break;
}
for ( i = 1; i <= NumZones; i++ )
{
x1 = selectedBI - SelectedValue( PeakBars( High_, Sensitivity, i ) );
y1 = SelectedValue( Peak( High_, Sensitivity, i ) );
y2 = ValueWhen( bi == x1, High_ - Valsup );
Line1 = LineArray( x1 + 1, y1, selectedBI, y1, 1 );
Line2 = Line1 - y2;
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
x2 = selectedBI - SelectedValue( TroughBars( Low_, Sensitivity, i ) );
y3 = SelectedValue( Trough( Low_, Sensitivity, i ) );
y4 = ValueWhen( bi == x2, ValDem - Low_ );
Line3 = LineArray( x2 + 1, y3, selectedBI, y3, 1 );
Line4 = Line3 + y4;
//::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
i_1 = 20 * i;
i_2 = 25 + ( i - 1 ) * 10;
Rcolor_ = ColorBlend( ColorSup, ColorRGB( 180, i_1, i_1 ), ColFacSup ); // ParamColor( "Supply Color", colorBrown );
Scolor_ = ColorBlend( ColorDem, ColorRGB( i_2, i_2, 80 + i_1 ), ColFacDem ); // ParamColor( "Demand Color", colorGreen );
RColor = IIf( selectedC > Line1, Scolor_, Rcolor_ );
SColor = IIf( selectedC > Line4, Scolor_, Rcolor_ );
if ( SDSwitch )
{
zorder = -i - 9;
zorder2 = zorder + 1;
PlotOHLC( Line1, Line1, Line2, Line2, "", Rcolor, style1, 0, 1, 0, zorder );
Plot( Line1, "", Colorline, style2, 0, 1, 0, zorder2 );
Plot( Line2, "", Colorline, style2, 0, 1, 0, zorder2 );
PlotOHLC( Line3, Line3, Line4, Line4, "", Scolor, style1, 0, 1, 0, zorder );
Plot( Line3, "", Colorline, style2, 0, 1, 0, zorder2 );
Plot( Line4, "", Colorline, style2, 0, 1, 0, zorder2 );
}
}