Thanks Graham.  I will take a good look at restructuring the code.  In the 
meanwhile, as an experiment, I've commented 
out the lines where I'm connecting the peaks and troughs with  lines and notice 
that the execution is much faster.
I can live without the connecting lines.  The retracement levels were a lot 
more important for me - I have them now, so very 
pleased about that.

By the way, all this is a prelude to building Pesavento Pattern recognition 
logic.  And hopefully Wolfewaves as well...:-)  

Cheers,
Lal

----- Original Message ----
From: Graham <[EMAIL PROTECTED]>
To: [email protected]
Sent: Sunday, 11 March, 2007 9:18:57 PM
Subject: Re: [amibroker] Retracements levels and Plottext

you are double looping, using loops from each bar within a loop
this is slow 
can you move some functions outside of the loops to remove the double looping?


-- 
Cheers
Graham
AB-Write >< Professional AFL Writing Service 
Yes, I write AFL code to your requirements
http://www.aflwriti ng.com 


On 12/03/07, Lal <[EMAIL PROTECTED] co.uk> wrote:Graham,

Thank you for the suggestion.  That does solve the problem.  The retracements 
levels displayed now remain despite scrolling or clicking on the chart. 

One other thing that bothered me was the slow execution of the code.  Grateful 
for any pointers on speeding it up.

Cheers,
Lal

----- Original Message ----
From: Graham <kavemanperth@ gmail.com>
To:  [EMAIL PROTECTED] ps.com
Sent: Sunday, 11 March, 2007 8:50:44 PM
Subject: Re: [amibroker]  Retracements levels and Plottext

I have not gone through the code in detail but you should add this to it 
because you are using loop 
setbarsrequired( 10000,10000) ;


-- 
Cheers
Graham
AB-Write >< Professional AFL Writing Service
 Yes, I write AFL code to your requirements
 http://www.aflwriti ng.com 




On 11/03/07, Lal < [EMAIL PROTECTED] co.uk> wrote:Hi,

I'm trying to compute and display retracement levels after a peak has formed.  
The code I have developed works fine only once after I apply the indicator. 
Clicking anywhere on the graph causes the computed levels to disappear!  
Obviously, I am doing something wrong, only can't figure   
out what.  Would be grateful for any helpful hints.

Attached is a screenshot showing how the graph looks immediately after the 
first application of the indicator.

Cheers,
Lal



_SECTION_BEGIN("Retracements");  

Level = Param("Pivot Level", 9, 2, 100, 1);

Plot(C, "Retracements", colorBlack, styleBar);

My_Peak[0] = 0;
My_Trough[0] = 0;

for( i = Level+1; i <  BarCount-Level; i++ )  
  { 
        // There shouldn't be a higher high for the next few bars
        R_Higher_high[ 0] = 0;          // Higher High found on the right of 
current bar
        L_Higher_high[  0] = 0;         // Higher High found on the left of 
current bar 

        R_Lower_Low[ 0] = 0;            // Lower Low found on the right of 
current bar
        L_Lower_Low[ 0] = 0;            // Lower Low found on the left of 
current bar

        //    | | | | C | | | | 
        //                     ---->    
        for (j = i; j <= i+Level; j++)   
                {
                if(High[j] > High[i])   
                        {
                        R_Higher_high[ 0] = R_Higher_high[ 0] + 1;
                }

                if(Low[j] < Low[i])     
                        {
                        R_Lower_Low[ 0] = R_Lower_Low[ 0] + 1; 
                }
        }

        // There should be no  higher high for previous few bars 
        //    | | | | C | | | |
        //               <----  
        for(k = i;  k >= (i-Level);  k--)       
        {
                if(High[k] > High[i])
                {
                        L_Higher_high[ 0] = L_higher_high[ 0] + 1;
                }

                if(Low[k] < Low[i]) 
                {
                        L_Lower_Low[ 0] = L_Lower_Low[ 0] + 1;
                }
        }

        // If we've detected a higher high on either 
        // side of current bar, 
        // we do NOT have a valid  peak
        if(NOT L_Higher_High[ 0] AND NOT r_Higher_High[ 0]) 
        {
                My_peak[i] = 1; // Mark current bar as a valid pivot/peak
                PlotText("P", i, H[i] + 20, colorRed);
        }

        // If we've detected a lower low on either  
        // side of current bar,
        // we do NOT have a valid trough 
        if(NOT L_Lower_Low[ 0] AND NOT R_Lower_Low[ 0])
        {
                My_Trough[i] = 1;       // Mark current bar as a valid 
pivot/peak
                PlotText("T", i, L[i] - 30, colorBlue); 
        }

        L_higher_high[ 0] = 0; R_Higher_High[ 0] = 0; 
        L_Lower_Low[ 0] = 0;  R_Lower_Low[ 0] = 0;
} 


// Find Co-ordinates to draw lines 
// Peak to Peak AND Trough to Trough
Y0 = ValueWhen(My_ Peak, H, 2); 
X0 = ValueWhen(My_ Peak, BarIndex(), 2);

 Y1 =  ValueWhen(My_ Peak, H, 1);
X1 = ValueWhen(My_ Peak, BarIndex(),  1);

NullY0 = IsNull(y0);
NullY1 = IsNull(y1);

TY0 = ValueWhen(My_ Trough, L, 2); 
TX0 = ValueWhen(My_ Trough, BarIndex(), 2);

TY1 =   ValueWhen(My_ Trough, L, 1);
TX1 = ValueWhen(My_ Trough, BarIndex(), 1); 

NullTY0 = IsNull(Ty0);
NullTY1 = IsNull(Ty1);



// Work out retracement levels after a peak
P1              =  ValueWhen(My_ Peak, H, 1); 
P1_B    = ValueWhen(My_ Peak, BarIndex(), 1);

T1              = ValueWhen(My_ Trough, L, 2); 
T1_B    = ValueWhen(My_ Trough, BarIndex(), 2);

T2              =  ValueWhen(My_ Trough, L, 1);
T2_B    = ValueWhen(My_ Trough, BarIndex(), 1); 

Cond1 = P1_B > T1_B AND P1_B < T2_B;
T1P1_Swing = P1 - T1;
P1T2_Swing = P1 - T2; 
Swing_Extent = P1T2_Swing / T1P1_Swing;
PlotNow         = ValueWhen(Cond1, BarIndex());
Ext                     = ValueWhen(Cond1, Swing_Extent, 1); 

// Test End

for( i = BarCount-1; i > 10; i--)
{
        if ( !Nully0[i]) 
        {
                // Line to conncect peaks
                Line1 =  LineArray( x0[i], y0[i], x1[i], y1[i], 0, True);
                Plot(Line1, "", colorWhite, styleDashed+ styleNoRescale+ 
styleNoLabel) ; 
        }       

        if (  !NullTy0[i])
        {
                // Line to connect troughs
                Line2 = LineArray( tx0[i], ty0[i], tx1[i], ty1[i], 0, True); 
                Plot(Line2, "", colorWhite, styleLine+styleNoRe 
scale+styleNoLab el);
        }       

        if (PlotNow[i]) 
        {
                // Show retracement extent after a peak
                PlotText("" + WriteVal(Ext[ i], 1.2), T2_B[i], T2[i]-60, 
colorBlack); 

        }
}
_SECTION_END( );






  What kind of emailer are you? Find out today - get a free analysis of your 
email personality. Take the quiz at the    Yahoo! Mail Championship. 












  New Yahoo! Mail is the ultimate force in competitive emailing. Find out more 
at the  Yahoo! Mail Championships. Plus: play games and win prizes. 







  <!--  #ygrp-mlmsg 
{font-size:13px;font-family:arial,helvetica,clean,sans-serif;} #ygrp-mlmsg 
table {font-size:inherit;font:100%;} #ygrp-mlmsg select, input, textarea 
{font:99% arial,helvetica,clean,sans-serif;} #ygrp-mlmsg pre, code {font:115% 
monospace;} #ygrp-mlmsg * {line-height:1.22em;} #ygrp-text{ 
font-family:Georgia; } #ygrp-text p{ margin:0 0 1em 0; } #ygrp-tpmsgs{ 
font-family:Arial; clear:both; } #ygrp-vitnav{ padding-top:10px; 
font-family:Verdana; font-size:77%; margin:0; } #ygrp-vitnav a{ padding:0 1px; 
} #ygrp-actbar{ clear:both; margin:25px 0; white-space:nowrap; color:#666; 
text-align:right; } #ygrp-actbar .left{ float:left; white-space:nowrap; } 
.bld{font-weight:bold;} #ygrp-grft{ font-family:Verdana; font-size:77%; 
padding:15px 0; } #ygrp-ft{ font-family:verdana; font-size:77%; border-top:1px 
solid #666; padding:5px 0; } #ygrp-mlmsg #logo{ padding-bottom:10px; }  
#ygrp-vital{ background-color:#e0ecee; margin-bottom:20px; padding:2px 0 8px 
8px; }
 #ygrp-vital #vithd{ font-size:77%; font-family:Verdana; font-weight:bold; 
color:#333; text-transform:uppercase; } #ygrp-vital ul{ padding:0; margin:2px 
0; } #ygrp-vital ul li{ list-style-type:none; clear:both; border:1px solid 
#e0ecee; } #ygrp-vital ul li .ct{ font-weight:bold; color:#ff7900; float:right; 
width:2em; text-align:right; padding-right:.5em; } #ygrp-vital ul li .cat{ 
font-weight:bold; } #ygrp-vital a { text-decoration:none; }  #ygrp-vital 
a:hover{ text-decoration:underline; }  #ygrp-sponsor #hd{ color:#999; 
font-size:77%; } #ygrp-sponsor #ov{ padding:6px 13px; background-color:#e0ecee; 
margin-bottom:20px; } #ygrp-sponsor #ov ul{ padding:0 0 0 8px; margin:0; } 
#ygrp-sponsor #ov li{ list-style-type:square; padding:6px 0; font-size:77%; } 
#ygrp-sponsor #ov li a{ text-decoration:none; font-size:130%; } #ygrp-sponsor 
#nc { background-color:#eee; margin-bottom:20px; padding:0 8px; } #ygrp-sponsor 
.ad{ padding:8px 0; } #ygrp-sponsor .ad #hd1{ font-family:Arial;
 font-weight:bold; color:#628c2a; font-size:100%; line-height:122%; } 
#ygrp-sponsor .ad a{ text-decoration:none; } #ygrp-sponsor .ad a:hover{ 
text-decoration:underline; } #ygrp-sponsor .ad p{ margin:0; } o {font-size:0;} 
.MsoNormal { margin:0 0 0 0; } #ygrp-text tt{ font-size:120%; } 
blockquote{margin:0 0 0 4px;} .replbq {margin:4;} --> 



                
___________________________________________________________ 
Yahoo! Messenger - with free PC-PC calling and photo sharing. 
http://uk.messenger.yahoo.com

Reply via email to