MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

### Discover what MATLAB® can do for your career.

 Subject: MACD Trading system starting Long only From: dpb Date: 7 Jul, 2012 13:24:16 Message: 3 of 15 On 7/7/2012 8:05 AM, dpb wrote: ... > logic of the loops can be written as== > > TS=zeros(size(S)); TS(1,:)=[]; % prefill 1 column smaller > P=S>L; M=L TS(P(2:end,:)&M(1:end-1,:))=-1; % Buy signal > TS(~P(2:end,:)&~M(1:end-1,:))=1; % and Sell is complement... ... Just slightly more concisely... P=S>L; P(1,:)=[]; % logic vectors for changes M=L
 Subject: MACD Trading system starting Long only From: dpb Date: 7 Jul, 2012 19:34:28 Message: 4 of 15 On 7/7/2012 8:24 AM, dpb wrote: > On 7/7/2012 8:05 AM, dpb wrote: ... > Still no magic for the final cleanup, sorry... :) But, the "straight ahead" solution looks something like-- for i=1:size(TS,1)    TS(i,1:find(TS(i,:)==-1,1,'first')-1)=0; end --
 Subject: MACD Trading system starting Long only From: Jelle Date: 8 Jul, 2012 16:05:08 Message: 5 of 15 dpb wrote in message ... > On 7/7/2012 8:24 AM, dpb wrote: > > On 7/7/2012 8:05 AM, dpb wrote: > ... > > > Still no magic for the final cleanup, sorry... :) > > But, the "straight ahead" solution looks something like-- > > for i=1:size(TS,1) > TS(i,1:find(TS(i,:)==-1,1,'first')-1)=0; > end > > -- Okay I used the following now, as you suggested: for i=1:size(Tradesignal,1)    TradeSignal(i,1:find(TradeSignal(i,:)==1,1,'first')-1)=0; end Unfortunately TradeSignal still starts with a '1', being a short trade. Furthermore I was wondering because I do not fully understand the code ( I tried to find out using 'help find' but did not figure it ou yet. I understand that the code says find TradeSignal==1 but what does the ,1 do? than 'first' means finding the first '1' in the vector, than -1 is the replace i guess... and what does the =0 at the end. Thanks for all the help!
 Subject: MACD Trading system starting Long only From: Jelle Date: 9 Jul, 2012 08:53:07 Message: 7 of 15 %% attempt 1 Loop here, then: TradeSignal(i,1:find(TradeSignal(i,:)==-1,1,'first')-1)=0; % error: ??? Subscript indices must either be real positive integers or logicals. %% attempt 2 TradeSignal=zeros(size(Long)); TradeSignal(1,:)=[]; % prefill 1 column smaller P=Short>Long; M=LongLong; P(1,:)=[]; % logic vectors for changes M=Long
 Subject: MACD Trading system starting Long only From: dpb Date: 9 Jul, 2012 13:00:05 Message: 9 of 15 On 7/9/2012 7:27 AM, dpb wrote: ... > > Question--what does > > any(TS==TradeSignal(:,2:end)) > > return in the debugger when finish? Should (and I bet is) == 1 ... ERRATA... all(TS==TradeSignal(:,2:end)) not 'any' Suggestion--use the debugger and halt at this point and look manually at a small subsection that can see in a glance--- If you look at elements of the logic condition tests you wrote if (S(k)>L(k) & S(k-1) S>L and M --> L
 Subject: MACD Trading system starting Long only From: dpb Date: 9 Jul, 2012 13:15:20 Message: 10 of 15 On 7/9/2012 8:00 AM, dpb wrote: > On 7/9/2012 7:27 AM, dpb wrote: ... > If you look at elements of the logic condition tests you wrote > > if (S(k)>L(k) & S(k-1) > it should be clear that P --> S>L and M --> L S>L and M --> S a) are the same except all values are in the two vector arrays instead > of one column at a time in the loop and then ...
 Subject: MACD Trading system starting Long only From: dpb Date: 9 Jul, 2012 13:45:53 Message: 11 of 15 On 7/9/2012 7:27 AM, dpb wrote: > On 7/9/2012 3:53 AM, Jelle wrote: ... >> P=Short>Long; P(1,:)=[]; % logic vectors for changes >> M=Long> TradeSignal(P&&M)=-1; % Buy signal >> TradeSignal(~P&&~M)=1; % and Sell is complement... >> >> Error: ??? Operands to the || and && operators must be convertible to >> logical scalar values. >> >> am I making a mistake again? Also what does P(1,:)=[]; do? > > I screwed up there; '&&' should be '&' > > P(1,:)=[]; just throws away the first column... I blew that in the first posting and have been copying it around ever since... :( _THAT_ as written of course actually throws away the first row and the other as written killed the last...totally wrong. I should have cut'n pasted the test code from my command window instead of retyping it from scratch. I interchanged the row and column array indices and thereby screwed up royally... :( Sorry, mea culpa...should be P=Short>Long; P(:,1)=[]; M=Long TS(P(2:end,:)&M(1:end-1,:))=-1; > TS(~P(2:end,:)&~M(1:end-1,:))=1; should have been TS(P(:,2:end) & M(:,1:end-1))=-1; TS(~P(:,2:end)&~M(:,1:end-1))=1; to adjust the column offsets. --
 Subject: MACD Trading system starting Long only From: Jelle Date: 14 Jul, 2012 09:55:09 Message: 13 of 15 dpb wrote in message ... > On 7/9/2012 3:53 AM, Jelle wrote: > > %% attempt 1 > > > > Loop here, then: > > > > TradeSignal(i,1:find(TradeSignal(i,:)==-1,1,'first')-1)=0; > > % error: ??? Subscript indices must either be real positive integers or > > logicals. > > > > %% attempt 2 > > ...[elided for brevity; for reasons explained below there's no need for > it]... > Okay perfect it works now. Although I get better returns starting short (ofcourse this is in no way your fault!) Thanks for all the great help!
 Subject: MACD Trading system starting Long only From: dpb Date: 14 Jul, 2012 14:09:48 Message: 14 of 15 On 7/14/2012 4:55 AM, Jelle wrote: ... > Okay perfect it works now. Although I get better returns starting short > (ofcourse this is in no way your fault!) > > Thanks for all the great help! No Prob! Glad to...I'll not gloat and say "told ya'!" but... OK, I'm still curious if you did use the vectorized solution for the table to replace your loop solution as well...it's just so cute your prof is bound to like it! :) --
 Subject: MACD Trading system starting Long only From: Jelle Date: 15 Jul, 2012 10:00:12 Message: 15 of 15 dpb wrote in message ... > On 7/14/2012 4:55 AM, Jelle wrote: > ... > > > Okay perfect it works now. Although I get better returns starting short > > (ofcourse this is in no way your fault!) > > > > Thanks for all the great help! > > No Prob! Glad to...I'll not gloat and say "told ya'!" but... > > OK, I'm still curious if you did use the vectorized solution for the > table to replace your loop solution as well...it's just so cute your > prof is bound to like it! :) Yes but some guy in a movie once taught me: Greed is good. Therefore it is now out of my script..