Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

_SECTION_BEGIN(" Mean_Revert");

SetPositionSize(1,spsShares);
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" ) | GetPriceStyle() );

SetBarsRequired(10000,0);
FastEMAPeriod = Param("FastEMAPeriod",15,1,100,1);
SlowEMAPeriod =Param("SlowEMAPeriod",180,1,200,1);

per1= 15;
per2= 2;

EMA1= EMA(C,FastEMAPeriod);
EMA2= EMA(C,SlowEMAPeriod);

uptrend= EMA1>EMA2; dwntrend= EMA1<EMA2;


bbtop= BBandTop(C,per1,per2);
bbot= BBandBot(C,per1,per2);
supp= Cross(C,bbot); ress= Cross(bbtop,C);

Ll= LLV(L,5); Hh= HHV(H,5);

Buy=Sell=Short=Cover=Null;

sl=sls=tgt=tgts=0;
for(i=200; i<BarCount; i++)
{
if(sl==0 AND uptrend[i] AND supp[i])
{ Buy[i]=1; sl= Ll[i]; tgt= H[i];}
if((L[i]<sl OR ress[i]) AND sl>0)
{ if(L[i]<sl)SellPrice[i]= sl; Sell[i]= 1; sl=tgt=0;}

if(sls==0 AND dwntrend[i] AND ress[i])


{ Short[i]=1; sls= Hh[i]; tgts= L[i];}
if( (H[i]>sls OR supp[i]) AND sls>0)
{ if(H[i]>sls)CoverPrice[i]=sls; Cover[i]=1; sls=tgts=0; }
}

Plot( EMA1, "EMA Fast", colorRed, styleLine | styleNoRescale );


Plot( EMA2, "EMA Slow", colorBlue, styleLine | styleNoRescale );
Plot(bbtop, "Band Top", colorBlack, styleLine);
Plot(bbot, "Band Bottom", colorBlack, styleLine);

PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );


PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -45 );

PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );


PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45
);
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -45 );
_SECTION_END();

You might also like