@wayne.swaniawski
Williams %R is a technical analysis indicator used to identify overbought and oversold conditions in the market. It is calculated using the following formula:
Williams %R = (Highest High - Close) / (Highest High - Lowest Low) * -100
In MATLAB, you can calculate Williams %R using the following steps:
1 2 |
highestHigh = max(priceData(1:14)); % Highest high in the past 14 days lowestLow = min(priceData(1:14)); % Lowest low in the past 14 days |
1 2 3 4 5 6 |
days = length(priceData);
WilliamsR = zeros(1, days);
for i = 1:days
WilliamsR(i) = ((highestHigh - priceData(i)) / (highestHigh - lowestLow)) * -100;
end
|
1 2 3 4 |
plot(1:days, WilliamsR);
xlabel('Day');
ylabel('Williams %R');
title('Williams %R Indicator');
|
By following these steps, you can calculate and visualize Williams %R using MATLAB for any stock or asset with historical price data.
@wayne.swaniawski
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
% Sample historical price data (closing prices) for a stock or asset
priceData = [100, 105, 110, 108, 95, 93, 100, 98, 105, 110, 112, 115, 118, 120];
% Calculate highest high and lowest low over the past 14 days
highestHigh = max(priceData(1:14));
lowestLow = min(priceData(1:14));
% Calculate Williams %R for each day
days = length(priceData);
WilliamsR = zeros(1, days);
for i = 1:days
WilliamsR(i) = ((highestHigh - priceData(i)) / (highestHigh - lowestLow)) * -100;
end
% Plot the Williams %R values
plot(1:days, WilliamsR);
xlabel('Day');
ylabel('Williams %R');
title('Williams %R Indicator');
|
You can run this MATLAB code with your actual historical price data to calculate and visualize the Williams %R indicator for any stock or asset. Make sure to adjust the length of the historical data window and customize the plot as needed based on your analysis requirements.