Created
May 4, 2017 18:31
-
-
Save marketcalls/6b46e490cc8e68b4cb167f644dd4b63f to your computer and use it in GitHub Desktop.
Backtesting Basics - EMA Crossover Trading System
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Marketcalls Backtesting Tutorial | |
_SECTION_BEGIN("EMA Crossover Trading System"); | |
SetChartOptions(0,chartShowArrows|chartShowDates); | |
//Plot CandleSticks | |
Plot( C, "Price", ParamColor( "Color", colorDefault ), ParamStyle( "Style", styleCandle, maskPrice ) ); | |
//Compute EMA 20 and EMA50 | |
EMA20 = EMA(C,20); | |
EMA50 = EMA(C,50); | |
//Plot the EMA lines | |
Plot(EMA20,"EMA20",colorGreen,styleLine); //Shorter Length EMA | |
Plot(EMA50,"EMA50",colorblue,styleLine); //Longer Length EMA | |
//Logical Buy and Sell Rules | |
Buy = Cross(EMA20,EMA50); //Positive Crossover | |
sell = Cross(EMA50,EMA20); //Negative Crossover | |
//Short AND Cover for a system which wants to go short | |
//Plot Buy and Sell Arrows | |
/* Plot Buy and Sell Signal Arrows */ | |
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, shapeSquare, shapeNone),colorRed, 0, H, Offset=40); | |
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50); | |
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45); | |
//At what Price to Buy | |
BuyPrice = Close; | |
SellPrice = Close; | |
//Money Management - How much to buy | |
SetPositionSize( 100000, spsValue ); // 1 Lakh in each trade | |
//PositionSize = 100000; | |
//Trade Delays | |
SetTradeDelays(0,0,0,0); | |
_SECTION_END(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment