function drawForceIndex(hist_date, hist_open, hist_close, hist_low, hist_high, hist_vol)

dates = hist_date;
cl = hist_close;
vo = hist_vol;

vout = indicators([cl,vo],'force',2)

     data = vout(:,1);

force_out = fints(dates, data)

%just draw Force Index.
p2 = plot(force_out,'r')
title('Force Index indicator')
hold on
set(p2,'LineWidth', 2)

plot(force_out.dates, 0*ones(1, length(force_out)),... 
'color', [0 0.5 0], 'linewidth', 2)

ylabel({'Force Index'})
xlabel({'Timeline'})
legend('Force Index')
NumTicks = 18;
L = get(gca,'XLim');
set(gca,'XTick',linspace(L(1),L(2),NumTicks))
% set(get(gca,'XLabel'),'Rotation',270)
dateaxis('x', 2)

%---Force index
filename = 'ForceIndexdata.xlsx';
filenameSim = 'ForceIndexSimulation.xlsx';

max_price = 0;
min_price = 0;

flag = {};
flag{1} = 'calm';
flag{2} = 'calm';

fee = 0.2;

inTrade = 0;
inTradeOld = 0;

low = hist_low
high = hist_high
open = hist_open
close = hist_close

inTradeSell = 0;
inTradeBuy = 0;
typeOfTrade = 'calm';

dayClose = 0;
dayOpen = 0;

sell = 0;
oldSell = 0;
oldBuy = 1000000;
buy = 1000000;
stop = -1;

startBudget = 100000;
budget = 100000;
trend = 'no trend';

fileID = fopen('ForceIndexBudget.txt','w');

for i = 3:length(data)    
    last_value = data(i-1)
    pre_last_value = data(i-2)
    last_price = cl(i-1)
    
    today = dates{i}
    
    % EMA13 Trend
%       if(datenum(today) < datenum('02-Mar-2014'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('18-May-2014'))
%           trend = 'increasing';
%       elseif(datenum(today) < datenum('26-Oct-2014'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('04-Jan-2015'))
%           trend = 'increasing';
%       elseif(datenum(today) < datenum('11-Jan-2015'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('18-Jan-2015'))
%           trend = 'increasing';
%       elseif(datenum(today) < datenum('08-Feb-2015'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('22-Feb-2015'))
%           trend = 'increasing';
%       elseif(datenum(today) < datenum('01-Mar-2015'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('08-Mar-2015'))
%           trend = 'increasing';
%       elseif(datenum(today) < datenum('29-Mar-2015'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('05-Apr-2015'))
%           trend = 'increasing';
%       elseif(datenum(today) < datenum('28-Jun-2015'))
%           trend = 'decreasing';
%       elseif(datenum(today) < datenum('26-Jul-2015'))
%           trend = 'increasing';
%       else
%           trend = 'decreasing';
%       end    


%     %Directional system
%     if(datenum(today) < datenum('06-Apr-2014'))
%         trend = 'decreasing';
%     elseif(datenum(today) < datenum('13-Apr-2014'))
%         trend = 'no ternd';
%     elseif(datenum(today) < datenum('18-May-2014'))
%         trend = 'increasing';
%     elseif(datenum(today) < datenum('25-May-2014'))
%         trend = 'no ternd';
%     elseif(datenum(today) < datenum('16-Nov-2014'))
%         trend = 'decreasing';
%     elseif(datenum(today) < datenum('23-Nov-2014'))
%         trend = 'no trend';
%     elseif(datenum(today) < datenum('30-Nov-2014'))
%         trend = 'increasing';
%     elseif(datenum(today) < datenum('14-Dec-2014'))
%         trend = 'no trend';
%     elseif(datenum(today) < datenum('04-Jan-2015'))
%         trend = 'increasing';
%     elseif(datenum(today) < datenum('11-Jan-2015'))
%         trend = 'no trend';
%     elseif(datenum(today) < datenum('28-Jun-2015'))
%         trend = 'decreasing';
%     elseif(datenum(today) < datenum('05-Jul-2015'))
%         trend = 'no trend';
%     elseif(datenum(today) < datenum('02-Aug-2015'))
%         trend = 'increasing';
%     elseif(datenum(today) < datenum('09-Aug-2015'))
%         trend = 'no trend';
%     else
%         trend = 'decreasing';
%     end

%MACD
%      if(datenum(today) < datenum('12-Jan-2014'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('19-Jan-2014'))
%          trend = 'increasing';
%      elseif(datenum(today) < datenum('02-Feb-2014'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('20-Apr-2014'))
%          trend = 'increasing';
%      elseif(datenum(today) < datenum('18-May-2015'))
%          trend = 'increasing';
%      elseif(datenum(today) < datenum('01-Jun-2014'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('12-Oct-2014'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('18-Jan-2015'))
%          trend = 'increasing';
%      elseif(datenum(today) < datenum('08-Feb-2015'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('08-Mar-2015'))
%          trend = 'increasing';
%      elseif(datenum(today) < datenum('29-Mar-2015'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('05-Apr-2015'))
%          trend = 'increasing';
%      elseif(datenum(today) < datenum('28-Jun-2015'))
%          trend = 'decreasing';
%      elseif(datenum(today) < datenum('26-Jul-2015'))
%          trend = 'increasing'; 
%      elseif(datenum(today) < datenum('02-Aug-2015'))
%          trend = 'decreasing';     
%      else
%          trend = 'decreasing';
%      end

% EMA13 - Out of sample 1.9.2015 - 1.5.2016
      if(datenum(today) < datenum('13-Sep-2015'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('20-Sep-2015'))
          trend = 'increasing';
      elseif(datenum(today) < datenum('27-Sep-2015'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('18-Oct-2015'))
          trend = 'increasing';
      elseif(datenum(today) < datenum('01-Nov-2015'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('08-Nov-2015'))
          trend = 'increasing';
      elseif(datenum(today) < datenum('06-Dec-2015'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('13-Dec-2015'))
          trend = 'increasing';
      elseif(datenum(today) < datenum('31-Jan-2016'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('07-Feb-2016'))
          trend = 'increasing';
      elseif(datenum(today) < datenum('27-Mar-2016'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('03-Apr-2016'))
          trend = 'increasing';
      elseif(datenum(today) < datenum('17-Apr-2016'))
          trend = 'decreasing';
      elseif(datenum(today) < datenum('24-Apr-2016'))
          trend = 'increasing';
      else
          trend = 'decreasing';
      end
   
    if(last_price > max_price)
        max_price = last_price
    
        %medvedi divergence - ceny vzrostou na nove maximum, ale Force Index ukazuje slabnouci
        %medvedu, ptz vytvori mensi vrchol, neboli klesa 
        if(pre_last_value > last_value)
            flag{i-1} = '!!! Bear divergence - sell !!!'    
        end    
    end
    
    if(last_price < min_price)
        min_price = last_price
    
        %byci divergence - ceny klasnou na nove minimum, ale Force Index ukazuje slabnouci
        %medvedu, ptz vytvori melci dno, neboli roste 
        if(pre_last_value < last_value)
            flag{i-1} = '!!! Bull divergence - buy !!!'    
        end    
    end
        
    % Force index pod nulou - spolu s rostoucim trendem nakupovat
    if(pre_last_value >= 0 && last_value < 0)
            flag{i-1} = 'Below zero - buy'
    % Force index nad nulou - spolu s klesajicim trendem prodavat
    elseif(pre_last_value <= 0 && last_value > 0)
            flag{i-1} = 'Above zero - sell'
    else flag{i-1} = 'calm'
    end
    
    % Force index pod nulou - spolu s rostoucim trendem nakupovat
    %if(last_value < 0)
    %       flag{i} = 'Below zero - buy'
    % Force index nad nulou - spolu s klesajicim trendem prodavat
    %elseif(last_value > 0)
    %        flag{i} = 'Above zero - sell'
    %else flag{i} = 'calm'
    %end
 
 %nbytes = fprintf(fileID,'day : %s, pre_last_value : %f, last_value : %f, flag - %s\n', today, pre_last_value, last_value, flag{i}) 
 A = {'day', today, 'trend', trend, last_price', last_price, 'pre_last_value' , pre_last_value, 'last_value', last_value, 'yesterdayFlag', flag{i-1}}
 sheet = 1;
 xlswrite(filename,A,sheet,strcat('A',num2str(i)));
 
 % simulace obchodovani
 % hist_date, hist_open, hist_close, hist_low, hist_high, hist_vol
 %pokud indikator radi nakupovat, nastavim nakupni prikaz
 % na high + 1
 if((strcmp(flag{i-1}, '!!! Bull divergence - buy !!!') == 1) || (strcmp(flag{i-1}, 'Below zero - buy') == 1)) && (inTrade == 0)
     buy = high(i-1) + 1
     sell = 0
     typeOfTrade = 'BUY'
     stop = 1000000
 elseif((strcmp(flag{i-1}, '!!! Bear divergence - sell !!!') == 1) || (strcmp(flag{i-1}, 'Above zero - sell') == 1)) && (inTrade == 0)
 % pokud indikator radi prodavat, nastavim prodejni prikaz
 % na low - 1
     sell = low(i-1) - 1
     buy = 1000000
     typeOfTrade = 'SELL'
     stop = 0
 % else
   %  typeOfTrade = 'calm'
 end
 
 % dlouha pozice - nakup
 %vystup z dlouhe pozice - pokud dnes ceny uzavrou pod urovni stop loss, tak se obchod automaticky uzavre  
 if(inTradeBuy == 1) && ((close(i) <= stop) || (open(i) <= stop) || i == length(data))
     inTradeOld = inTrade
     inTradeBuy = 0
     inTrade = 0
     typeOfTrade = 'calm'
     dayClose = today
     budget = budget + ((stop - buy) * 50);
     sell = 0
     buy = 10000000
% vstup do dlouhe pozice - kdyz behem dne ceny protnou prikaz buy (vzrostou na hodnotu buy), tak automaticky vstoupim do obchodu   
 elseif((low(i) >= buy) || (high(i) > buy)) && (inTrade == 0) && (strcmp(trend, 'increasing') == 1) && (strcmp(typeOfTrade, 'BUY') == 1);
    inTradeOld = inTrade
    inTrade = 1;
    inTradeBuy = 1;
    dayOpen = today;
    %budget = budget - buy
    budget = budget - fee
    stop = (min(low(i), low(i-1))) -1
    oldBuy = buy    
 %setrvani v dlouhe pozici a posunuti stop lossu    
 elseif(inTradeBuy == 1)
    stop = low(i-1);
    oldBuy = buy
    inTradeOld = inTrade
 else
 % cekani na vstup do dlouhe pozice    
    oldBuy = buy 
    buy = high(i) + 1;
    %inTradeOld = inTrade
 end
 
 % kratka pozice (prodej)
 %vystup z kratke pozice - pokud dnes ceny uzavrou nad urovni stop loss, tak se obchod automaticky uzavre
 if(inTradeSell == 1) && ((close(i) >= stop) || (open(i) >= stop) || i == length(data))
     inTradeOld = inTrade
     inTradeSell = 0;
     inTrade = 0;
     typeOfTrade = 'calm';
     dayClose = today;
     budget = budget + ((sell - stop) * 50);
     sell = 0;
     buy = 10000000; 
 % vstup do kratke pozice - kdyz behem dne ceny protnou prikaz sell (klesnou na hodnotu sell), tak automaticky vstoupim do obchodu
  elseif((low(i) <= sell) || (high(i) < sell)) && (inTrade == 0) && (strcmp(trend, 'decreasing') == 1) && (strcmp(typeOfTrade, 'SELL') == 1);
     inTradeOld = inTrade
     inTrade = 1;
     inTradeSell = 1;
     dayOpen = today;
     %budget = budget + sell
     budget = budget - fee
     stop = (max(high(i), high(i-1))) + 1;
     oldSell = sell
 % setrvani v kratke pozici    
 elseif(inTradeSell == 1)
     stop = high(i-1)
     oldSell = sell
     inTradeOld = inTrade
 % cekani na vstup do kratke pozice    
 else
     oldSell = sell
     sell = low(i) - 1;
     %inTradeOld = inTrade
 end
 
 if(inTradeOld == 1) && (inTrade == 0)
    nbytes = fprintf(fileID,'day - %s, typeOfTrade - %s, budget - %f\n', today, typeOfTrade, budget);
    inTradeOld = inTrade;
 end    
 
 M = {'today', today, 'trend', trend, 'yesterdayFlag', flag{i-1}, 'dayOpen', dayOpen, 'dayClose', dayClose, 'inTradeOld', inTradeOld, 'inTrade', inTrade, 'typeOfTrade', typeOfTrade, 'inTradeSell', inTradeSell, 'inTradeBuy', inTradeBuy, 'budget', budget, 'budgetDiff', budget - startBudget, 'hist_low', hist_low(i), 'hist_high', hist_high(i), 'oldBuy', oldBuy, 'buy', buy, 'oldSell', oldSell, 'sell', sell, 'stop', stop, 'hist_open', hist_open(i), 'hist_close', hist_close(i)};
     sheet = 1;
     xlswrite(filenameSim,M,sheet,strcat('A',num2str(i)));
end

fclose(fileID);