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

[amibroker] Code Translation Help



PureBytes Links

Trading Reference Links

I found this Tradestation code for Percentage Trend Indicator which I 
am having trouble translating.

Here is the Tradestation code.

Inputs:
K(15), {%Coeff. of correction}
Max_per(50); {Max. Dynamic Period for Trend Calculation}

Vars: Trend(C), Period(0) ; {Trend Calculation}
Condition1= C > Trend[1]; {UpTrend}
Condition2= C <= Trend[1]; { DownTrend}

{SetUp Period When New Trend Begin}
If C Cross over Trend[1] or C Cross Below Trend[1] Then Period = 0;
If Period < Max_per Then Begin {Counting UpTrends with dynamic period}
If Condition1 Then Begin
Period = Period +1;
Trend = Highest(C,Period)[1]*(1 ? (K/100));
End ; {Counting DownTrends with dynamic period}
If Condition2 Then Begin
Period = Period + 1;
Trend = Lowest(C,Period)[1]*(1 + (K/100));
End;
End Else Begin {Counting UpTrends with constant period}
If Condition1 Then Trend = Highest(C,Max_per)[1]*(1 ? (K/100));
{Counting DownTrends with constant period}
If Condition2 Then Trend = Lowest(C,Max_per)[1]*(1 + (K/100));
End; {Plotting Indicator}
Plot1(Trend, «Trend»);


Here is my attempt at translation.

K = Param("% Coeff of Correlation",15,1,50,1);
MaxPeriod = Param("Trend Calculation Period",50,1,100,1);
Trend = C;
Period = 0;
Cp = Close[0];
Condition1 = C > Ref(Trend,-1);
Condition2 = C <= Ref(Trend,-1);
Cond1 = Cross(C, Ref(Trend,-1));
Cond2 = Cross(Ref(Trend,-1) ,C);
HV = HHV(Cp,Period);
LV = LLV(Cp,Period);

for (i = 1; i < BarCount; i++)
{
if (Cond1[i] OR Cond2[i]) Period = 0;
   
if(Period[i] < MaxPeriod) 
   {
   if (Condition1[i])
      {
	  Period++;
	  Trend[i] = HV[i] * (1 - (K/100));
	  }
	if (Condition2[i])
      {
        Period++;
        Trend[i] = LV[i] * (1 + (K/100));
      }		
	else
	   {
	   if (Condition1[i]) Trend[i] = HV[i]*(1-(K/100));

	   if (Condition2[i]) Trend[i] = LV[i]*(1+(K/100));
	   }
	}   
}	  
Plot(Trend,"Trend",colorGreen,1);
Plot(C,"Percentage Trend Indicator",colorYellow,64);

If anybody can point out where I went wrong, I would greatly 
appreciate it.

Thanks in advance

Rick




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
 
Yahoo! Groups Links

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

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> 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/