[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [amibroker] Re: Looping - our previous discussion



PureBytes Links

Trading Reference Links

GP,
 
thanks for your reply.  In Yahoo you can not view attachements but if you tell Yahoo to forward the Email to your ISP Email adres then you will receive the attachments.
 
I will poste the code below.
 
First about your code. I will try to use it and recreate what I have done.
 
Second about your remarks. I added some code that outputs i and j. The output looks like (a snapshot)
 
II: 50
II: 51
II: 52
II: 53
JJ: 54
JJ: 55
JJ: 56
JJ: 57
JJ: 58
JJ: 59
II: 60
II: 61
II: 62
 
you see that i = 53 and then goes to j = 54 and get back into the i loop at 60 after the last element in the j loop was 59. This seems right to me. If it would skip a bar at the end of the inner loop I would think that one would get
 
JJ: 59
II: 61
 
This is not the case.
 
Then you say there is an overflow in the j loop. Guess my former code was not adjusted for that. I avoid this in the later code (see below),
 
rgds, Ed
 
 
 
procedure setup_proc(Setup, MaxWaitPeriod) {

global
SetupAdjusted;
global
SetupPrice;

SetupPrice =
Null
;
SetupAdjusted = Setup;

for (i = 0; i < BarCount
; i++) {

   
printf("II: " + i + "\n"
);

   
if
(SetupAdjusted[ i ]) {

      
for (j = i + 1; j < BarCount
; j++) {
      
         
printf("JJ: " + j + "\n"
);
      
         
if (H[ j ] < H[ i ] AND (j - (i + 1
) ) <= MaxWaitPeriod) {
         
            SetupAdjusted[ j ] =
0
;
            SetupPrice[ j ] =
H
[ i ];
            
         }
else if (H[ j ] < H[ i ] AND (j - (i + 1
) ) >= MaxWaitPeriod) {
         
            SetupAdjusted[ j ] =
0
;
            SetupPrice[ j ] =
H
[ i ];      
            i = j;
            
break
;                           
            
         }
else if (H[ j ] >= H
[ i ]) {
         
            SetupPrice[ j ] =
H
[ i ];
            i = j;
            
break
;         
                                       
         }
else if (j == BarCount - 1
) {
         
            
break
;
         
         }            
         
      }

   }

}

}



SetBarsRequired(10000,10000
);

per =
Param( "Period", 20, 2, 100
);

SetupPrice =
Null
;
MaxWaitPeriod =
10
;

Setup =
C < BBandBot(C,per,2
);

setup_proc(Setup, MaxWaitPeriod);
Setup = SetupAdjusted;

Buy = Cross(H,SetupPrice) AND !IsNull
(SetupPrice);
BuyPrice = IIf(O > SetupPrice,O
,SetupPrice);

SetChartOptions(0, chartShowDates
);
GraphXSpace = 5
;
Plot(C,"C",1,64
);
Plot(BBandBot(C,per,2),"",colorGold,1
);
Plot(SetupPrice,"",colorLightBlue,1
);
PlotShapes(IIf(Setup,shapeSmallCircle,0),colorYellow, layer = 0, yposition = L, offset = 0
);
 
 
 
 
----- Original Message -----
From: gp_sydney
Sent: Friday, June 15, 2007 1:00 PM
Subject: [amibroker] Re: Looping - our previous discussion

Ed,

I can't get your attachements. They show at the bottom of the message
but also say "not stored", and there's nothing to get. Any idea why
that might be (it seems to be the same for all messages with
attachments here)?

I looked back at the original discussion, and from what it seems like
the objective is to me, I think the whole thing can be done like this:

Setup = ExRemSpan(C < BBandBot(C, 20, 2), waitPeriod-1);
SetupPrice = ValueWhen(Setup,H) * triggerPercentage;
Buy = Cross(H, SetupPrice) && BarsSince(Setup) < waitPeriod;

All that loop code can be replaced by the ExRemSpan array function.

Also, in that original loop code, there are a couple of problems.
Firstly, it skips a bar at the end of each inner loop, because the
statement i=j sets i to the next bar, but then the for loop's i++
statement increments it straight away. It should be i=j-1. Secondly,
it won't run to the end of the array. The outer loop's condition
should be i < BarCount but then the inner loop needs to add "AND j <
BarCount" to its condition to avoid over-running the array.

Regards,
GP

__._,_.___

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html





SPONSORED LINKS
Investment management software Investment property software Investment software
Investment tracking software Return on investment software

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___