function drawDirectSystem(hist_dates, hist_high, hist_low, hist_close)

dates = hist_dates;

vout = indicators([hist_high,hist_low,hist_close],'adx',13)

     pdi = vout(:,1);
     mdi = vout(:,2);
     adx = vout(:,3);

pdi_out = fints(dates, pdi)
mdi_out = fints(dates, mdi)
adx_out = fints(dates, adx)

%plot(1:length(pdi_out),pdi_out,'--g',1:length(mdi_out),mdi_out,':b',1:length(adx_out),adx_out,'r')

%just draw Directional System.
p2 = plot(pdi_out,'--g')
title('Directional system')
hold on
set(p2,'LineWidth', 2)
p3 = plot(mdi_out,':b')
set(p3,'LineWidth', 2)
p4 = plot(adx_out,'r')
set(p4,'LineWidth', 2)

ylabel({'Directional system'})
xlabel({'Timeline'})

legend('+DI13','-DI13','ADX')

NumTicks = 18;
L = get(gca,'XLim');

set(gca,'XTick',linspace(L(1),L(2),NumTicks))

% set(get(gca,'XLabel'),'Rotation',270)
dateaxis('x', 2)

%fileID = fopen('directionalSystem_hist3ADX3.txt','wt');
flag = 'calm'

%--------------TRITYDENNI s TRItydenni ADX-----------
for i = 3:length(pdi)    
    pdi_last_value = pdi(i)
    pdi_pre_last_value = pdi(i - 1)
    pdi_pre_pre_last_value = pdi(i - 2)
    
    mdi_last_value = mdi(i)
    mdi_pre_last_value = mdi(i - 1)
    mdi_pre_pre_last_value = mdi(i - 2)
    
    adx_last_value = adx(i)
    adx_pre_last_value = adx(i - 1)
    adx_pre_pre_last_value = adx(i - 2)
    
    today = dates{i}
    
    %pokud ADX roste tri hodnoty po sobe a +DI se drzi nad -DI, tak je zdravy trend rostouc
    if (pdi_pre_pre_last_value >= mdi_pre_pre_last_value && pdi_pre_last_value >= mdi_pre_last_value && pdi_last_value >= mdi_last_value && adx_pre_pre_last_value < adx_pre_last_value && adx_pre_last_value < adx_last_value)
        flag = 'increasing trend'
    %pokud ADX roste tri hodnoty po sobe a -DI se drzi nad +DI, tak je zdravy trend klesajici   
    elseif(pdi_pre_pre_last_value <= mdi_pre_pre_last_value && pdi_pre_last_value <= mdi_pre_last_value && pdi_last_value <= mdi_last_value && adx_pre_pre_last_value < adx_pre_last_value && adx_pre_last_value < adx_last_value)
       flag = 'decreasing trend'
    else flag = 'calm'
    end
 
% nbytes = fprintf(fileID,'day : %s, flag - %s\n', today, flag)
end
%fclose(fileID);


%--------------DVOUTYDENNI s TRItydenni ADX-----------
%fileID = fopen('directionalSystem_hist2ADX3.txt','wt');
flag = 'calm'

for i = 3:length(pdi)    
    pdi_last_value = pdi(i)
    pdi_pre_last_value = pdi(i - 1)
    
    mdi_last_value = mdi(i)
    mdi_pre_last_value = mdi(i - 1)
    
    adx_last_value = adx(i)
    adx_pre_last_value = adx(i - 1)
    adx_pre_pre_last_value = adx(i - 2)
    
    today = dates{i}
    
    %pokud ADX roste dve hodnoty po sobe a +DI se drzi nad -DI, tak je zdravy trend rostouc
    if (pdi_pre_last_value >= mdi_pre_last_value && pdi_last_value >= mdi_last_value && adx_pre_pre_last_value < adx_pre_last_value && adx_pre_last_value < adx_last_value)
        flag = 'increasing trend'
    %pokud ADX roste dve hodnoty po sobe a -DI se drzi nad +DI, tak je zdravy trend klesajici   
    elseif(pdi_pre_last_value <= mdi_pre_last_value && pdi_last_value <= mdi_last_value && adx_pre_pre_last_value < adx_pre_last_value && adx_pre_last_value < adx_last_value)
       flag = 'decreasing trend'
    else flag = 'calm'
    end
 
 %nbytes = fprintf(fileID,'day : %s, flag - %s\n', today, flag)
end
%fclose(fileID);


%--------------DVOUTYDENNI s DVOUtydenni ADX-----------
%fileID = fopen('directionalSystem_hist2ADX2.txt','wt');
flag = 'calm'
%filename = 'DirectSystemdata.xlsx';

for i = 2:length(pdi)    
    pdi_last_value = pdi(i)
    pdi_pre_last_value = pdi(i - 1)
    
    mdi_last_value = mdi(i)
    mdi_pre_last_value = mdi(i - 1)
    
    adx_last_value = adx(i)
    adx_pre_last_value = adx(i - 1)
        
    today = dates{i}
    
    %pokud ADX roste dve hodnoty po sobe a +DI se drzi nad -DI, tak je zdravy trend rostouc
    if (pdi_pre_last_value >= mdi_pre_last_value && pdi_last_value >= mdi_last_value && adx_pre_last_value < adx_last_value)
        flag = 'increasing trend'
    %pokud ADX roste dve hodnoty po sobe a -DI se drzi nad +DI, tak je zdravy trend klesajici   
    elseif(pdi_pre_last_value <= mdi_pre_last_value && pdi_last_value <= mdi_last_value && adx_pre_last_value < adx_last_value)
       flag = 'decreasing trend'
    else flag = 'calm'
    end
    
   % A = {'day', today, 'pdi_pre_last_value', pdi_pre_last_value, 'pdi_last_value' , pdi_last_value, 'mdi_pre_last_value', mdi_pre_last_value, 'mdi_last_value', mdi_last_value, 'adx_pre_last_value', adx_pre_last_value, 'adx_last_value', adx_last_value, 'flag', flag}
   % sheet = 1;
   % xlswrite(filename,A,sheet,strcat('A',num2str(i)));

 %nbytes = fprintf(fileID,'day : %s, flag - %s\n', today, flag)
end
%fclose(fileID);

%--------------DVOUTYDENNI BEZ ADX-----------
%fileID = fopen('directionalSystem_hist2ADX2.txt','wt');
flag = 'calm'
filename = 'DirectSystemdata.xlsx';

for i = 2:length(pdi)    
    pdi_last_value = pdi(i)
    pdi_pre_last_value = pdi(i - 1)
    
    mdi_last_value = mdi(i)
    mdi_pre_last_value = mdi(i - 1)
        
    today = dates{i}
    
    %pokud ADX roste dve hodnoty po sobe a +DI se drzi nad -DI, tak je zdravy trend rostouc
    if (pdi_pre_last_value >= mdi_pre_last_value && pdi_last_value >= mdi_last_value)
        flag = 'increasing trend'
    %pokud ADX roste dve hodnoty po sobe a -DI se drzi nad +DI, tak je zdravy trend klesajici   
    elseif(pdi_pre_last_value <= mdi_pre_last_value && pdi_last_value <= mdi_last_value)
       flag = 'decreasing trend'
    else flag = 'calm'
    end
    
    A = {'day', today, 'pdi_pre_last_value', pdi_pre_last_value, 'pdi_last_value' , pdi_last_value, 'mdi_pre_last_value', mdi_pre_last_value, 'mdi_last_value', mdi_last_value, 'flag', flag}
    sheet = 1;
    xlswrite(filename,A,sheet,strcat('A',num2str(i)));

 %nbytes = fprintf(fileID,'day : %s, flag - %s\n', today, flag)
end
%fclose(fileID);