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

Re: [amibroker] Working with DateNum and If Statement



PureBytes Links

Trading Reference Links

> All I would like to do is create an indicator that assigns 4 to a
> variable called x if the date of the bar is before the year 2008.
> After that date I want the value to be zero.

hi,
 
you could just use iif for that:
 
x = IIf(DateNum() < 1080101,4,0);
WriteVal
(x);
if you choose to use a loop it would look like:
 
x = 0;
DN =
DateNum
();
for( i = 0; i < BarCount
; i++ )
{
if (DN[ i ] < 1080101
)
   x[ i ] =
4
;
else

   x[ i ] =
0
;
}
WriteVal
(x);
rgds, Ed
 
 
 
----- Original Message -----
Sent: Tuesday, June 03, 2008 7:19 AM
Subject: [amibroker] Working with DateNum and If Statement

I am making a lot of progress on some custom studies and indicators
but I have run into a road block and am hoping someone here can point
me in the right direction.

Although the help file states that there are 6 arrays for each symbol,
isn't there a 7th? That being the date? One array each for Date,
High, Low, Open, Close, Volume, and OI?

Or is the date a part of each array as in (Date, High) ... (Date, Close)?

If I can learn how figure out how to code a simple little indicator it
will allow me to move forward.

All I would like to do is create an indicator that assigns 4 to a
variable called x if the date of the bar is before the year 2008.
After that date I want the value to be zero.

This is the code I created:

if (DateNum() < 1080101)
x = 4;
else
x = 0;

From the error message I get it sounds like I have to use a script to
cycle through each bar.

That means I have to use some looping code and therefore tried this:

for( i = 1; i < BarCount; i++ )
{
DN = DateNum();
if (DN[i] < 1080101)
x = 4;
else
x = 0;
}

Plot( X, "X", ParamColor("Color", colorBlack ), styleLine );

All it plots is a zero across all dates.

I have tried a lot of other combinations as well. Please help as I
have lost enough of my hairline for one night, lol.

Regards,
MM

__._,_.___

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




Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___