# Need Moving Average %shift bands - AFL

#### yasu222

##### Active Member

Moving Average - Shift'ed Bands - Plot
V1:=Input("Mov periods",2,500,200);
V2:=Input("% shift",0,50,.1);
A1:=Mov(C,V1,E);
A2:=A1+(A1*(V2/100));
A3:=A1-(A1*(V2/100));
A1;
A2;
A3

Moving Average - Shift'ed Bands - Alerts

V1:=Input("Mov periods",2,500,200);
V2:=Input("% shift",0,50,.1);
A1:=Mov(C,V1,E);
A2:=A1+(A1*(V2/100)); {Top band}
A3:=A1-(A1*(V2/100)); {Bottom band}
Alert(C=A2 OR Cross(A2,C),1); {Top band contact OR crossing}
-Alert(C=A3 OR Cross(C,A3),1); {Bottom band contact OR crossing, minus sign in front makes it easier to see plot}

#### ford7k

##### Banned
Hi friend

actually-in summary you see a 200 moving average with 0.1% line above it and below it.
any price chart with 200 ma is same as it,barring 0.1% change above or below.

Try this- not perfect-but need some adjustments.
can you post some image from metastock!
--------------------------------------------------------------------------------------------
NOTE THE ORIGINAL CONCEPT
AS FOLLOWS FOR THE MOVING AVERAGE SHIFTED BANDS
Nick Channon SAYS
I have plotted a 200-day exponential moving average, and also:
* above it, the same MA but with a vertical shift of 0.1%
* below it, the same MA but with a vertical shift of 0.1%

This obviously creates 3 parallel bands.

I want to set up an alert that fires when the price touches or drops below the top band, and another that fires when the price touches or rises above the bottom band.

-------------------------------------------------------------------------------------------
go to parameters and play with % shift increase or decrease
TRY FOR 5 MIN CHART,NIFTY FUTURES WITH 200 AND 0.1 SHIFT

I remember there was an afl called MTB MOVING TREND BANDS.

HTML:
``````//Moving Average - Shift'ed Bands
//SETTINGS TRY PERIODS 200,SHIFT 2.2
/*
Moving Average - Shift'ed Bands - Plot--METASTOCK CODE
V1:=Input("Mov periods",2,500,200);
V2:=Input("% shift",0,50,.1);
A1:=Mov(C,V1,E);
A2:=A1+(A1*(V2/100));
A3:=A1-(A1*(V2/100));
A1;
A2;
A3
//-----------------------------

Moving Average - Shift'ed Bands - Alerts

V1:=Input("Mov periods",2,500,200);
V2:=Input("% shift",0,50,.1);
A1:=Mov(C,V1,E);
A2:=A1+(A1*(V2/100)); {Top band}
A3:=A1-(A1*(V2/100)); {Bottom band}
Alert(C=A2 OR Cross(A2,C),1); {Top band contact OR crossing}
-Alert(C=A3 OR Cross(C,A3),1); {Bottom band contact OR crossing, minus sign in front makes it easier to see Plot}
*/
//===============================
//afl
V1 =Param("periods",200,200,500);
V2 =Param("%shift",0.10,0,50,0.50);
A1 = EMA(C,V1);
A2 = A1 + (A1*(V2/100));//TOPBAND
A3 = A1 - (A1*(V2/100));//BOTTOM BAND
Plot(A1,"EMA V1",colorBlue,styleThick);
Plot(A2,"TOPBAND",colorRed,styleThick);
Plot(A3,"BOT BAND",colorRed,styleThick);
TBC=(C==A2  OR Cross(A2,C));
BBC = (C=A3   OR Cross(C,A3));

_SECTION_BEGIN("Price");
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", colorBlack ), styleNoTitle | ParamStyle("Style") | styleBar );
_SECTION_END();``````

Last edited: