// Deep Learning Test ///////////////////////////////////////////
//#define DO_SIGNALS // generate sample set in Train mode
//#define DEEPNET
//#define H2O
//#define MXNET
#define KERAS
///////////////////////////////////////////////////////////////////////
#include <r.h>
var change(int n)
{
return scale((priceClose(0) - priceClose(n))/priceClose(0),100)/100;
}
var range(int n)
{
return scale((HH(n) - LL(n))/priceClose(0),100)/100;
}
function DL1()
{
var vLong,vShort;
if(Init) print(TO_WINDOW,"\nR DL1 and Keras required");
Script = "DeepLearnKeras1";
vLong = adviseLong(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4));
vShort = adviseShort(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4));
return vLong;
return vShort;
}
function DL2()
{
var vLong1,vShort1;
if(Init) print(TO_WINDOW,"\nR DL2 and Keras required");
Script = "DeepLearnKeras2";
vLong1 = adviseLong(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4));
vShort1 = adviseShort(NEURAL+BALANCED,0,
change(1),change(2),change(3),change(4),
range(1),range(2),range(3),range(4));
return vLong1;
return vShort1;
}
///////////////////////////////////////////////////////////////////////
function run()
{
NumCores = -1;
StartDate = 20170101;
EndDate= 20190101;
BarPeriod = 1440; // 1 hour
LookBack = 100;
//WFOPeriod = 252*24; // 1 year
//DataSplit = 90;
assetList("AssetsDarwinexFMB");
asset("EUR/USD");
set(RULES);
Spread = RollLong = RollShort = Commission = Slippage = 0;
LifeTime = 3;
if(Train) Hedge = 2;
var Threshold = 0.5;
var vLong,vShort,vLong1,vShort1;
///////////////////////////////////////////////////////////
//SelectWFO = -1; // use the last WFO cycle for calibrating the neural net
set(LOGFILE|PLOTNOW);
while(algo(loop("DeepLearnKeras1","DeepLearnKeras2"))){
if(Algo == "DeepLearnKeras1")
DL1();
if(Algo == "DeepLearnKeras2")
DL2();
if (vLong > Threshold
and vLong1 > Threshold )
enterLong();
if(vShort > Threshold
and vShort1 > Threshold)
enterShort();
plot("Long",vLong,NEW|LINE,BLACK);
plot("Short",vShort,NEW|LINE,GREY);
plot("Long1",vLong1,NEW|LINE,BLUE);
plot("Short1",vShort1,NEW|LINE,RED);
}
}