Special thanks to “George Soros” (Matt Briand) for the original example.

 

ESignal 7.1 example :

 

In order to run this example written in EFS (_Javascript-like) you need to use eSignal 7.1 because of the filesystem / backtesting new features it incorporates.

 

By default the file will be written in eSignal subfolder : FormulaOutput. If you want to change this go to Tools menu and choose settings and change the formula Output Root to whatever you want (for example C:\).

 

Or you can keep the original eSignal settings and change the path of the filename in your BTDefaults.ini in order to read the file from the default C:\Program Files\eSignal\FormulaOutput.

 

You can find more examples on central.esignal.com, in the Automated Trading group.

function preMain() {

setPriceStudy(true);

setStudyTitle("MA15 under/over BT Trading System");

setCursorLabelName("MA15", 0);

// var d = new File("BracketTrader"); // You can use those lines to create a directory

// if (!d.exists()) // does directory exist?

// d.mkDir(); // Create this new directory in FormulaOutput Root

}

var study = new MAStudy(15, 0, "Close", MAStudy.SIMPLE); // We display a simple 15 period moving average.

var f = new File("Trading.txt"); // you can change it to whatever you want

 

function main() {

 

nYear = getValue("year");
nMonth = getValue ("month");
nDay = getValue("day");
nHour = getValue("hour");
nMinute = getValue("minute");
timestamp = (nYear*1000000000)+(nMonth*10000000)+(nDay*100000)+(nHour*1000)+(nMinute*10);

 

var v = study.getValue(MAStudy.MA);

if(v == null)

return;

 

f.open("at+"); // Open and append

if(!f.isOpen()) {

debugPrintln("Could not open!");

}

 

 

if(close() >= v) {

if(!Strategy.isLong()) {

Strategy.doLong("Crossing Up", Strategy.MARKET, Strategy.THISBAR);

f.writeln("cxlplace,BUY,1,MKT,,0,"+ timestamp);

}

 

} else {

if(!Strategy.isShort()) {

Strategy.doShort("Crossing Down", Strategy.MARKET, Strategy.THISBAR);

f.writeln("cxlplace,SELL,1,MKT,,0,"+ timestamp);

}

}

 

if (Strategy.isLong()) {

setBarBgColor(Color.green);

} else if(Strategy.isShort()) {

setBarBgColor(Color.red);

}

f.close();

return v;

}

 

 

Download

 

Community

 

Blog

 

Locations of visitors to this page