Friday, February 25, 2011

Maximum profits indicator

Here it is: the Matlab code for "ais" indicator, as I've commented in a previous post.



function [long short] = ais(HLOC, timeframe, pips)
%
% ais
%
% [long short] = ais(HLOC, timeframe, pips)
%
% Indicator of maximum profit for each moment open a position in just
% this moment
%
% Parameters:
% HLOC, matrix with High,Low,Open,Close prices values in columns.
% timeframe, size of the window to before closing the position
% pips, spread between opening and closing position
%
% Output:
%
%
[p1 p2] = size(HLOC);

long = [];
short = [];
for ii=1:p1-timeframe
% Long positions
profit = -inf;
for jj=ii+1:ii+timeframe
profit2 = (HLOC(jj,1) - HLOC(ii,3)-pips)/HLOC(ii,3);
if profit2 > profit
profit = profit2;
end
end
long = [long
profit];

% Short positions
profit = -inf;
for jj=ii+1:ii+timeframe
profit2 = (HLOC(jj,3) - HLOC(ii,2)-pips)/HLOC(ii,3);
if profit2 > profit
profit = profit2;
end
end
short = [short
profit];
end

No comments:

Post a Comment