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

[amibroker] Re: Checking the past by referencing current bar price?



PureBytes Links

Trading Reference Links

Maybe somebody could have a look at what's wrong with this code? runs
ok, but I don't get the indicator adjusted

remember that:
> Trying to build an indicator along the following lines:
> if price at bar satisfies condition Cond1 then Indicator = 1
> UNLESS the price did NOT satisfy Cond2 from last time Indicator was 1
> AND Close was == Close at bar, in which case Indicator = 0

Indicator = IIf(Cond1, 1, 0); // first just check Cond1 on all history

 //adjust for Cond2
for (i= 1; i < BarCount; i++) {

   if ( Cond1[i]  ) 
   for (k=i-1; k > 0 ; k--) { // looking at the past of  bar i
      if ( Close[k] == Close[i]  AND Cond1[k]  ) { Indicator[i] = 0; j
= 0;} // adjust bar i, exit loop
      if ( Cond2[k] ) k = 0; // Cond 2 met, exit loop

   }

}

On 9/9/05, neurotic self <neuroticself@xxxxxxxxx> wrote:
> This is causing me a big headache, hope I can express my problem clearly...
> 
> Trying to build an indicator along the following lines:
> if price at bar satisfies condition Cond1 then Indicator = 1
> UNLESS the price did NOT satisfy Cond2 from last time Indicator was 1
> AND Close was == Close at bar, in which case Indicator = 0
> 
> I thought of using ValueWhen so
> 
> bi = BarIndex();
> Indicator[0] = Cond1[0];
> Indicator = IIf (ValueWhen(bi, Ind == 1 AND Close == CloseAtBar) <
> ValueWhen(bi, Cond2 ), Cond1, 0)
> 
> Can't find a way to reference CloseAtBar, tried via Barindex() with
> C[Barindex()] but that makes no sense given that Barindex() is an
> array and can't be used as a subscript
> 
> Also tried to explicitly loop back in the past from current bar to
> check if Cond2 was met before price touched again price at bar and
> Indicator was 1, kind of like
> 
> for (i=BarIndex() ; i > 0; i--) {...
> 
> but again Barindex() is not the "current" bar but an array
> 
> Maybe I should loop all the history
> 
> for( i = 1; i < BarCount ; i++)
> 
> and compute Indicator bar by bar? I did something similar with the
> custom backtester but I'd really like a simplier solution, feel like
> valuewhen could do the job, but that function always escaped me
> somehow :(
> 
> Thanks for any help
> n.
> 
> --
> Janeczko for President!
> 


-- 
Janeczko for President!


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Put more honey in your pocket. (money matters made easy).
http://us.click.yahoo.com/r7D80C/dlQLAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

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

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