_SECTION_BEGIN( "Confluence" );
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Volume Zone Oscillator/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
//Volume Zone Oscillator
C1=C;
V1=V;
period=Param("LookBack",14,2,999,1,0);
R= IIf (C1>Ref(C1,-1), V1,-V1);
VP= EMA (R, period);
TV=EMA (V, period);
VZO= 100*(VP/TV);
//Plot(VZO,"",colorOrange,4);
//Plot(60,"",colorPaleBlue,styleLine);
//Plot(40,"",colorPaleBlue,styleLine);
//Plot(0,"",colorDefault,styleDashed);
//Plot(-60,"",colorPaleBlue,styleLine);
//Plot(-40,"",colorPaleBlue,styleLine);
//PlotOHLC(Null,60,40,Null,"",colorDarkGreen);//Removed stylecloud
//PlotOHLC(Null,-60,-40,Null,"",colorDarkRed); //Removed styleCloud
///////////////////////////////buy/sell///////////////////////
//zerochkbuy = IIf(Cross(0,Ref(VZO,-1)) AND Cross(VZO,0),True,False);
//zerochksell = IIf(Cross(Ref(VZO,-1),0)AND Cross(0,VZO),True,False);
//Buy=Cross(VZO,-40) OR zerochkbuy;Sell=Cross(40,VZO) OR zerochksell ;
Buy1=Cross(VZO,-40) OR Cross(VZO,0);
Sell1=Cross(40,VZO) OR Cross(0,VZO);
//Buy = ExRem( Buy, Sell );
//Sell = ExRem( Sell, Buy );
/////////////////////////shapes ///////////////////////////////
//shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
//PlotShapes( shape, IIf( Buy, colorBrightGreen, colorRed ),0, IIf( Buy,VZO,VZO) );
/////////////////////////exploration ///////////////////////////////
//Filter=Buy OR Sell;
//AddColumn( IIf(Buy,1,IIf(Sell,-1,Null)) ,"B/S",1.0,colorWhite,IIf(Buy,colorGreen,IIf(Sell,colorRed,Null)),60);
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////Volume Zone Oscillator/////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////SuperTrend ATR System///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
Factor = Param( "Factor", 1, 1, 10, 0.1 );
Pd = Param( "ATR Periods", 5, 1, 100, 1 );
Up = ( H + L ) / 2 + ( Factor * ATR( Pd ) );
Dn = ( H + L ) / 2 - ( Factor * ATR( Pd ) );
iATR = ATR( Pd );
TrendUp = TrendDown = Null;
trend[0] = 1;
changeOfTrend = 0;
flag = flagh = 0;
for ( i = 1; i < BarCount - 1; i++ )
{
TrendUp[i] = Null;
TrendDown[i] = Null;
trend[i] = 1;
if ( Close[i] > Up[i-1] )
{
trend[i] = 1;
if ( trend[i-1] == -1 )
changeOfTrend = 1;
}
else
if ( Close[i] < Dn[i-1] )
{
trend[i] = -1;
if ( trend[i-1] == 1 )
changeOfTrend = 1;
}
else
if ( trend[i-1] == 1 )
{
trend[i] = 1;
changeOfTrend = 0;
}
else
if ( trend[i-1] == -1 )
{
trend[i] = -1;
changeOfTrend = 0;
}
if ( trend[i] < 0 && trend[i-1] > 0 )
{
flag = 1;
}
else
{
flag = 0;
}
if ( trend[i] > 0 && trend[i-1] < 0 )
{
flagh = 1;
}
else
{
flagh = 0;
}
if ( trend[i] > 0 && Dn[i] < Dn[i-1] )
{
Dn[i] = Dn[i-1];
}
if ( trend[i] < 0 && Up[i] > Up[i-1] )
{
Up[i] = Up[i-1];
}
if ( flag == 1 )
{
Up[i] = ( H[i] + L[i] ) / 2 + ( Factor * iATR[i] );;
}
if ( flagh == 1 )
{
Dn[i] = ( H[i] + L[i] ) / 2 - ( Factor * iATR[i] );;
}
if ( trend[i] == 1 )
{
TrendUp[i] = Dn[i];
if ( changeOfTrend == 1 )
{
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}
else
if ( trend[i] == -1 )
{
TrendDown[i] = Up[i];
if ( changeOfTrend == 1 )
{
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}
// Plot( TrendUp, "Trend", colorBrightGreen , styleNoRescale);
// Plot( TrendDown, "Down", colorRed , styleNoRescale);
//////////////////////////////SuperTrend BUY CONDITIONS///////////////////////////////////////////////////////////
Buy2 = IIf(trend == 1,1,0);
//////////////////////////////SuperTrend SELL CONDITIONS////////////////////////////////////
Sell2 = IIf(trend == -1,1,0);
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////VWAP CALCULATIONS////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////
starttime = 093000;
endtime = 160000;
timeWindow = TimeNum() >= starttime AND TimeNum() <= endtime;
firstBarOfDay = TimeNum() >= starttime ;
firstBarOfDay = firstBarOfDay - Ref(firstBarOfDay,-1);
P = (H + L)/2;
vv = V * P * timeWindow;
BarsInDay = (1 + BarsSince(firstBarOfDay)) * timeWindow;
CumVolumeInDay = Sum(V,BarsInDay);
VWAP = Sum(vv, BarsInDay ) / CumVolumeInDay;
SV = Sum((P - VWAP)^2,BarsInDay) / BarsInDay; // sample variance
SD = sqrt(SV); // standard deviation
period = ParamList( "What period?", "Daily|Weekly|Monthly", 0 );
switch ( period )
{
case "Daily":
newPeriod = Day() != Ref( Day(), -1 );
break;
case "Weekly":
newPeriod = DayOfWeek() == 0 AND Ref( DayOfWeek(), -1 ) != 0;
break;
case "Monthly":
newPeriod = Month() != Ref( Month(), -1 );
break;
}
//////////////////////////////VWAP BUY CONDITIONS///////////////////////////////////////////////////////////
Buy3 = Ref(C,-1) > VWAP ;
//////////////////////////////VWAP SELL CONDITIONS///////////////////////////////////////////////////////////
Sell3 = Ref(C,-1) < VWAP ;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////Buy Sell Logic///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
Buy = (ValueWhen(Buy1,Buy1)==1 AND ValueWhen(Buy2,Buy2)==1 AND ValueWhen(Buy3,Buy3)==1) AND (ValueWhen(Sell1,Sell1) ==0 AND ValueWhen(Sell2,Sell2) == 0 AND ValueWhen(Sell3,Sell3) ==0);
Sell = (ValueWhen(Sell1,Sell1)==1 AND ValueWhen(Sell2,Sell2)==1 AND ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1) == 0 AND ValueWhen(Buy2,Buy2) ==0 AND ValueWhen(Buy3,Buy3) ==0);
sideways = ((ValueWhen(Buy1,Buy1)==1 AND ValueWhen(Buy2,Buy2)==1 AND ValueWhen(Buy3,Buy3)==1) AND (ValueWhen(Sell1,Sell1)==1 OR ValueWhen(Sell2,Sell2)==1 OR ValueWhen(Sell3,Sell3) ==1))
OR ((ValueWhen(Sell1,Sell1)==1 AND ValueWhen(Sell2,Sell2)==1 AND ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)==1 OR ValueWhen(Buy2,Buy2)==1 OR ValueWhen(Buy3,Buy3) ==1))
OR ((ValueWhen(Sell1,Sell1) ==1 OR ValueWhen(Sell2,Sell2)==1 OR ValueWhen(Sell3,Sell3)==1) AND (ValueWhen(Buy1,Buy1)==1 OR ValueWhen(Buy2,Buy2) OR ValueWhen(Buy3,Buy3) ==1));
//Buy = (LastValue(Buy1)==1 AND LastValue(Buy2)==1 AND LastValue(Buy3)==1) AND (LastValue(Sell1) ==0 AND LastValue(Sell2) == 0 AND LastValue(Sell3) ==0);
//Sell = (LastValue(Sell1)==1 AND LastValue(Sell2)==1 AND LastValue(Sell3)==1) AND (LastValue(Buy1) == 0 AND LastValue(Buy2) ==0 AND LastValue(Buy3) ==0);
//sideways = ((LastValue(Buy1)==1 AND LastValue(Buy2)==1 AND LastValue(Buy3)==1) AND (LastValue(Sell1)==1 OR LastValue(Sell2)==1 OR LastValue(Sell3) ==1))
// OR ((LastValue(Sell1)==1 AND LastValue(Sell2)==1 AND LastValue(Sell3)==1) AND (LastValue(Buy1)==1 OR LastValue(Buy2)==1 OR LastValue(Buy3) ==1))
//OR ((LastValue(Sell1) ==1 OR LastValue(Sell2)==1 OR LastValue(Sell3)==1) AND (LastValue(Buy1)==1 OR LastValue(Buy2) OR LastValue(Buy3) ==1));
//Buy = (LastValue(VWAPbuyflag)==LastValue(vzobuyflag)==LastValue(SupTbuyflag)==1) AND (LastValue(VWAPsellflag) == LastValue(vzosellflag) == LastValue(SupTsellflag) ==0);
//Sell = (LastValue(VWAPsellflag)==LastValue(vzosellflag)==LastValue(SupTsellflag)==1) AND (LastValue(VWAPbuyflag) == LastValue(vzobuyflag) == LastValue(SupTbuyflag) ==0);
//sideways = ((LastValue(VWAPbuyflag)==LastValue(vzobuyflag)==LastValue(SupTbuyflag)==1) AND (LastValue(VWAPsellflag) | LastValue(vzosellflag) | LastValue(SupTsellflag) ==1))
// OR ((LastValue(VWAPsellflag)==LastValue(vzosellflag)==LastValue(SupTsellflag)==1) AND (LastValue(VWAPbuyflag) | LastValue(vzobuyflag) | LastValue(SupTbuyflag) ==1))
// OR ((LastValue(VWAPsellflag) | LastValue(vzosellflag) | LastValue(SupTsellflag)==1) AND (LastValue(VWAPbuyflag) | LastValue(vzobuyflag) | LastValue(SupTbuyflag) ==1));
///////////////////////////////////////////////////////////////////////////////////////////////////////
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
//Buy = Flip( Buy, Sell );
//Sell = Flip(Sell,Buy);
///////////////////////////////////////////////////////////////////////////////////////////////////////
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, L, Offset = -12 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -12 );
AlertIf( Buy, "SOUND C:\\Program Files (x86)\\AmiBroker\\Sound Alerts\\alert1.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Program Files (x86)\\AmiBroker\\Sound Alerts\\alert1.wav", "Audio alert", 2 );
Filter = Buy OR Sell;
//if(Candletype)
//{
//SetBarFillColor( IIf ( (Sell) AND (!sideways),colorRed,colorBrightGreen));
//Plot(C,"Price", IIf ( (Hlv == -1 && Hlv !=1 && Hlv !=0) AND NOT(Hlv == 1 && Hlv !=-1 && Hlv !=0),colorRed,colorBrightGreen),styleCandle);
//}
//else
//{
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
//}
_SECTION_END();