creating a signal without an IF statement

1 回表示 (過去 30 日間)
Aaron Varma
Aaron Varma 2020 年 6 月 18 日
回答済み: David Hill 2020 年 6 月 18 日
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 :)

回答 (1 件)

David Hill
David Hill 2020 年 6 月 18 日
signal(find(fastMA>slowMA & rsi10mins < 65,1):find(fastMA<slowMA & rsi10mins > 35,1)-1) = 1;

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by