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

[amibroker] SwingHigh



PureBytes Links

Trading Reference Links


Cound any kind soul translate the following EasyLanguage SwingHigh
function to afl ?

I'm aware of acesheet's fine afl code dated Jan 09, 2003 
but unfortunately they don't match.
When there is a tie, acesheet's code picks the first high 
whereas I want the last high.

Thank you in advance.

--------------- Easylanguage code begins ----------

Inputs: Occur(NumericSimple), Price(NumericSeries),
Strength(NumericSimple), Length(NumericSimple) ;

Variables: X(0), J(0), Counter(0), Found(FALSE), Price1(0),
Truth(FALSE);

J = Strength;
Found = FALSE;

If J > 0 Then Begin
	Counter = 0;
	While J < Length  AND Found = FALSE Begin
		Price1 = Price[J];
		X = J + 1;
		Truth = TRUE;
		While  Truth AND X - J <= Strength Begin
			If Price1 < Price[X] Then 
				Truth = FALSE;
			X = X + 1;
		End;
		X = J - 1;
		While Truth AND J - X <= Strength Begin
			If Price1 <= Price[X] Then 
				Truth = FALSE;
			X = X - 1;
		End;
		If Truth Then 
			Counter = Counter + 1;
		If Counter >= Occur Then 
			Found = TRUE;
		J = J + 1;
	End;
End;
If Found Then 
	SwingHigh = Price1 
Else 
	SwingHigh = -1 ;

--------------- Easylanguage code ends ----------

--------------- afl code begins ----------

//---------------------------------------------------------------
//-------------------- N Degree Swing High ----------------------
//---------------------------------------------------------------
// The 'degree' of a swing high refers to the 
// number of lower/equal highs to both sides of the bar 
// being analyzed. As an example if n=2 then there are
// 2 lower or equal highs prior to the analyzed bar and
// 2 lower or equal highs to the right of the bar
//---------------------------------------------------------------
function SwingHigh(n)
{
// Degree of SH set
// --------------------------------------------------
// Peak points (SH's)
  pk=Ref(HHV(H,2*n+1)==Ref(H,-n),n);
// --------------------------------------------------
// SH envelope values
  sh1=IIf(pk,H,Null);
  sh=Ref(HighestSince(pk,sh1,1),-n-1);
  return sh;
}

--------------- afl code ends ----------





------------------------ Yahoo! Groups Sponsor --------------------~--> 
What would our lives be like without music, dance, and theater?
Donate or volunteer in the arts today at Network for Good!
http://us.click.yahoo.com/Tcy2bD/SOnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/