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

Re: [amibroker] Retracements levels and Plottext



PureBytes Links

Trading Reference Links

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.aflwriting.com



On 11/03/07, Lal <klal25@xxxxxxxxxxx> 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+styleNoRescale+styleNoLabel);
}

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.




__._,_.___

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

__,_._,___