0% found this document useful (0 votes)
206 views

Mean Reversion

This document defines a mean reversion trading strategy using EMA crossover signals and Bollinger Bands. It sets position size, chart options, and defines the fast and slow EMA periods. It calculates EMA, Bollinger Band, and crossover signals and enters/exits long and short positions when signals are generated between the EMA and Bollinger Bands. Charts are plotted to visualize the signals and strategy.

Uploaded by

Bharat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
206 views

Mean Reversion

This document defines a mean reversion trading strategy using EMA crossover signals and Bollinger Bands. It sets position size, chart options, and defines the fast and slow EMA periods. It calculates EMA, Bollinger Band, and crossover signals and enters/exits long and short positions when signals are generated between the EMA and Bollinger Bands. Charts are plotted to visualize the signals and strategy.

Uploaded by

Bharat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy