Proper video demo of technical analysis trend line via regression in Matlab with source code

(Last Updated On: September 30, 2014)

Proper video demo of technical analysis trend line via regression in Matlab with source code

I finally achieved this via a simple regression line, why oh why do I complicated things unecessarily ? This is my of internal trading system

Join my FREE newsletter to see how I progress with this new system I am working on


Source code:

function [ clrev ] = fetchYahoo( sym )
%FETCHYAHOO Summary of this function goes here
%   Detailed explanation goes here
c = yahoo;
d = fetch(c,sym,’1/1/2010′,’9/29/2014′)
cl=d(:,5); %close


function trendline(Y1)
%  Y1:  vector of y data

%  Auto-generated by MATLAB on 30-Sep-2014 00:06:07

% Create figure
figure1 = figure;

% Create axes
axes1 = axes(‘Parent’,figure1);

% Create plot
plot1 = plot(Y1,’Parent’,axes1,’DisplayName’,’data1′);

% Get xdata from plot
xdata1 = get(plot1, ‘xdata’);
% Get ydata from plot
ydata1 = get(plot1, ‘ydata’);
% Make sure data are column vectors
xdata1 = xdata1(:);
ydata1 = ydata1(:);

% Remove NaN values and warn
nanMask1 = isnan(xdata1(:)) | isnan(ydata1(:));
if any(nanMask1)
    warning(‘GeneratedCode:IgnoringNaNs’, …
        ‘Data points with NaN coordinates will be ignored.’);
    xdata1(nanMask1) = [];
    ydata1(nanMask1) = [];

% Find x values for plotting the fit based on xlim
axesLimits1 = xlim(axes1);
xplot1 = linspace(axesLimits1(1), axesLimits1(2));

fitResults1 = polyfit(xdata1, ydata1, 1);
% Evaluate polynomial
yplot1 = polyval(fitResults1, xplot1);
% Plot the fit
fitLine1 = plot(xplot1,yplot1,’DisplayName’,’   linear’,’Parent’,axes1,…
    ‘Color’,[1 0 0]);

% Set new line in proper position
setLineOrder(axes1, fitLine1, plot1);

% Create legend

function setLineOrder(axesh1, newLine1, associatedLine1)
%  Set line order
%  AXESH1:  axes
%  NEWLINE1:  new line
%  ASSOCIATEDLINE1:  associated line

% Get the axes children
hChildren = get(axesh1,’Children’);
% Remove the new line
hChildren(hChildren==newLine1) = [];
% Get the index to the associatedLine
lineIndex = find(hChildren==associatedLine1);
% Reorder lines so the new line appears with associated data
hNewChildren = [hChildren(1:lineIndex-1);newLine1;hChildren(lineIndex:end)];
% Set the children:


NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.
Scroll to Top