//------------------------------------------------------------------------------
//
// Formula Name: ATR Volatility System
// Author/Uploader: Marcelin
// E-mail: marcelint@xnet.ro
// Date/Time Added: 2006-01-14 13:08:22
// Origin:
// Keywords:
// Level: medium
// Flags: system
// Formula URL: http://www.amibroker.com/library/formula.php?id=578
// Details URL: http://www.amibroker.com/library/detail.php?id=578
//
//------------------------------------------------------------------------------
//
// ATR trading system for short terms tradings. You can use it with Absolute
// Strength Index for confirmation of signals.
//
//------------------------------------------------------------------------------
_SECTION_BEGIN("NewSystem ATR");
SetPositionSize(100,spsShares);
/*Writed & composed by Tudor Marcelin - Art Invest*/
n=Optimize( "perioada", 14, 5 , 20, 1 );
k=Optimize( "factor de multiplicare", 1.4, 0.5 , 2.5, 0.1 );
f=ATR(n);
/*R rezistenta pentru ziua curenta*/
R[0] = C[0];
/*S rezistenta pentru ziua curenta*/
S[0] = C[0];
for( i = n+1; i < BarCount; i++ )
{
R[i]=R[i-1];
S[i]=S[i-1];
if (( S[i-1]<=C[i-1]) AND (C[i-1] <=R[i-1] ) AND (C[i-1]+k*f[i-1])<=RV)
R[i] = C[i-1]+k*f[i-1];
if (( S[i-1]<=C[i-1]) AND (C[i-1]<=R[i-1] ) AND (C[i-1]-k*f[i-1])>=SV)
S[i]= C[i-1]-k*f[i-1];
if ( C[i-1] >R[i-1] )
{
R[i] = C[i-1]+k*f[i-1];
S[i]= C[i-1]-k*f[i-1];
RV=R[i];
SV=S[i];
}
if ( C[i-1] <S[i-1] )
{
R[i] = C[i-1]+k*f[i-1];
S[i]= C[i-1]-k*f[i-1];
RV=R[i];
SV=S[i];
}
Buy=Close>R;
Sell=Close<S;
Cump=IIf(Close>R,1,0);
Vanz=IIf(Close<S,1,0);
}
Plot(Close,"Close",colorBlack,styleCandle);
Buy = ExRem( Buy, Sell );
Sell = ExRem( Sell, Buy );
iBuy = Flip( Buy, Sell );
iSell =Flip( Sell, Buy );
Plot(IIf(iSell,R,Null), "Rez:",colorRed,styleDots|styleNoLine);
Plot(IIf(iBuy,S,Null), "Sup:",colorGreen,styleDots|styleNoLine);
Short=Sell;
Cover=Buy;
BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);
Title = EncodeColor(colorWhite)+ "Super Trend AFL code from www.marketcalls.in" + " - " + Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
" - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V)+"\n"+
EncodeColor(colorLime)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorYellow)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","");
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(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);
//AlertIf( Buy, "", "Volatility System", 1 );
//AlertIf( Sell, "", "Volatility System",2);
//Color = IIf( Vanz OR Sell, colorRed, IIf(Buy,colorGreen,colorLightGrey));
//Plot( 2, "", Color, styleArea | styleOwnScale | styleNoLabel, -0.1, 50 );
GraphXSpace = 3;
Title=EncodeColor(colorBlue)+"Volatility System"+EncodeColor(colorBlack)+ " Open:"+O+" High:"+H+" Low:"+L+" Close:"+C+EncodeColor(colorGreen)+" Rez:"+R+EncodeColor(colorRed)+" Sup:"+S+EncodeColor(colorBlue)+
" \nDate: "+EncodeColor(colorRed)+Date();
_SECTION_END();