// Downloaded From https://www.WiseStockTrader.com
_SECTION_BEGIN("Mlightf");
// ACD Plot
// LSMA is Linreg
// ACD.afl
// v 1.2 9/13/2004
// plots ACD levels and pivot range from daily

SetChartBkColor(16);

Per = Param("Periods",13);
Per2 = Param("Periods 2",34);
LSMAPer = Param("LMSA Period",25);
Offset = Param("A Level",1);
ACDFlag = 0;
IntervalFlag = IIf(Interval(format=0)==300,1,0);

strInterval = Interval(format=2);

strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);


if( StrFind( Name(), "YM" ) )
 {
 ACDOffset = 10;
 ACDFlag = 1;
 ACDTime = 94500;
 }

if( StrFind( Name(), "ER" ) )
 {
 ACDOffset = 0.5;
 ACDFlag = 1;
 ACDTime = 93500;

 }
if( StrFind( Name(), "ES" ) )
 {
 ACDOffset = 2;
 ACDFlag = 1;
 ACDTime = 94500;

 }

if( StrFind( Name(), "NQ" ) )
 {
 ACDOffset = 3;
 ACDFlag = 1;
 ACDTime = 94500;

 }

if( StrFind( Name(), "ZB" ) )
 {
 ACDOffset = 0.15;
 ACDFlag = 1;
 ACDTime = 83000;

 }

if( StrFind( Name(), "ZN" ) )
 {
 ACDOffset = 0.15;
 ACDFlag = 1;
 ACDTime = 83000;

 }


GraphXSpace = 1;
Shift = 2;

// calculate the pivot range
PDH = TimeFrameGetPrice( "H", inDaily, -1 ); // gives previous Day High when working on intraday data
PDL = TimeFrameGetPrice( "L", inDaily, -1 );
PDC = TimeFrameGetPrice( "C", inDaily, -1 );
PP = (PDH+PDL+PDC)/3;

DIFF = abs((PDH+PDL)/2 - PP);
PRHi = PP + DIFF;
PRLo = PP - DIFF;

EMA1 = EMA(Avg,Per);
EMA2 = EMA(Avg,Per2);
LSMA = LinearReg(Avg, LSMAPer);

Plot(C, "Close",colorWhite,styleCandle);


if ((ACDFlag) AND (IntervalFlag)) {

ORHigh=
ValueWhen(TimeNum()<ACDTime,HighestSince(DateNum()>Ref(DateNum(),-1),High));
ORLow = ValueWhen(TimeNum()<ACDTime,LowestSince(DateNum()>Ref(DateNum(),-1), Low));

Plot(PRHi,"PRHigh",colorWhite,styleDots+styleNoLine+styleNoLabel);
Plot(PRLo,"PRLow",colorWhite,styleDots+styleNoLine+styleNoLabel);
Plot(ORHigh,"ORHigh",colorBlue,style=styleStaircase+styleDots+styleNoLine+styleNoLabel);
Plot(ORLow,"ORLow",colorBlue,style=styleStaircase+styleDots+styleNoLine+styleNoLabel);
Plot(ORHigh+ACDOffset,"AUp",colorYellow,style=styleStaircase+styleDots+styleNoLine);
Plot(ORLow-ACDOffset,"ADn",colorYellow,style=styleStaircase+styleDots+styleNoLine);
// Plot(LSMA, "LSMA", colorYellow,style=styleThick);

}

Title=Name()+" ["+strInterval+"] "+ strWeekday + " " +Date()+ " Close:
"+WriteVal(C,format=1.2) +" "+WriteVal(per,format=1.0)+"-Per MA: "
+WriteVal(EMA1,format=1.2)+" " + WriteVal(per2,format=1.0)+"-Per MA: "
+WriteVal(EMA2,format=1.2) + " PR High: "+WriteVal(PRHi,format=1.2) + " PR
Low: "+WriteVal(PRLo,format=1.2)  ;
_SECTION_END();
_SECTION_BEGIN("Show Values at H&L");

n=Param("Values back",20,1,200,1);
p=Param("zig %",5,1,100,1);
dist = 0.8*ATR(15);

for( i = 1; i < n; i++ )
{	
	PlotText(""+LastValue(Peak(H,p,i),True),BarCount-3-LastValue(PeakBars(H,p,i)),LastValue(dist,True)+LastValue(Peak(H,p,i),False),colorBlack,ColorRGB(225,225,225));
	PlotText(""+LastValue(Trough(L,p,i),True),BarCount-3-LastValue(TroughBars(L,p,i)),LastValue(Trough(L,p,i),False)-LastValue(dist,True),colorBlack,ColorRGB(225,225,225));
}
_SECTION_BEGIN("Sup / Res Lines");
SRswitch = ParamToggle("Sup / Res Lines","On,Off");
CHLswitch = ParamToggle("Hi Low / Close","Hi Low,Close");
NoLines = Param("No of Lines",3,1,10,1);
Sen = Param("Sensitivity",5,1,100,1);

Rcolor=ParamColor( "Res Color", colorGreen );
Rstyle=ParamStyle( "Res Style", styleLine );

Scolor=ParamColor( "Sup Color", colorBrown );
Sstyle=ParamStyle( "Sup Style", styleLine );

y=0;
x=0;

for( i = 1; i < NoLines+1 ; i++ )
{
Y[i]=LastValue(Peak(IIf(CHLswitch,C,H),Sen,i));
x[i]=BarCount - 1 - LastValue(PeakBars(IIf(CHLswitch,C,H),Sen,i));
Line = LineArray( x[i], y[i], Null, y[i], 1 );
Plot( IIf(SRswitch,Null,Line), "", Rcolor, Rstyle );

Y[i]=LastValue(Trough(IIf(CHLswitch,C,L),Sen,i));
x[i]=BarCount - 1 - LastValue(TroughBars(IIf(CHLswitch,C,L),Sen,i));
Line = LineArray( x[i], y[i], Null, y[i], 1 );
Plot( IIf(SRswitch,Null,Line), "", Scolor, Sstyle );
}
_SECTION_END();
_SECTION_BEGIN("VAP");
segments = IIf( Interval() < inDaily, Day(), inQuarterly);
segments = segments != Ref( segments , -1 );

PlotVAPOverlayA( segments , Param("Lines", 323, 100, 1000, 1 ), Param("Width", 100, 1, 100, 1 ), ParamColor("Color", colorBlue ), ParamToggle("Side", "Left|Right" ) | 2 * ParamToggle("Style", "Fill|Lines", 1) | 4*ParamToggle("Z-order", "On top|Behind", 1 ) );
Plot(segments, "", colorLightGrey, styleHistogram | styleOwnScale );
_SECTION_END();
_SECTION_BEGIN("Vol-Trend");

uptrend=PDI(20)>MDI(10)AND Signal(29)<MACD(13);
downtrend=MDI(10)>PDI(20)AND Signal(29)>MACD(13);
Plot( 2, /* defines the height of the ribbon in percent of pane width */"",
IIf( uptrend, colorGreen, IIf( downtrend, colorRed, 0 )), /* choose color */
styleOwnScale|styleArea|styleNoLabel, -0.5, 100 );
Plot(V,"",IIf(C>O,colorGreen,IIf(C<O,4,7)),2|4|32768,5);
//Plot(MA(V,45),"",colorBlue,0|4|32768,40);
//,styleLine|styleThick|styleOwnScale);

GfxSetOverlayMode(0); 
GfxSelectFont("Tahoma", Status("pxheight")/36); 
GfxSetTextAlign( 6 );// center alignment 
GfxSetTextColor( colorWhite ); 
GfxSetBkMode(0); // transparent 
GfxTextOut(Name(), Status("pxwidth")/2, Status("pxheight")/15 );
GfxTextOut( "Chart By Mlightf", Status("pxwidth")/2, Status("pxheight")/9 );
GfxSelectFont("Tahoma", Status("pxheight")/40 );