Trying to use if to create a table
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have to do this tick test which is classified as:
I have no problem with classifying uptick, downtick and zero tick. But find it quite hard to classify zero-downtick and zero-uptick. I have tried following:
Rows=height(data);
Uptick=sum(data.price(1:end-1)<data.price(2:end));
downtick=sum(data.price(1:end-1)>data.price(2:end));
Zerotick=sum(data.price(1:end-1)==data.price(2:end));
if data.price(1:end-1)<data.price(2:end)
ZeroUptick=sum(data.price(2:end-1)==data.price(3:end))
end
if data.price(1:end-1)>data.price(2:end)
ZeroDowntick=sum(data.price(2:end-1)==data.price(3:end))
end
PrcUptick=Uptick./Rows*100;
PrcDowntick=downtick./Rows*100;
PrcZerotick=Zerotick./Rows*100;
PrcZeroUptick=ZeroUptick./Rows*100;
PrcZeroDowntick=ZeroDowntick./Rows*100;
Isn't it possible to use the if funtion to create this data? Any help to solve this would be very helpfull..
Kind Regard, Emil Petersen.
0 commentaires
Réponses (1)
Jan
le 5 Juin 2022
Remember, that the if condition must be a scalar. You provide a comparison of two vectors:
if data.price(1:end-1)<data.price(2:end)
Then Matlab executes this internally:
if all(data.price(1:end-1) < data.price(2:end)) && ...
~isempty(data.price(1:end-1) < data.price(2:end))
I assume you want something else.
Either use logical indexing. Or create a loop over all "trades" like:
for iTrade = 1:numel(data.price) - 1
if data.price(iTrade) < data.price(iTrade + 1)
...
end
end
0 commentaires
Voir également
Catégories
En savoir plus sur Time Series Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!