PureBytes Links
Trading Reference Links
|
You are close, you just need to initialise the variables before the
loop rather than inside it, and define the X as an array. Inside the
loop all bar values of X[i] will be passed to the code after the loop,
by using just X only the last value in the loop of this variable is
passed to the code after the loop
DN = DateNum();
X = 0;
for( i = 0; i < BarCount; i++ )
{
if (DN[i] < 1080101) x[i] = 4;
else x[i] = 0;
}
Plot( X, "X", ParamColor("Color", colorBlack ), styleLine );
and just to confuse the issue, because X is pre-defined as zero you
can simplify the loop a bit
DN = DateNum();
X = 0;
for( i = 0; i < BarCount; i++ )
{
if (DN[i] < 1080101) x[i] = 4;
}
Plot( X, "X", ParamColor("Color", colorBlack ), styleLine );
but then you really do not need a loop for this simple array variable anyway
X = iif(DateNum() < 1080101, 4, 0);
Plot( X, "X", ParamColor("Color", colorBlack ), styleLine );
--
Cheers
Graham Kav
AFL Writing Service
http://www.aflwriting.com
2008/6/3 marketmonk777 <RedEyes777@xxxxxxxxx>:
> 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
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/
|