creating a signal without an IF statement

1 view (last 30 days)
Aaron Varma
Aaron Varma on 18 Jun 2020
Answered: David Hill on 18 Jun 2020
Hi again everyone
quick question, using the below code, I want the signal to become 1 when certain criteria are met, I want it to stay as a 1 until another set of criteria are met.
I do not want it to revert back to a zero simply because the first set of criteria no longer exist.
How can I tweak my code to accomplish this or must I use the IF function?
signal = zeros(size(eurUSDClose));
signal(fastMA>slowMA & rsi10mins < 65) = 1;
signal(fastMA<slowMA & rsi10mins > 35) = -1;
Thanks for your help and any tips :)

Answers (1)

David Hill
David Hill on 18 Jun 2020
signal(find(fastMA>slowMA & rsi10mins < 65,1):find(fastMA<slowMA & rsi10mins > 35,1)-1) = 1;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!