Thanks Terry, 

Have now got a result. Many many thanks. 

Have inadvertantly left subscripts in from earlier attempts to get it to work 
correctly in a loop.

Agree about recomputation of abs( t1), but wanted to ensure I was getting the 
correct value in the compare. 


Thanks once again.



DJ

 

  ----- Original Message ----- 
  From: Terry 
  To: [email protected] 
  Sent: Saturday, December 02, 2006 4:01 PM
  Subject: RE: [amibroker] Code Help Please



  David,



  A few comments:



  #1 Try removing the [j] and [k] subscripts.

  You have mixed subscripts (used in loop code) and arrays. This won't work as 
expected. The 3rd line (TempL = .)and the next to last line contain subscripts 
[j] plus the line Test2S = which contains [k]. These subscripts will always 
evaluate the single bar for whatever the current value of [j] and [k] are 
(which can't be seen in this code snippet). Maybe you have this whole thing is 
inside a double loop, but then most of the other variables are full arrays and, 
at best, will simply recalculate each time the loop is executed possibly 
causing problems and major slowdown in execution. You really want to use the 
entire array which computes the results for all bars of data simultaneously. 



  #2. Compares are incorrect. You are trying to do compares using = instead of 
==. This will simply reset all your arrays to True instead of comparing which 
== does. 

  Instead of this line:

         XPermLong = IIf(Test1L = True OR Test2L[j] = True OR Test3L[j] = 
True,True, False); 



  Do this instead:

         XPermLong = IIf(Test1L == True OR Test2L == True OR Test3L == 
True,True, False); 



  Or more simply (because True or False is implied):

         XPermLong = IIf(Test1L OR Test2L OR Test3L,True, False);

  (Note that I removed the subscripts in my fixed lines.)



  #3 No problem for results, but you have recomputed several variables which 
takes extra execution time. Example is the 2nd line which could be: 

         inter2 = abs(t1); 



  Also this line where you have already computed inter2, but recomputed it as 
abs(t1): 

         Test1L = IIf(tempL = True  AND abs(t1) < 2, True, False);



  --

  Terry

  -----Original Message-----
  From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of David 
Jennings
  Sent: Saturday, December 02, 2006 05:43
  To: [email protected]
  Subject: [amibroker] Code Help Please



  I have a piece of code which seems straight forward but I seem to be 
struggling. i have written it in a number of different ways e.g. using if 
statements in a loop and using iif statements as below. However, I seem to have 
a problem which ever way I write it insofar that Test1L & Test1S  fail to 
evaluate correctly. Herewith a snippet:



         t1 = XPermK - XpermD;

         inter2 = abs(XPermK - XpermD);



         TempL = IIf (XpermD[j] >UpperBound AND XPermK[j] >UpperBound, 
True,False);

         Test1L = IIf(tempL = True  AND abs(t1) < 2, True, False);

         Test2L=       IIf(XpermD < Lowerbound AND XPermK < Lowerbound AND t1 > 
2.0,True, False);

         Test3L=IIf(XPermK >Lowerbound AND XPermK > XPermD,True,False);       

         

         Test1S = IIf(XpermD < Lowerbound AND XPermK < Lowerbound AND abs(t1) < 
2,True,False); 

         Test2S = IIf(XpermD > UpperBound AND XPermK[k] > UpperBound AND t1> 
2,True,False); 

         Test3S = IIf(XPermK < UpperBound AND XPermK < XPermD,True,False); 



         XPermLong = IIf(Test1L = True OR Test2L[j] = True OR Test3L[j] = 
True,True, False);

         

         XpermShort =IIf(Test1S = True OR Test2S = True OR Test3S = 
True,True,False);







  For instance Test1l can return false and Test1L will evaluate as true.



  Most grateful if someone could help me understand why I have it around my 
neck. 


   

Reply via email to