Created
October 19, 2016 16:47
-
-
Save fxborg/b9d451a7ba8d1fadb058b8b406c10601 to your computer and use it in GitHub Desktop.
This file contains 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
// EWMAC Trading /////////////////// | |
#include <profile.c> | |
function run() | |
{ | |
//+----------------------------------------------+ | |
//| Settings | | |
//+----------------------------------------------+ | |
// simulation period 2010-2016 | |
StartDate = 2010; | |
EndDate = 2016; | |
Commission=0; | |
Spread=0.01; | |
PlotWidth = 1200; | |
PlotHeight1 = 400; | |
set(LOGFILE); // log all trades | |
//+----------------------------------------------+ | |
//| Trading Logic | | |
//+----------------------------------------------+ | |
vars Price = series(price()); | |
vars ret = series(Price[0]-Price[1]); | |
vars ema32 = series(EMA(Price,32)); | |
vars ema128 = series(EMA(Price,128)); | |
vars sd = series(StdDev(ret,25)); | |
vars rawdata = series(2.0*(ema32[0]-ema128[0])/sd[0]); | |
vars ewmac = series(max(-20.0,min(20,rawdata[0]))); | |
// Entry | |
if(TradeIsOpen) | |
{ | |
if(ewmac[0]>-5.0 && ewmac[1]<=-5.0) exitShort(); | |
else if(ewmac[0]<5.0 && ewmac[1]>=5.0)exitLong(); | |
} | |
if(!TradeIsOpen) | |
{ | |
if(ewmac[0]>10.0 && ewmac[1]<=10.0) enterLong(); | |
else if(ewmac[0]<-10.0 && ewmac[1]>=-10.0)enterShort(); | |
} | |
set(PLOTNOW); | |
plot("EWMAC",ewmac,NEW,RED); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment