Generate a Valid Trading Signal based on Simple Moving Average
3 views (last 30 days)
Show older comments
I am trying to generate a LONG Trading Signal based on Simple Moving Average(SMA) (using CLOSE prices) using the following rule:
LONG Signal:
close(today) > SMA(today) & close(yesterday) < SMA(today)
Both above statements must be satisfied in order to generate a valid trading signal.
I have attached a picture in which there is a green arrow. That is the point where I should be able to generate a trading signal. Purple line is a 100 days SMA.
The code I am using is as follows:
signal = zeros(numel(close),1);
for i = 2:numel(close)
signal = close(i-1) < sma100 & close > sma100;
end
The above code does create a logical vector but all items are 0(false).
Any help to remedy the above situation would be of great help.
Thank you.
0 Comments
Answers (0)
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!