function [entree,entree_comp,sortie]=RN_target_ochl(date,time,open,close,high,low,nb,e_type,s_type,normalisation,coef_fract,coef_fract_2)

% on utilise les données quotidiennes. 
% nb => délai sur les données d'entrées 
% e_type => type d'entrée : 
%         e_type=1 on prend ochl 
%         e_type=2 on prend c
% s_type => type de sortie : 
%         s_type=1 on prend la taille de la barre positive si haussier, négative si baissière 
%         s_type=2 on prend le sens 1 pour haussier et 0 pour baissier
%         s_type=3 on prend le sens 1 pour haussier et -1 pour baissier
%         s_type=4 on prend c
% normalisation=1 pour normaliser toutes les données entre 0 et 1
% normalisation=2 pour normaliser toutes les données entre -1 et 1, rien si
% ~=1 et 2;
% coef_fract => nb de données utilisées en intraday par les indicateurs 
% coef_fract_2 => nb de données indicateurs intraday utilisées

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% découpage des données

% [lig,col]=find(time==1659);

% date_t=transf_date(date,1);
date_t=date;
j=0;
for i=5:size(date_t,1)
    if date_t(i)==date_t(i-1)+1 && date_t(i)==date_t(i-2)+2 && date_t(i)==date_t(i-3)+3 && date_t(i)==date_t(i-4)+4
        j=j+1;
        lig(j,1)=i;
    end;
end;

ecart=lig(2)-lig(1);
if coef_fract>ecart || coef_fract_2>coef_fract
    errordlg('nombre de données insuffisant','Erreur');
end;

coef=ecart/(floor(ecart/coef_fract));
coef2=floor(ecart/coef_fract);

int_time=zeros(size(lig,1),1);
int_open=zeros(size(lig,1),1);
int_close=zeros(size(lig,1),1);
int_high=zeros(size(lig,1),1);
int_low=zeros(size(lig,1),1);
comp_time=zeros(size(lig,1)*coef,1);
comp_open=zeros(size(lig,1)*coef,1);
comp_close=zeros(size(lig,1)*coef,1);
comp_high=zeros(size(lig,1)*coef,1);
comp_low=zeros(size(lig,1)*coef,1);

for i=1:size(lig,1)
    int_time(i)=time(lig(i));
    int_open(i)=open(lig(i));
    int_close(i)=close(lig(i));
    int_high(i)=high(lig(i));
    int_low(i)=low(lig(i));
    for j=1:coef
        comp_time((i-1)*coef+j)=time(lig(i)-lig(1)+j*coef2);
        comp_open((i-1)*coef+j)=open(lig(i)-lig(1)+j*coef2);
        comp_close((i-1)*coef+j)=close(lig(i)-lig(1)+j*coef2);
        comp_high((i-1)*coef+j)=high(lig(i)-lig(1)+j*coef2);
        comp_low((i-1)*coef+j)=low(lig(i)-lig(1)+j*coef2);
    end;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition du vecteur entree
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if e_type==1 
    entree_init=zeros(4*nb,size(int_close-1,1)-nb);
    for i=nb:size(int_close,1)-1
        for j=1:nb
            entree_init(4*(j-1)+1,i-nb+1)=int_open(i-j+1);
            entree_init(4*(j-1)+2,i-nb+1)=int_close(i-j+1);
            entree_init(4*(j-1)+3,i-nb+1)=int_high(i-j+1);
            entree_init(4*(j-1)+4,i-nb+1)=int_low(i-j+1);
        end;
    end;
end;

if e_type==2 
    entree_init=zeros(1*nb,size(int_close-1,1)-nb);
    for i=nb:size(int_close,1)-1
        for j=1:nb
            entree_init(j,i-nb+1)=int_close(i-j+1);
        end;
    end;
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition du vecteur entree_comp
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rsi_1=rsindex(comp_close,5);
rsi_2=rsindex(comp_close,9);
rsi_3=rsindex(comp_close,14);

[fastK_1, fastD_1]= fpctkd(comp_high,comp_low,comp_close, 9, 3, 'e');
[slowK_1, slowD_1] = spctkd(fastK_1, fastD_1, 3, 'e');
[fastK_2, fastD_2]= fpctkd(comp_high,comp_low,comp_close, 14, 3, 'e');
[slowK_2, slowD_2] = spctkd(fastK_2, fastD_2, 3, 'e');

[macd,moy,diff]=MACD(comp_close,12,26,9);

cci_1=CCI(comp_close,comp_high,comp_low,14);
cci_2=CCI(comp_close,comp_high,comp_low,20);

range=Range(comp_high,comp_low);
mean_range=tsmovavg(range, 's', 10, 1);

body=Body(comp_open,comp_close);
mean_body=tsmovavg(body, 's', 10, 1);

[ombre_h,ombre_b]=Ombres(comp_open,comp_close,comp_high,comp_low);

mean_1=tsmovavg(comp_close, 's', 6, 1);
mean_2=tsmovavg(comp_close, 's', 12, 1);
mean_3=tsmovavg(comp_close, 's', 30, 1);
mean_4=tsmovavg(comp_close, 's', 60, 1);
mean_5=tsmovavg(comp_close, 's', 120, 1);

typical_price=typprice(comp_high,comp_low,comp_close);

% entree_comp_int=[rsi_1 rsi_2 fastK_1 fastD_1...
%     cci_1 cci_2 mean_1 mean_2 macd];

% entree_comp_int=[range body mean_range mean_body...
%     typical_price];

entree_comp_int_1=[mean_1 mean_2 mean_3 mean_4 mean_5];

for i=1:floor(size(entree_comp_int_1,1)/coef)
    inter=entree_comp_int_1((i-1)*coef+1:i*coef,:);
    for j=1:coef_fract_2
        inter_2(j,:)=inter((size(inter,1)/coef_fract_2)*j,:);
    end;
    entree_comp_int(i,:)=reshape(inter_2,1,[]);
end;

for num=1:size(entree_comp_int,1)
    if nnz(entree_comp_int(num,:))==size(entree_comp_int,2)
        break;
    end;
end;
nb2=max(nb,num);
entree_comp=entree_comp_int(nb2:end-1,:)';
entree=entree_init(:,nb2-nb+1:end);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Définition du vecteur sortie
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if s_type==1
    sortie=(int_open(nb2+1:end)-int_close(nb2+1:end))';
end;

if s_type==2
    for i=nb2+1:size(int_close,1)
        if (int_open(i)-int_close(i))>0 
            sortie(i-nb2)=1;
        end;
        if (int_open(i)-int_close(i))<0 
            sortie(i-nb2)=0;
        end;
    end;
end;

if s_type==3
    for i=nb2+1:size(int_close,1)
        if (int_open(i)-int_close(i))>0 
            sortie(i-nb2)=1;
        end;
        if (int_open(i)-int_close(i))<0 
            sortie(i-nb2)=-1;
        end;
    end;
end;

if s_type==4
    sortie=int_close(nb2+1:end)';
end;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Normalisation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if normalisation==1
    for i=1:size(entree,1)
        entree(i,:)=(entree(i,:)-min(entree(i,:)))/(max(entree(i,:))-min(entree(i,:)));
    end;
    for i=1:size(entree_comp,1)
        entree_comp(i,:)=(entree_comp(i,:)-min(entree_comp(i,:)))/(max(entree_comp(i,:))-min(entree_comp(i,:)));
    end;
    sortie=(sortie-min(sortie))/(max(sortie)-min(sortie));
end;

if normalisation==2
    for i=1:size(entree,1)
        entree(i,:)=(2*entree(i,:)-(max(entree(i,:))+min(entree(i,:))))/(max(entree(i,:))-min(entree(i,:)));
    end;
    for i=1:size(entree_comp,1)
        entree_comp(i,:)=(2*entree_comp(i,:)-(max(entree_comp(i,:))+min(entree_comp(i,:))))/(max(entree_comp(i,:))-min(entree_comp(i,:)));
    end;
    sortie=(2*sortie-(max(sortie)+min(sortie)))/(max(sortie)-min(sortie));
end;

