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

[amibroker] Struggling to Learn



PureBytes Links

Trading Reference Links

Hello

I am trying to learn AB and loops in particular.  There seems to be 
something I'm not getting - and I have been playing with this for the 
past several weeks.

I want to create a trend indicator that will track below an uptrend 
(x% below the highest high of the most recent "y" period) or track 
above a downtrend(x% above the lowest low of the most recent "y" 
period), where the period "y" increases each day for the duration of 
each trend up to a maximum level.  

When a cross of the price (C) and the trend occurs,(either up or 
down) the period "y" resets to zero.

My attepmt at coding this is below. For some reason, when a cross 
occurs the change doesn't happen.  And the value of the "trend" 
indicator doesn't seem to be the HHV or LLV value either.  I'm 
stumped and any help would be appreciated. 

Here is the code:

// Percentage Trend Indicator 
K = Param("% Coeff of Correlation",10,1,50,1);
MaxPeriod = Param("Trend Calculation Period",5,1,25,1);
Period = 1;
Trend = C[0];
Uptrend = C > Ref(Trend,-1); // Uptrend
Downtrend = NOT Uptrend;
CrossUP = Cross(C, Ref(Trend,-1)); // change to uptrend
CrossDown = Cross(Ref(Trend,-1),C); // change to downtrend

HV = HHV(H,Period );
LV = LLV(L,Period );
MP = MaxPeriod ;


for (i = 1; i < BarCount; i++) 
{
   if (CrossUP [i] OR CrossDown [i]){ 
   Period = 0; 
}
   if(Period < MP) 
   {
      if ( Uptrend[i])
      {
 	      Period ++;
         Trend[i] = HV[i] * (1-(K/100));

	   }
	   if (Downtrend[i])
      {
         Period ++;
         Trend[i] = LV[i] * (1+(K/100));
      }
    }	
    else if (Period >= MP)
	 {
     	if (Uptrend[i]) Trend[i] = HV[i] * (1-(K/100)) ; 
      if (Downtrend[i]) Trend[i] = LV[i] * (1+(K/100)) ;
    }
}
 
Plot(Trend,"Trend",colorYellow,1);
Plot(C,"Close",colorYellow,64);




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/