//VWAP CODE - updated
SetChartOptions(2,chartWrapTitle);
SetChartBkColor(ParamColor("Background", colorLightGrey)) ;
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email protected]
//
/*
The VWAP for a stock is calculated by adding the dollars traded for every
transaction in that stock ("price" x "number of
shares traded") and dividing the total shares traded. A VWAP is computed
from the Open of the market to the market Close, AND is
calculated by Volume weighting all transactions during this time period
*/
Layer = Param("Layer", 0, -5, 5, 1) ;
showprice = ParamToggle("Show Price", "No|Yes", 0) ;
if (showprice)
{
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} " + EncodeColor( colorGreen ) + " Open %g," + EncodeColor( colorBlue ) + " Hi %g, " + EncodeColor( colorRed ) + " Lo %g, " + EncodeColor( colorBlack ) + " Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", colorBlack, styleNoTitle | styleCandle,0,0,0,Layer );
//Peaking Volumes
HiVolume = IIf(V > (2 * MA(V,10)), True, False);
PlotShapes(shapeSmallCircle * HiVolume, IIf(C > O, colorBlack, colorWhite), 0, (O+C)/2, 0);
ToolTip = "Open = " + O + "\nHigh = " + H + "\nLow = " + L + "\nClose = " + C ;
}
SetChartBkColor(colorLightGrey) ;
turnvwapoff = ParamToggle("VWAP All OFF", "No|Yes", 0) ;
showintitle = ParamToggle("Show in Title", "No|Yes", 0) ;
Filterdaych = ParamToggle("Filter Day Change Connections", "No|Yes", 1) ;
Vwapmode = ParamList("VWAP mode", "As Per Param|Only VWAP|VWAP+SD|VWAP+2SD", 0) ;
showvwap = ParamToggle("Show VWAP", "No|Yes", 1) ;
showvwap1sd = ParamToggle("Show VWAP 1SD", "No|Yes", 1) ;
showvwap2sd = ParamToggle("Show VWAP 2SD", "No|Yes", 1) ;
showvwap3sd = ParamToggle("Show VWAP 3SD", "No|Yes", 0) ;
showvwapband = ParamToggle("Show VWAP Trend Bands", "No|Yes", 0) ;
showvwapswband = ParamToggle("Show VWAP Sideways Bands", "No|Yes", 1) ;
showprevdayvals = ParamToggle("Show Prev Day Values", "No|Yes", 1) ;
showprev2dayvals = ParamToggle("Show Prev 2 Day Values", "No|Yes", 1) ;
showprevdayband = ParamToggle("Show Prev Day Bands", "No|Yes", 1) ;
showextprevday = ParamToggle("Show Extension", "No|Yes", 1) ;
showextbandprevday = ParamToggle("Show Extension Band", "No|Yes", 1) ;
extend = Param("Extend", 10, 0, 100, 1) ;
Vwaplayer = Param("VWAP Layer", -3, -5, 5, 1) ;
extlayer = Param("Extend Layer", -2, -5, 5, 1) ;
MAwidthper = Param("MA Width %", 0.005, 0, 10, 1) ;
SDwidthper = Param("SD Width %", 0.005, 0, 10, 1) ;
MAwidth = SelectedValue(C) * MAwidthper /100 ;
SDwidth = SelectedValue(C) * SDwidthper /100 ;
showtradearr = ParamToggle("Trade Arrow", "No|Yes", 1) ;
showtext = ParamToggle("Show Text", "No|Yes", 1) ;
Clrtext = ParamColor("Color Text", colorBlack) ;
showvahvaltext = ParamToggle("Show VAH-VAL Text", "No|Yes", 1) ;
Onlyvwap = False ;
withsd = False ;
with2sd = False ;
switch (Vwapmode)
{
// case "As Per Param":
// break ;
case "Only VWAP" :
Onlyvwap = True ;
break ;
case "VWAP+SD" :
Onlyvwap = True ;
withsd = True;
break ;
case "VWAP+2SD" :
Onlyvwap = True ;
withsd = True;
with2sd = True;
break ;
}
if (Onlyvwap)
{
if (withsd)
showvwap1sd = True;
else
showvwap1sd = False ;
if (with2sd)
showvwap2sd = True;
else
showvwap2sd = False ;
showvwap3sd = False ;
showvwapband = False ;
showvwapswband = False ;
showprevdayvals = False ;
showprev2dayvals = False ;
showprevdayband = False ;
showvwapband = False ;
// showtradearr = False ;
showcomm = False ;
showtext = withsd ;
}
stylelabel = 0 ;
if (showtext)
stylelabel = styleNoLabel ;
styletitle = 0 ;
if (NOT showintitle)
styletitle = styleNoTitle ;
if (NOT turnvwapoff)
{
P = (H + L + C) / 3;
nd = Day() != Ref(Day(),-1) ;
Bars_so_far_today = 1 + BarsSince( nd);
TodayVolume = Sum(V,Bars_so_far_today);
CumV = Sum(V,Bars_so_far_today);
CumVWP = Sum (P * V, Bars_so_far_today );
VWAP = CumVWP / CumV;
VWAPsd = IIf(Ref(nd, 1), 0, VWAP);
CumVsd = IIf(Ref(nd, 1), 0, CumV);
S = Sum(Ref(CumVsd, -1) * V * (P - Ref(VWAPsd, -1))^2 / CumV,Bars_so_far_today);
Variance = S / CumV;
SD = sqrt(Variance);
Vwapm1 = VWAP - SD ;
Vwapp1 = VWAP + SD ;
Vwapm2 = VWAP -2*SD ;
Vwapp2 = VWAP +2*SD ;
Vwapm3 = VWAP -3*SD ;
Vwapp3 = VWAP +3*SD ;
dt = DateTime() ;
dtnum = DateTimeConvert(0, dt) ;
newdt = dtnum != Ref(dtnum, -1) ;
Lastbar = H-H ;
if (Filterdaych)
Lastbar = dtnum != Ref(dtnum, 1) ;
RefVWAP = VWAP;
RefVwapm1 = Vwapm1;
RefVwapp1 = Vwapp1 ;
RefVwapm2 = Vwapm2;
RefVwapp2 = Vwapp2;
RefVwapm3 = Vwapm3;
RefVwapp3 = Vwapp3;
Clrvwap = ParamColor("Color VWAP",colorBlack) ;
Clrvwapm1 = ParamColor("Color VWAP -1SD", colorGreen) ;
Clrvwapp1 = ParamColor("Color VWAP +1SD", colorRed) ;
strnday = "day";
if (showvwap)
{
// Vwapstyle = 0 ;
// if (ndays > 1)
Vwapstyle = styleNoRescale ;
Plot(IIf(Lastbar, Null, RefVWAP), "VWAP"+strnday, Clrvwap , styleThick|stylelabel|Vwapstyle, Null, Null, 0, 1);
if (MAwidth > 0)
PlotOHLC(IIf(Lastbar, Null, RefVWAP+MAwidth), IIf(Lastbar, Null, RefVWAP+MAwidth), IIf(Lastbar, Null, RefVWAP-MAwidth), IIf(Lastbar, Null, RefVWAP-MAwidth), "",Clrvwap, styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, 1 ) ;
}
Plot(SD, "SD", colorBlack, styleNoDraw|styleNoLabel|styleNoRescale) ;
if (showvwap1sd)
{
Plot(IIf(Lastbar, Null, RefVwapm1), "-1SD"+strnday, Clrvwapm1, styleThick + styleTitle + stylelabel+styleNoRescale, Null, Null, 0, 1);
Plot(IIf(Lastbar, Null, RefVwapp1), "+1SD"+strnday, Clrvwapp1, styleThick + styleTitle + stylelabel+styleNoRescale, Null, Null, 0, 1);
if (SDwidth > 0)
PlotOHLC(IIf(Lastbar, Null, RefVWAPm1+SDwidth), IIf(Lastbar, Null, RefVWAPm1+SDwidth), IIf(Lastbar, Null, RefVWAPm1-SDwidth), IIf(Lastbar, Null, RefVWAPm1-SDwidth), "",Clrvwapm1, styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, 0 ) ;
if (SDwidth > 0)
PlotOHLC(IIf(Lastbar, Null, RefVWAPp1+SDwidth), IIf(Lastbar, Null, RefVWAPp1+SDwidth), IIf(Lastbar, Null, RefVWAPp1-SDwidth), IIf(Lastbar, Null, RefVWAPp1-SDwidth), "",Clrvwapp1, styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, 0 ) ;
}
if (showvwap2sd)
{
Plot(IIf(Lastbar, Null, RefVwapm2), "-2SD"+strnday, ParamColor("Color VWAP -2SD", colorSeaGreen), styleThick + styleTitle + stylelabel+styleNoRescale, Null, Null, 0, 1);
Plot(IIf(Lastbar, Null, RefVwapp2), "+2SD"+strnday, ParamColor("Color VWAP +2SD", colorOrange), styleThick + styleTitle + stylelabel+styleNoRescale, Null, Null, 0, 1);
if (SDwidth > 0)
PlotOHLC(IIf(Lastbar, Null, RefVWAPm2+SDwidth), IIf(Lastbar, Null, RefVWAPm2+SDwidth), IIf(Lastbar, Null, RefVWAPm2-SDwidth), IIf(Lastbar, Null, RefVWAPm2-SDwidth), "",ParamColor("Color VWAP -2SD", colorSeaGreen), styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, 0 ) ;
if (SDwidth > 0)
PlotOHLC(IIf(Lastbar, Null, RefVWAPp2+SDwidth), IIf(Lastbar, Null, RefVWAPp2+SDwidth), IIf(Lastbar, Null, RefVWAPp2-SDwidth), IIf(Lastbar, Null, RefVWAPp2-SDwidth), "",ParamColor("Color VWAP +2SD", colorOrange), styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, 0 ) ;
}
if (showvwap3sd)
{
Plot(IIf(Lastbar, Null, RefVwapm3), "-3SD"+strnday, ParamColor("Color VWAP -3SD", colorRed), styleThick + styleNoTitle + stylelabel+styleNoRescale, Null, Null, 0, 1);
Plot(IIf(Lastbar, Null, RefVwapp3), "+3SD"+strnday, ParamColor("Color VWAP +3SD", colorBlue), styleThick + styleNoTitle + stylelabel+styleNoRescale, Null, Null, 0, 1);
}
if (showvwapband)
{
PlotOHLC(IIf(Lastbar, Null, RefVwapm1), IIf(Lastbar, Null, RefVwapm1), IIf(Lastbar, Null, RefVwapm2), IIf(Lastbar, Null, RefVwapm2), "",ParamColor("Down Trend", colorRose), styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, Vwaplayer ) ;
PlotOHLC(IIf(Lastbar, Null, RefVwapp1), IIf(Lastbar, Null, RefVwapp1), IIf(Lastbar, Null, RefVwapp2), IIf(Lastbar, Null, RefVwapp2), "",ParamColor("Up Trend", colorSkyblue), styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, Vwaplayer ) ;
}
// if (showvwapswband)
// {
// PlotOHLC(RefVwapm1, RefVwapm1, RefVwapp1, RefVwapp1, "",ParamColor("Sideways Color", colorLavender), styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, Vwaplayer ) ;
// }
Avgp = (H+L+C)/3 ;
if (showtradearr)
{
Buy = Avgp >= Refvwapp1 ;
Short = Avgp <= Refvwapm1 ;
Sell = Avgp <= Refvwapp1 ;
Cover = Avgp >= Refvwapm1 ;
Buy = ExRem(Buy, Short OR Sell) ;
Short = ExRem(Short, Buy OR Cover) ;
sdp1touch = False ; // Ht >= Refvwapp1 ;
sdm1touch = False ; //Lt >= Refvwapm1 ;
Sell = ExRem(Sell, Buy OR sdp1touch ) ;
Cover = ExRem(Cover, Short OR sdm1touch ) ;
PlotShapes(Buy*shapeUpArrow, colorBlue, 0, H, 12) ;
PlotShapes(Short*shapeDownArrow, colorRed, 0, L, 12) ;
PlotShapes(Cover*shapeUpArrow, colorBlack, 0, H, 12) ;
PlotShapes(Sell*shapeDownArrow, colorBlack, 0, L, 12) ;
}
shift = Param("Shift", 0, -1, 0, 1) ;
prevdayvalue = prevdayvwap = ValueWhen(Ref(newdt,1), RefVWAP, 1) ;
prevdayvaluelow = prevdayvwapm1 = ValueWhen(Ref(newdt,1), RefVwapm1, 1) ;
prevdayvaluehigh = prevdayvwapp1 = ValueWhen(Ref(newdt,1), RefVwapp1, 1) ;
prevdayvwapm2 = ValueWhen(Ref(newdt,1), RefVwapm2, 1) ;
if (showvwapswband)
{
swclr = ParamColor("Sideways Color", colorLavender) ;
upclr = ParamColor("Bull Bias Color", colorSkyblue) ;
dnclr = ParamColor("Bear Bias Color", colorRose) ;
bandclr = IIf(Refvwap < prevdayvaluelow, dnclr, IIf(Refvwap > prevdayvaluehigh, upclr, swclr)) ;
PlotOHLC(IIf(Lastbar, Null, RefVwapp1), IIf(Lastbar, Null, RefVwapp1), IIf(Lastbar, Null, RefVwap), IIf(Lastbar, Null, RefVwap), "",bandclr, styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, Vwaplayer ) ;
PlotOHLC(IIf(Lastbar, Null, RefVwap), IIf(Lastbar, Null, RefVwap), IIf(Lastbar, Null, RefVwapm1), IIf(Lastbar, Null, RefVwapm1), "",bandclr, styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, Vwaplayer ) ;
}
if (showprevdayvals OR showextprevday)
{
if (shift == -1)
{
prevdayvaluehigh = prevdayvwap;
prevdayvalue = prevdayvwapm1 ;
prevdayvaluelow = prevdayvwapm2 ;
}
if (showprevdayvals) //(NOT showextprevday)
{
Plot(IIf(Lastbar, Null, prevdayvalue), "Prev VWAP", Clrvwap, styleDots|styleNoRescale+stylelabel|styleNoTitle) ;
Plot(IIf(Lastbar, Null, prevdayvaluelow), "VAL"+strnday, Clrvwapm1, styleDots|styleNoRescale+stylelabel+styleNoTitle) ;
Plot(IIf(Lastbar, Null, prevdayvaluehigh), "VAH"+strnday, Clrvwapp1, styleDots|styleNoRescale+stylelabel+styleNoTitle) ;
}
Clrprevdayband = ParamColor("Prev Day Band Color", colorLightYellow);
if (showprevdayband)
{
// if (NOT showextprevday)
PlotOHLC(IIf(Lastbar, Null, prevdayvaluelow), IIf(Lastbar, Null, prevdayvaluelow), IIf(Lastbar, Null, prevdayvaluehigh), IIf(Lastbar, Null, prevdayvaluehigh), "",Clrprevdayband, styleCloud|styleNoLabel|styleNoRescale, 0, 0, 0, Vwaplayer ) ;
}
if (showprev2dayvals)
{
prev2dayvalue = prev2dayvwap = ValueWhen(Ref(newdt,1), RefVWAP, 2) ;
prev2dayvaluelow = prev2dayvwapm1 = ValueWhen(Ref(newdt,1), RefVwapm1, 2) ;
prev2dayvaluehigh = prev2dayvwapp1 = ValueWhen(Ref(newdt,1), RefVwapp1, 2) ;
prev2dayvwapm2 = ValueWhen(Ref(newdt,1), RefVwapm2, 2) ;
// if (NOT showextprevday)
{
Plot(IIf(Lastbar, Null, prev2dayvalue), "2day prev VWAP"+strnday, Clrvwap, styleStaircase|styleThick|stylelabel|styleNoRescale+styleNoTitle) ;
Plot(IIf(Lastbar, Null, prev2dayvaluelow), "2day VAL"+strnday, Clrvwapm1, styleStaircase|styleThick|stylelabel|styleNoRescale+styleNoTitle) ;
Plot(IIf(Lastbar, Null, prev2dayvaluehigh), "2day VAH"+strnday, Clrvwapp1, styleStaircase|styleThick|stylelabel|styleNoRescale+styleNoTitle) ;
}
}
if (showextprevday)
{
x0 = BarCount - (extend+1) ;
x1 = BarCount -1 ;
Hdlast = SelectedValue(prevdayvaluehigh ) ;
Ldlast = SelectedValue(prevdayvaluelow ) ;
Hplot = LineArray(x0, Hdlast, x1, Hdlast) ;
Plot(Hplot, "", colorOrange, styleLine|styleNoLabel|styleNoRescale, 0,0,extend, extlayer) ;
LPlot = LineArray(x0, Ldlast, x1, Ldlast) ;
Plot(LPlot, "", colorGreen, styleLine|styleNoLabel|styleNoRescale, 0,0,extend, extlayer) ;
if (showextbandprevday)
PlotOHLC(HPlot, HPlot, LPlot, LPlot, "", Clrprevdayband, styleCloud|styleNoLabel|styleNoRescale, 0,0,extend,extlayer ) ;
}
}
if (showtext)
{
PlotText(NumToStr(RefVwapp1[BarCount-1], 1.1), BarCount+1, RefVwapp1[BarCount-1],Clrtext) ;
PlotText(NumToStr(RefVwapm1[BarCount-1], 1.1), BarCount+1, RefVwapm1[BarCount-1],Clrtext) ;
PlotText(NumToStr(RefVwap[BarCount-1], 1.1), BarCount+1, RefVwap[BarCount-1],Clrtext) ;
PlotText(NumToStr(RefVwapp2[BarCount-1], 1.1), BarCount+1, RefVwapp2[BarCount-1],Clrtext) ;
PlotText(NumToStr(RefVwapm2[BarCount-1], 1.1), BarCount+1, RefVwapm2[BarCount-1],Clrtext) ;
}
if (showvahvaltext)
{
PlotText(NumToStr(prevdayvalue[BarCount-1], 1.1), BarCount+1, prevdayvalue[BarCount-1],Clrtext) ;
PlotText(NumToStr(prevdayvaluelow[BarCount-1], 1.1), BarCount+1, prevdayvaluelow[BarCount-1],Clrtext) ;
PlotText(NumToStr(prevdayvaluehigh[BarCount-1], 1.1), BarCount+1, prevdayvaluehigh[BarCount-1],Clrtext) ;
}
}
_SECTION_BEGIN("AMA");
datamode = ParamToggle("Data Mode", "No|Yes", 0) ;
showintitle = ParamToggle("Show in Title", "No|Yes", 1) ;
showlabel = ParamToggle("Show Label", "No|Yes", 1) ;
usetf = ParamToggle("Use TF", "No|Yes", 1) ;
tf = Param("TF", 15, 1, 100000, 1) ;
isexpandLast = ParamToggle("Expand Mode", "First|Last", 1) ;
expandmode = IIf(isexpandLast, expandLast, expandFirst) ;
period = Param("Period", 30, 1, 100, 1) ;
noiseperiod = Param("Noise Period", 5, 1, 100, 1) ;
Clr = ParamColor("AMA Color", colorLightOrange) ;
ClrClose = ParamColor("AMA Close Color", colorOrange) ;
MAwidthper = Param("MA Width %", 0.005, 0, 10, 1) ;
MAwidth = SelectedValue(C) * MAwidthper /100 ;
showasband = ParamToggle("Show as band", "No|Yes", 1) ;
Onlyclose = ParamToggle("Show Only Close", "No|Yes", 0) ;
showclosebias = ParamToggle("Show Close Bias", "No|Yes", 0) ;
Closebiasht = Param("Close bias Ht", 4, 0, 100) ;
Clrbiasup = ParamColor("Color Bias Up", colorSkyblue) ;
Clrbiasdn = ParamColor("Color Bias Down", colorRose) ;
Clrbiasnone = ParamColor("Color Bias None", colorLavender) ;
Clrband = ParamColor("Color Band", colorViolet) ;
bandlevel = Param("Level Band", -1, -5, 5, 1) ;
tradearr = ParamToggle("Show Trade Arrow", "No|Yes", 0) ;
triggertypepvt = ParamToggle("Trigger Type", "Bar|Pvt", 0) ;
Onbody= ParamToggle("BO style", "H-L|Body", 1) ;
datamodestyle = styleNoRescale ;
if (NOT showintitle)
datamodestyle |= styleNoTitle ;
if (NOT showlabel)
datamodestyle |= styleNoLabel ;
if (datamode)
datamodestyle = styleNoDraw|styleNoTitle|styleNoLabel|styleNoRescale ;
onlyClosestyle = 0 ;
if (Onlyclose)
OnlyClosestyle = styleNoDraw ;
tfs = tf *in1Minute ;
if (usetf)
TimeFrameSet(tfs) ;
tfma = int(Interval()/60) ;
if (usetf AND tfs >= Interval())
tfma = tf ;
strtf = NumToStr(tfma, 8.0)+"min" ;
Refo = ParamField("TF Open", 0) ;
Refh = ParamField("TF High", 1) ;
Refl = ParamField("TF Low", 2) ;
Refc = ParamField("TF Close", 3) ;
//Refbi = ParamField("BI", 4) ;
//Plot(EMA( Close, period ), "", colorRed) ;
fast = 2/(2+1);
slow = 2/(period+1);
dir=abs(Refc -Ref(Refc ,-noiseperiod ));
vol=Sum(abs(Refc -Ref(Refc,-1)),noiseperiod );
ER=dir/vol;
sc =( ER*(fast-slow)+slow)^2;
amaplotcx = AMA( Refc, sc );
dirh=abs(Refh -Ref(Refh ,-noiseperiod ));
volh=Sum(abs(Refh -Ref(Refh,-1)),noiseperiod );
ERh=dirh/volh;
sch =( ERh*(fast-slow)+slow)^2;
amaplothx = AMA( Refh, sch );
dirl=abs(Refl -Ref(Refl ,-noiseperiod ));
voll=Sum(abs(Refl -Ref(Refl,-1)),noiseperiod );
ERl=dirl/voll;
scl =( ERl*(fast-slow)+slow)^2;
amaplotlx = AMA( Refl, scl );
amaplotc = amaplotcx ;
amaploth = amaplothx ;
amaplotl = amaplotlx ;
if (usetf)
{
amaplotc = TimeFrameExpand(amaplotcx, tfs, expandmode) ;
amaploth = TimeFrameExpand(amaplothx, tfs, expandmode) ;
amaplotl = TimeFrameExpand(amaplotlx, tfs, expandmode) ;
TimeFrameRestore() ;
}
showoncrb = ParamToggle("Show On CRB", "No|Yes", 0) ;
Refo = ParamField("CRB Open", 7+0) ;
Refh = ParamField("CRB High", 7+1) ;
Refl = ParamField("CRB Low", 7+2) ;
Refc = ParamField("CRB Close", 7+3) ;
Refbi = ParamField("CRB BI", 7+4) ;
Refcrbbars = ParamField("CRB Bars", 7+5) ;
Refnbars = ParamField("TF Bars", 7+6) ;
Refdt = ParamField("CRB DT", 7+7) ;
if (showoncrb)
{
diffbars = Refnbars -Refcrbbars -1 ;
// convert to crb
Refamaploth = Ref(amaploth, -diffbars) ;
Refamaplotc = Ref(amaplotc, -diffbars) ;
Refamaplotl = Ref(amaplotl, -diffbars) ;
// RefClre = Ref(Clr, -diffbars) ;
k = 0 ;
for ( i = Crbst ; i < BarCount ; i++)
{
Refbar = Refbi[i];
Refamaploth[i] = amaploth[Refbar] ;
Refamaplotc[i] = amaplotc[Refbar] ;
Refamaplotl[i] = amaplotl[Refbar] ;
// RefClre[i] = Clr[Refbar];
k++;
}
}
else
{
Refamaploth = amaploth ;
Refamaplotc = amaplotc ;
Refamaplotl = amaplotl ;
// RefClre = Clre ;
}
Plot(Refamaplotc, strtf+"AMA close"+NumToStr(period, 1.0)+" "+ NumToStr(noiseperiod , 1.0), ClrClose, styleThick|datamodestyle) ;
Plot(Refamaploth, strtf+"AMA high"+NumToStr(period, 1.0)+" "+ NumToStr(noiseperiod , 1.0), Clr, styleThick|datamodestyle|OnlyClosestyle) ;
Plot(Refamaplotl, strtf+"AMA low"+NumToStr(period, 1.0)+" "+ NumToStr(noiseperiod , 1.0), Clr, styleThick|datamodestyle|OnlyClosestyle) ;
if (MAwidth > 0)
PlotOHLC(Refamaplotc+MAwidth, Refamaplotc+MAwidth, Refamaplotc-MAwidth, Refamaplotc-MAwidth, "", ClrClose , styleCloud|styleNoLabel|datamodestyle) ;
if (showasband)
{
PlotOHLC(Refamaploth, Refamaploth, Refamaplotl, Refamaplotl, "", Clrband, styleCloud|styleNoLabel|datamodestyle|OnlyClosestyle, 0, 0, 0, bandlevel) ;
}
if (showclosebias)
{
upside = Refamaploth-(Refamaploth-Refamaplotl)/3 ;
dnside = Refamaplotl+(Refamaploth-Refamaplotl)/3 ;
up = Refamaplotc >= upside ;
dn = Refamaplotc <= dnside ;
Clr = IIf(up, Clrbiasup, IIf(dn, Clrbiasdn,Clrbiasnone)) ;
Plot(Closebiasht, "", Clr, styleArea|styleNoLabel|styleOwnScale, 0, 100) ;
}
showparam = ParamToggle("Show Key Param", "No|Yes", 0) ;
if (showparam)
{
y = (SelectedValue(Refamaploth)+ SelectedValue(Refamaplotl)) /2 ;
tfsd = tfs ;
if (tfsd < Interval())
tfsd = Interval() ;
str = "TF="+NumToStr(tfsd/in1Minute, 1.0) + " P=" + NumToStr(period, 1.0)+"-"+ NumToStr(noiseperiod, 1.0);
PlotText(str, BarCount+2, y, colorBlack) ;
}
showrib = ParamToggle("Show Ribbon", "No|Yes", 0) ;
barht = Param("Bar Ht", 4, 1, 100) ;
Refo = ParamField("Open", 0) ;
Refh = ParamField("High", 1) ;
Refl = ParamField("Low", 2) ;
Refc = ParamField("Close", 3) ;
if (showrib)
{
Buy = Refc > Max(Refamaplotc, Refamaploth) ;
Short = Refc < Min(Refamaplotc, Refamaplotl) ;
up = Flip(Buy, Short) ;
dn = Flip(Short, Buy) ;
Clr = IIf(up, colorBlue, colorRed) ;
Plot(barht, "", Clr, styleArea|styleNoLabel|styleOwnScale, 0, 100) ;
}
isemapvts = ParamToggle("Pvt Type", "H-L|EMA", 0) ;
if (tradearr)// AND NOT datamode)
{
avgP = (Refh+refl+Refc)/3 ;
p1 = Param("Fast", 1, 1, 100, 1) ;
p2 = Param("Slow", 3, 1, 100, 1) ;
ismph = H-H ;
ismpl = L-L ;
if (isemapvts)
{
EMA1 = EMA(avgP, p1) ;
EMA2 = EMA(avgP, p2) ;
upcross = Cross(EMA1, EMA2) ;
downcross = Cross(EMA2, EMA1) ;
bi = BarIndex() ;
mphbar = HighestSinceBars(upcross, Refh) ;
mplbar = LowestSinceBars(downcross, Refl) ;
mphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, mphbar, 0) ;
ismph = mphbi == bi ;
mplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, mplbar, 0) ;
ismpl = mplbi == bi ;
ismph = IIf(downCross AND mphbar == 0, True, ismph) ;
ismpl = IIf(upcross AND mplbar == 0, True, ismpl) ;
}
else
{
ismph = H >= Ref(H, -1) AND H > Ref(H, 1) ;
ismpl = L <= Ref(L, -1) AND L < Ref(L, 1) ;
/*
ismph = ExRem(ismph, ismpl) ;
ismpl = ExRem(ismpl, ismph) ;
isbmph = ExRem(isbmph, isbmpl) ;
isbmpl = ExRem(isbmpl, isbmph) ;
*/
}
showminor = ParamToggle("Show Minor Pvts", "No|Yes", 1) ;
showminorlvls = ParamToggle("Show Minor Levels", "No|Yes", 1) ;
issquare = ParamToggle("Pvt style", "Circle|Square", 0) ;
pvtmarker = IIf(issquare, shapeSmallSquare, shapeSmallCircle) ;
if (showminor)
{
PlotShapes(ismph*pvtmarker , colorRed, 0, Refh, 12) ;
PlotShapes(ismpl*pvtmarker , colorGreen, 0, Refl, -12) ;
}
mph = ValueWhen(ismph, Refh) ;
mpl = ValueWhen(ismpl, Refl) ;
if (showminorlvls)
{
x = LineArray(0, SelectedValue(mph), (BarCount-1), SelectedValue(mph));
Plot(x, "", colorGold, styleDashed);
x = LineArray(0, SelectedValue(mpl), (BarCount-1), SelectedValue(mpl));
Plot(x, "", colorGold, styleDashed);
}
Reflow = Refl ;
Refhigh = Refh ;
if (Onbody)
{
Reflow = Min(Refo, Refc) ;
Refhigh = Max(Refo, Refc) ;
}
if (triggertypepvt)
{
Buy = ismph AND mph > AMAploth ;
Short = ismpl AND mpl < AMAplotl ;
}
else
{
Buy = avgP > AMAploth ;
Short = avgP < AMAplotl ;
}
Buy = ExRem(Buy, Short OR (C < AMAploth AND NOT C < AMAplotl ) ) ;
Short = ExRem(Short, Buy OR C < (AMAplotl AND NOT C > AMAploth ) ) ;
PlotShapes(Buy*shapeUpTriangle, colorGreen, 0, Refh, 12) ;
PlotShapes(Short*shapeDownTriangle, colorBrown, 0, Refl, 12) ;
}
_SECTION_END();
_SECTION_BEGIN("gfx conditions");
Closefilter1 = Ref(C,-1)>Vwapp1 AND Ref(C,-2)>vwapp1;// +1sd
Closefilter2 = Ref(C,-1)<Vwapm1 AND Ref(C,-2)<Vwapm1;// vwap
Closefilter3 = Ref(C,-1)>prevdayvaluehigh AND Ref(C,-2)>prevdayvaluehigh;// y +1sd
Closefilter4 = Ref(C,-1)<prevdayvaluelow AND Ref(C,-2)<prevdayvaluelow;
Closefilter5 = (Ref(C,-1)>prevdayvaluelow AND Ref(C,-2)>prevdayvaluelow) AND Ref(C,-1)<prevdayvaluehigh;
Closefilter6 = Ref(C,-1)>amaploth AND Ref(C,-2)>amaploth;// amahigh
Closefilter7 = Ref(C,-1)<amaplotl AND Ref(C,-2)<amaplotl;// amalow
todayvwapUptrend = WriteIf(Closefilter1,"UPTREND",WriteIf(Closefilter2,"DOWNTREND","SIDEWAYS"));
ydayVwaptrend = WriteIf(Closefilter3,"WAIT FOR UPTREND",WriteIf(Closefilter4,"WAIT for SHORTS","NEUTRAL ZONE"));
entrynow = WriteIf(Closefilter1 AND Closefilter3,"enter@ MPH BO only",WriteIf(Closefilter2 AND Closefilter4,"enter@MPL BD only",
WriteIf((Closefilter5 AND Closefilter1)OR (Closefilter5 AND Closefilter2),"pivot bo/bd @1sd","scalp/BOF/BDF")));
exitnow = WriteIf(Closefilter1 AND Closefilter3,"TRAIL SL only& RELAX",WriteIf(Closefilter2 AND Closefilter4,"TRAiL SL& RELAX",
WriteIf((Closefilter5 AND Closefilter1)OR (Closefilter5 AND Closefilter2),"BO/BD of 1SD/Pivot","1:1 only")));
amahigh = WriteIf(Closefilter6,"LONG only",WriteIf(Closefilter7,"SHORT only","SIDEWAYS"));
_SECTION_END();
// Message Board -----------------
GfxSelectFont( "Tahoma", 13, 100 );
GfxSetBkMode( 1 );
GfxSetTextColor
( colorWhite );
if ( SelectedValue( Closefilter6 ) == 1 )
{
GfxSelectSolidBrush( colorDarkGreen );
}
else
if ( SelectedValue( Closefilter7 ) == 1 )
{
GfxSelectSolidBrush( colorRed );
}
else
{
GfxSelectSolidBrush( colorBlueGrey );
}
pxHeight = Status( "pxchartheight" ) ;
xx = Status( "pxchartwidth");
Left = 1100;
width = 310;
x = 5;
x2 = 290;
y = pxHeight;
GfxSelectPen
( colorLightBlue, 1); // border color
GfxRoundRect
( x, y - 155, x2, y , 7, 7 ) ;
GfxTextOut( ( "pivot+vwap+ AMA "),13,y-150);
GfxTextOut
("YDAY vwap = "+ ydayvwaptrend, 13, y-125);
GfxTextOut
("today vwap = "+ todayvwapuptrend, 13, y-105);
GfxTextOut
("AMA = " +AMAhigh,13,y-85);
GfxTextOut
("entry = "+ entrynow, 13, y-65);
GfxTextOut
("EXIT = "+ exitnow, 13, y-47);
GfxTextOut
("LTP =" + C,13,Y-30);
_SECTION_BEGIN("Time Left");
function GetSecondNum()
{
Time = Now( 4 );
Seconds = int( Time % 100 );
Minutes = int( Time / 100 % 100 );
Hours = int( Time / 10000 % 100 );
SecondNum = int( Hours * 60 * 60 + Minutes * 60 + Seconds );
return SecondNum;
}
RequestTimedRefresh( 1 );
TimeFrame = Interval();
SecNumber = GetSecondNum();
Newperiod = SecNumber % TimeFrame == 0;
SecsLeft = SecNumber - int( SecNumber / TimeFrame ) * TimeFrame;
SecsToGo = TimeFrame - SecsLeft;
x=Param("xposn",50,0,1000,1);
y=Param("yposn",380,0,1000,1);
GfxSelectSolidBrush( ColorRGB( 230, 230, 230 ) );
GfxSelectPen( ColorRGB( 230, 230, 230 ), 2 );
if ( NewPeriod )
{
GfxSelectSolidBrush( colorYellow );
GfxSelectPen( colorYellow, 2 );
Say( "New period" );
}
//GfxRoundRect( x+45, y+40, x-3, y-2, 0, 0 );
//GfxSetBkMode(1);
GfxSelectFont( "Arial", 14, 700, False );
GfxSetTextColor( colorRed );
GfxTextOut( "Time Left :"+SecsToGo+"", x, y );
_SECTION_END();