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

[amibroker] Re: Struggling to Learn



PureBytes Links

Trading Reference Links

>From a very quick look, one issue I can see is that you're trying to
use the Trend array and Period variable before you've defined their
values. Your values Uptrend, Downtrend, Crossup, Crossdown, HV, and LV
are all generated using only the initial values of Trend and Period.
You then go and generate the Trend array data in the loop,
incrementing Period as you go, but all those other variables you're
using only have their initial values.

To get what you want, you're going to have to do more for yourself in
the loop. Since you want the HHV and LLV values over varying periods
as you go along, you can't just call those functions once at the start
for some initial value of Period. Similarly, you can't start checking
for trend crossovers until you've actually generated the Trend array
data up to that point.

Essentially, all those array variables you've defined before the loop
need to be filled iteratively inside the loop, with the values at each
bar calculated from other values calculated at earlier bars.

Once basic rule of programming: you can't use values before you've
calculated them.

Regards,
GP


--- In amibroker@xxxxxxxxxxxxxxx, "ricko8294_98" <ricko@xxx> wrote:
>
> 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/