# Discussion of article "Deep neural network with Stacked RBM. Self-training, self-control" - page 6

14

First, you need to output the value of the variable from R to MT4 (for example, Rgi () if the variable int). Then in MT4 write print (""). The result is in the "Expert" tab

It works!

Thanks and Best

Akos

4693

Akos Kiss :

It works!

Thanks and Best

Akos

Hi Akos

Experiment.

Good luck

50

Here it is.

thanks for your explanation,Now I can understand your brillant articles! eh, but still some questions to be clear, I hope this won't bother you. I will try my best to learn from it.

1 by the last question, Now I can see your opinion.

shift the signal by one bar to the left (towards future).

In this do you mean that the subtraction is executed like this??

dz[1]=zz[2]-zz[1]

dz[2]=zz[3]-zz[2]

dz[3]=zz[4]-zz[3]

But the dplyr::lead()) didn't appear in the code attached to your articles. the code related is as follows,

nowhere is the moving to the left, should I change the form.data foo by myself?

///////////////////

ZZ <- function(pr = price, ch = ch , mode="m")

{

zz <- ZigZag(pr, change = ch, percent = F, retrace = F, lastExtreme = T)

n <- 1:length(zz)

dz <- zz %>% diff %>% c(., NA)

sig <- sign(dz)

for (i in n) { if (is.na(zz[i])) zz[i] = zz[i - 1]}

return(cbind(zz, sig)) }

form.data <- function(n = 16, z = 37, len = 500)

{data <- cbind(x, y = out[ ,2]) %>% as.data.frame %>% head(., (nrow(x)-len))%>% na.omit

data\$y <- as.factor(data\$y) return(data) }

///////////////////////

2 the second question is In form.data foo we have left out the test data(500) already,

form.data <- function(n = 16, z = 37, len = 500)

then why in prepareBest and prepareTrain split them again??

idx <- rminer::holdout(y = data.f\$y)

and in prepareBest the holdout ratio is 2/3 but the prepareTrain's ratio is 501 and the others, why?

and tricky thing that I found the data holdout in prepareTrain is randomly selected for testAcc, is that right?

the sequence of holdout and preProcess, should we seperate the train and test datasets first then preProcess the train data only

or should we preProcess all the data then seperate the data with holdout?

my question is , when the model is actually running,the data put into it is not preProessed, is it right?

4 last question, hope you read here through. the tp and sl 's config is somehow not met even the moveing direction of the market is right,

any hint on config them by custom making?

After live trading I find the SAEDN is trading too frequently and RBMDN's accuracy is a bit low, any thing wrong about my trading?

thanks

50

I found that in form.data the sequence of the In(x) is not changed; for example, after the following code the sequence is started from for example, 68 69 ....

data <- cbind(x, y = out[ ,2]) %>% as.data.frame %>% head(., (nrow(x)-len))%>% na.omit

and in prepareTest  after

x <- In(p = n ) %>% na.omit %>% extract( ,best) %>% tail(., len)

the sequence is renew from 1 2 3 4 ....

50

sorry it's me again

in foo correct <- function(sig)

{

sig <- Lag(sig) %>% na.omit  //this transforms sig from 501 to 500, just cut off the last one, maybe good to write sig <- sig[1:500] ?

bal <- cumsum(sig * (price[ ,6] %>% tail(.,length(sig))))

my point is, the sequence of sig and price[ ,6] %>% tail(.,length(sig)) is not the same

for example,

sig 1 2 3 4 5 6 ...   500 501

pri    1 2 3 4 5 6 .. 499 500.

even though 501 cutoff, the sig(2) should be the sig for price (1)

but the bal is calculating it with sig(i)*price(i), is that right?

should the sig predict for the current bar?

thanks

4693

vxgu86 :

жаль, что это я снова

в foo правильная <- функция (sig)

{

sig <- Lag (sig)%>% na.omit // это преобразует sig от 501 до 500, просто отключил последний, может быть, хорошо написать sig <- sig [1: 500]?

bal <- cumsum (sig * (цена [, 6]%>% tail (., length (sig))))

моя точка зрения, последовательность sig и цена [, 6]%>% tail (., length (sig)) не то же самое

например,

sig 1 2 3 4 5 6 ... 500 501

pri 1 2 3 4 5 6 .. 499 500.

даже если отсечка 501, сиг (2) должен быть сиг для цены (1)

но бал вычисляет его с помощью sig (i) * price (i), так ли это?

должен ли sig предсказать текущий бар?

благодаря

When preparing the data for training, we shift the target to the left by one bar.

When calculating the balance, we must move the predicted signal back, one bar to the right. Because having received a signal on the current bar, the result we get on the next.

I hope I understood clearly.

Good luck

50

thanks, I will try my best to understand it

and another question that I could not make it clear is still the correct foo

# summarize two vectors

dbr <- (roc + dbal) %>% as.matrix()

# calculate correction signal

sig.cor <- ifelse(dbr > 0, 1, -1) # sign(dbr) gives the same result

# resulting signal

S <- sig.cor * tail(sig, length(sig.cor))

for example

sig is -1, sig.cor is -1, the multiple get 1, is that right?

for the sig.cor, is 1 mean up and -1 mean down?

4693

vxgu86 :

спасибо, я постараюсь изо всех сил понять это

и еще один вопрос, который я не мог прояснить, по-прежнему верен foo

# суммировать два вектора

dbr <- (roc + dbal)%>% as.matrix ()

# рассчитать сигнал коррекции

sig.cor <- ifelse (dbr> 0, 1, -1) # sign (dbr) дает тот же результат

# результирующий сигнал

S <- sig.cor * tail (sig, length (sig.cor))

например

sig равно -1, sig.cor равно -1, множественный get 1, это правильно?

для sig.cor, означает 1 среднее значение и -1 означает вниз?

The meaning of the correction signal: if the correction signal = +1, we fulfill the predicted signal. If the correction signal is -1, then change the execution signal to the opposite one.
50

concerning on the mismatch problem!!!! I am confused on the signal and price['CO'] match, could you see it through

calculate the ball from zigzag for last 500 lines[ with one signal left out]

out <- ZZ(ch = z, mode = "m")[ ,2]

new.y<-tail(out, 501)[1:500]  ##is this right，

bal.zz <- cumsum(new.y * (price[ ,'CO']%>% tail(.,length(new.y))))

testBal for last 500 lines( DT.test is from prepareTest with last 501 lines)[ with one signal left out]

x <- DT.test[ ,best]

CO <- DT.test\$CO

out <- predict(obj, newdata = x, type = typ)

if(soft){out <- max.col(out)-1} else {out %<>% as.vector()}

sig <- ifelse(out == 0, -1, 1)

sig1 <- Lag(sig) %>% na.omit

bal <- cumsum(sig1 * tail(CO, length(sig1)))

bal from correct is calculated exactly as in testBal with difference that has been corrected and the number of signal is 497,right?

correct <- function(sig)

{

#sig <- sig[1:500] #same as next line?

sig <- Lag(sig) %>% na.omit

bal <- cumsum(sig * (price[ ,6] %>% tail(.,length(sig))))

...

dbal <- (bal - ma) %>% tail(., length(roc))

dbr <- (roc + dbal) %>% as.matrix()

sig.cor <- sign(dbr)

S <- sig.cor * tail(sig, length(sig.cor))

bal after pre.sig with difference from correct() that last signal is predicted with markovchain, so it's 498 signals

the last signal is meant to be sent to EA，not in the area of calculating bal,right?

In the pic below,the lines above are from zigzag in black and correct()

the green is after smooth, the blue is after network predict and the red is ma of bal. is this right

50

funny thing that the nimber of k lines cannot exceed 100 when I test it in EA, It always crash when variable i goes up to 100

for(i = 0; i < lim; i++)

{

Print("lim:"+lim+"i:"+i);

o[i]  = Open[i+1];

hi[i] = High[i+1];

lo[i] = Low[i+1];

clo[i]= Close[i+1];

}

below is the log, is there sth that I missed?

1 21:25:36.646 TestGenerator: unmatched data error (volume limit 2630 at 2017.10.04 15:00 exceeded)

1 21:25:36.646 TestGenerator: unmatched data error (volume limit 2630 at 2017.10.04 15:00 exceeded)

1 21:25:36.646 TestGenerator: unmatched data error (volume limit 2630 at 2017.10.04 15:00 exceeded)

2 21:25:36.709 1970.01.01 00:00:00  e_DNSAE inputs: Lots=0.1; TakeProfit=50; StopLoss=45; magic=654321; cor=3; n=34; z=37; soft=1; Kmin=10; limit=1000;

0 21:25:37.398 2017.05.17 10:00:00  e_DNSAE AUDCHF,H1: 1

0 21:25:37.409 2017.05.17 10:00:00  e_DNSAE AUDCHF,H1: lim:1000i:0

0 21:25:37.409 2017.05.17 10:00:00  e_DNSAE AUDCHF,H1: lim:1000i:1

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

0 21:25:37.409 2017.05.17 10:00:00  e_DNSAE AUDCHF,H1: lim:1000i:100

1 21:25:37.409 2017.05.17 10:00:00  e_DNSAE AUDCHF,H1: array out of range in 'e_DNSAE.mq4' (143,22)

3 21:25:37.409 2017.05.17 10:00:00  Testing pass stopped due to a critical error in the EA

0 21:25:37.409 AUDCHF,H1: 1 tick events (2466 bars, 8359005 bar states) processed in 0:00:00.703 (total time 0:00:45.469)