Moving Average Crossovers are a popular style of trading in Intraday trading.
The below Amibroker AFL for Moving Average Crossover is a 5 SMA crossing the
9 SMA. The Buy or Sell Arrows are shown on the closing candle at the crossover point.
Entries made on basis of Moving Average Crossover may turn out to be loss making
in sideways markets. So Trend should always be taken into account when such
crossover trades are being initiated.
When the Low Moving Average crosses the Higher Moving Average [Above or Below]
the trade is initiated in the direction of the crossover. That is if 5 SMA crosses 9 SMA
from above then a sell trade is to be initiated and when 5 SMA crosses the 9 SMA from below
then Long trade has to be initiated.
For reference an image has been posted below the post.
===========================Copy The Code Below============================
_SECTION_BEGIN("SMA5X9");
MA5 = MA(C, 5);
MA9 = MA(C, 9);
Buy = Cross(MA5, MA9);
Sell = Cross(MA9, MA5);
Filter = Buy OR Sell;
Buy = ExRem(Buy, Sell);
Sell =ExRem(Sell, Buy);
trigger = WriteIf(Buy, "BUY", WriteIf(Sell, "SELL", " "));
fg = IIf(Buy, colorDarkGreen, IIf(Sell, colorRed, colorDefault));
bg = IIf(Buy, colorPaleGreen, IIf(Sell, colorPink, colorDefault));
_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}} : O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, Vol=%1.0f\n{{VALUES}}", O, H, L, C, V));
if(Status("action") == actionIndicator)
{
PlotOHLC(O, H, L, C, "", colorGrey40, styleCandle);
Plot(MA5, "MA(Close, 5)", colorSeaGreen, styleLine);
Plot(MA9, "MA(Close, 9)", colorRed, styleLine);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-10);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=10);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-15);
}
if(Status("action") == actionExplore)
{
SetOption("NodefaultColumns", True);
AddTextColumn(Name(), "Symbol", 77, colorDefault, colorDefault, 120);
AddColumn(DateTime(), "Date", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(trigger, "Signal", 77, fg, bg);
AddColumn(C, "C. M. P.", 1.2, fg, colorDefault, 96);
}
_SECTION_END();
=====================================================================
CLICK TO ENLARGE
The below Amibroker AFL for Moving Average Crossover is a 5 SMA crossing the
9 SMA. The Buy or Sell Arrows are shown on the closing candle at the crossover point.
Entries made on basis of Moving Average Crossover may turn out to be loss making
in sideways markets. So Trend should always be taken into account when such
crossover trades are being initiated.
When the Low Moving Average crosses the Higher Moving Average [Above or Below]
the trade is initiated in the direction of the crossover. That is if 5 SMA crosses 9 SMA
from above then a sell trade is to be initiated and when 5 SMA crosses the 9 SMA from below
then Long trade has to be initiated.
For reference an image has been posted below the post.
===========================Copy The Code Below============================
_SECTION_BEGIN("SMA5X9");
MA5 = MA(C, 5);
MA9 = MA(C, 9);
Buy = Cross(MA5, MA9);
Sell = Cross(MA9, MA5);
Filter = Buy OR Sell;
Buy = ExRem(Buy, Sell);
Sell =ExRem(Sell, Buy);
trigger = WriteIf(Buy, "BUY", WriteIf(Sell, "SELL", " "));
fg = IIf(Buy, colorDarkGreen, IIf(Sell, colorRed, colorDefault));
bg = IIf(Buy, colorPaleGreen, IIf(Sell, colorPink, colorDefault));
_N(Title = StrFormat("{{NAME}} {{DATE}} {{INTERVAL}} : O=%1.2f, H=%1.2f, L=%1.2f, C=%1.2f, Vol=%1.0f\n{{VALUES}}", O, H, L, C, V));
if(Status("action") == actionIndicator)
{
PlotOHLC(O, H, L, C, "", colorGrey40, styleCandle);
Plot(MA5, "MA(Close, 5)", colorSeaGreen, styleLine);
Plot(MA9, "MA(Close, 9)", colorRed, styleLine);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-20);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-10);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-15);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=20);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=10);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-15);
}
if(Status("action") == actionExplore)
{
SetOption("NodefaultColumns", True);
AddTextColumn(Name(), "Symbol", 77, colorDefault, colorDefault, 120);
AddColumn(DateTime(), "Date", formatDateTime, colorDefault, colorDefault, 96);
AddTextColumn(trigger, "Signal", 77, fg, bg);
AddColumn(C, "C. M. P.", 1.2, fg, colorDefault, 96);
}
_SECTION_END();
=====================================================================
CLICK TO ENLARGE
अच्छा ब्लॉग है.helping info. मै मॅन्युअली अल्गो करता हु. ये सब बङा मुश्किल लगता है.
ReplyDeleteYou should try using Amibroker Bridge for Algo trades.
Delete