Saturday 16 November 2013

3/15 Crossover Trading AFL with buy sell signals

This trading system is based moving average cross over. The importance is given for the Three days moving average and the Fifteen days moving average. This method produces some good trades on a weekly time frame. Even on EOD basis this could generate good signals. But on intraday it can produce many whipsaw like patterns leaving the user in a confused state.  When a 3 day MA crosses the 15 days MA a trading signal is generated. It can be long or short. If the user identifies good stocks and applies this system some good trades can be done. The only condition is the system should be followed with discipline.

The system indicates support level and resistance levels based on the previous candles. SAR also has been provided which alerts the user reversal trends at the levels. In the properties windows the support and resistant levels can be adjusted and the desired colors too can be set. An audio alert is also incorporated alerting the trader of buy sell signals.

I have added a magnified market price to this AFL which is also customizable, for easy viewing.

//////////////////////////////////////////// the code is posted below ////////////////////////////////////////////////
_SECTION_BEGIN("ema3,15");
x = EMA(Close,3);
y = EMA(Close,15);

Plot(EMA(Close,3),"",colorYellow, styleLine, styleThick);
Plot(EMA(Close,15),"",colorGreen, styleLine, styleThick);
GraphXSpace=0.5;
Plot(C,"",colorBlack,styleCandle);
XR=(EMA(Close,3) * (2 / 6 - 1) - EMA(Close,15) * (2 / 11 - 1)) / (2 / 6 - 2 / 11);


Buy = Close > EMA( Close , 15 )
AND Ref( Close , -1 ) > Ref( EMA( Close , 15 ) , -1 )
AND Cross(x,y);

Sell = Close > EMA( Close , 3 )
AND Open > EMA( Close , 3 );

Short = Close < EMA( Close , 3 )
AND Ref( Close , -1 ) < Ref( EMA( Close , 3 ) , -1 )

AND Cross(y,x);

Cover = Close < EMA( Close , 3 )
AND Open < EMA( Close , 3 );

SellPrice=ValueWhen( Sell, C, 1);
BuyPrice=ValueWhen( Buy,C, 1);
Long=Flip(Buy,Sell);
Shrt=Flip(Sell,Buy );


PlotShapes(shapeUpArrow*Buy,colorBrightGreen, 0, L, Offset=-45);
PlotShapes(shapeDownArrow*Short,colorRed, 0, H, Offset=-45);
AlertIf( Buy, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );
AlertIf( Cover, "SOUND C:\\Windows\\Media\\notify.wav", "Audio alert", 2 );
AlertIf( Short, "SOUND C:\\Windows\\Media\\chord.wav", "Audio alert", 2 );

_SECTION_END();

_SECTION_BEGIN("supp");
("Price");
RSIperiod = 15; // Param("RSI p",3,14,30,1);
Percent = 5; // Param("ZIG %",8,9,15,1);
EMAperiod = 5; //Param("EMA p",4,5,10,1);
HHVperiod = 8; //Param("HHV p",3,5,10,1);
NumLine = 2; //Param("Num Lines",3,1,20,1);

Base = DEMA(RSI(RSIperiod),EMAperiod);

GraphXSpace=0.5;
Plot(C,"",colorWhite,styleCandle);

for( i = 1; i <= numline; i++ )
{
ResBase = LastValue(Peak(Base,Percent,i));
SupBase = LastValue(Trough(Base,Percent,i));
Plot(ValueWhen( ResBase==Base, HHV(H,HHVperiod) ), "Resist Level", colorOrange, styleLine);
Plot(ValueWhen( supbase==Base, LLV(L,HHVperiod) ), "Support Level", colorBrightGreen, styleLine);
}

_SECTION_END();

_SECTION_BEGIN("SAR");
acc = Param("Acceleration", 0.02, 0, 1, 0.001 );
accm = Param("Max. acceleration", 0.2, 0, 1, 0.001 );
Plot( SAR( acc, accm ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style", styleDots | styleNoLine, maskDefault | styleDots | styleNoLine ) );

_SECTION_BEGIN("Magnified Market Price");
FS=Param("Font Size",28,11,100,1);
GfxSelectFont("Arial", FS, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor( ParamColor("Color",colorViolet) );
Hor=Param("Horizontal Position",766,1,1200,1);
Ver=Param("Vertical Position",1,1,1,1);
GfxTextOut(""+C,Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont("Arial", 12, 700, italic = False, underline = False, True );
GfxSetBkMode( colorWhite );
GfxSetTextColor(ParamColor("Color",colorViolet) );
GfxTextOut(""+DD+" ("+xx+"%)", Hor+5, Ver+45 );
_SECTION_END();

_SECTION_BEGIN("Title");
if( Status("action") == actionIndicator )
(
Title = EncodeColor(colorBlack)+ ":EMA 3/15, " + " - " + Name() + " - " + EncodeColor(colorWhite)+ Interval(2) + EncodeColor(colorBlack) +
" - " + Date() +" - "+"\n" +EncodeColor(colorBlue) +"Op-"+O+" "+"Hi-"+H+" "+"Lo-"+L+" "+
"Cl-"+C+" "+ "Vol= "+ WriteVal(V, 1.0)+"\n"+
EncodeColor(colorBrightGreen)+
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+" ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+" ","")+"\n"+EncodeColor(colorWhite)+
WriteIf(Sell , "Total Profit/Loss for the Last Trade Rs."+(C-BuyPrice)+"","")+
WriteIf(Buy , "Total Profit/Loss for the Last trade Rs."+(SellPrice-C)+"","")+
WriteIf(Long AND NOT Buy, "Trade : Long - Entry price Rs."+(BuyPrice),"")+
WriteIf(shrt AND NOT Sell, "Trade : Short - Entry price Rs."+(SellPrice),"")+"\n"+
WriteIf(Long AND NOT Buy, "Current Profit/Loss Rs."+(C-BuyPrice)+"","")+
WriteIf(shrt AND NOT Sell, "Current Profit/Loss Rs."+(SellPrice-C)+"",""));
WriteIf(x-y, "Cross over","");
AlertIf( Buy, "SOUND C:\\Windows\\Media\\Windows XP Startup.wav", "Audio alert", 2 );
AlertIf( Sell, "SOUND C:\\Windows\\Media\\Ringin.wav", "Audio alert", 2 );


////////////////////////////////////////////////end of code////////////////////////

I hope this tool along with good money management ,will be very useful for traders

My best wishes.

No comments:

Post a Comment