#include <r.h>
function run()
{
set(PLOTNOW+PARAMETERS+LOGFILE);
BarPeriod = 1440;
LookBack = 100;
MaxLong = MaxShort = 1;
int size = optimize(50,10,100);
if(Init) {
if(!Rstart())
return quit("Error - R won't start!");
Rx("rm(list = ls());"); // clear the workspace
Rx("library(tseries)"); // load time series library
}
if(is(LOOKBACK)) return;
Rset("Data",rev(seriesC(),size),size); // send Close series to R
Rx("ADF = adf.test(Data)"); // Augmented Dickey-Fuller test
var adf = Rd("ADF$p.value");
if(adf > 0.6) enterLong();
if(adf < 0.6) exitLong();
plot("ADF p-value", adf ,NEW,RED); //display p-value
}