PureBytes Links
Trading Reference Links
|
Ken,
In your example: A0 is an ARRAY variable,
A1 is another (independent) ARRAY variable and so
on. So you have N array variables with different
names.
A[i] is not the same as Ai.
A[i] is i-th element of A array variable.
Ai is the (array) variable that has the name of
Ai
On the other hand you can no create variable names dynamically
like A+i = ..something
You could simplify the code by declaring a
function:
<FONT face="Courier New" color=#000000
size=2>
function
mycolor( array, shift )
<FONT face="Courier New"
size=2>{
array = Ref(
array, shift );
<FONT face="Courier New"
size=2> color<FONT
face="Courier New" color=#000000 size=2> =<SPAN
lang=en-us> <FONT face="Courier New"
color=#0000ff size=2>IIf<SPAN
lang=en-us>(
array<FONT face="Courier New"
color=#000000 size=2><<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorRed<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us>array >
<FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>
AND<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2><SPAN
lang=en-us> array
<FONT face="Courier New" color=#000000
size=2><<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>5<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorYellow<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorGreen<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>);
<FONT face="Courier New"
size=2>
return color;
}
and then just write:
A1 = mycolor( Tot, -1 );
A2 = mycolor( Tot, -2 );
A3 = mycolor( Tot, -3 );
A4 = mycolor( Tot, -4 );
A5 = mycolor( Tot, -5
);
<FONT face="Courier New"
size=2>
You would be able to wrap it up in a loop if you could declare
multi-dimensional arrays but you can't do this right now
(unless you use JScript or VBScript)
Please describe your high-level goal.
Quote from "how to ask questions the smart way":
"If you are trying to find out how to do something,begin by
describing the goal. Only then describe the particular step towards it that you
are blocked on.
Often, people who need technical help have a high-level goal in mind and get
stuck on what they think is one particular path towards the goal. They come for
help with the step, but don't realize that the path is wrong. It can take a lot
of effort to get past this."
Best regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE
>
----- Original Message -----
<DIV
>From:
Ken Close
To: <A title=amibroker@xxxxxxxxxxxxxxx
href="">AmiBroker List
Sent: Tuesday, November 11, 2003 4:33
AM
Subject: [amibroker] Repetitive
Statements with FOR (?)
As I venture
into the land of more "pure" programming constructs, I stumble. Any
help?
I have a
complex series of variables calculating values for today, yesterday, up to
Ref<FONT face="Courier New"
size=2>(<FONT face="Courier New"
size=2>xx,-20)
Instead
of
<FONT face="Courier New" color=#000000
size=2>A0 =<SPAN
lang=en-us> <FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot<<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorRed<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot><SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>
AND<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2> Tot<<SPAN
lang=en-us><FONT face="Courier New"
color=#ff00ff size=2>5<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorYellow<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorGreen<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>);
<FONT face="Courier New" color=#000000
size=2>A1 =<SPAN
lang=en-us> <FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>1<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>)<<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorRed<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>1<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>)><SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>
AND<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2><SPAN
lang=en-us> <FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>1<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>)<<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>5<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorYellow<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorGreen<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>);
<FONT face="Courier New" color=#000000
size=2>A2 =<SPAN
lang=en-us> <FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>2<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>)<<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorRed<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>2<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>)><SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>
AND<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2><SPAN
lang=en-us> <FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>2<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>)<<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>5<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorYellow<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorGreen<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>);
<FONT face="Courier New" color=#000000
size=2>And repeat this 19 times,<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2> back 19 days;<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2><SPAN
lang=en-us>
<FONT face="Courier New" color=#000000
size=2>I wanted to try and use a For loop, and tried the following. But
I get all sorts of error messages, the most frequent of which
is <FONT
face="Courier New" color=#000000 size=2>"Type Mismatch, number expected but
array found."
<FONT face="Courier New" color=#800000
size=2>for<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(i=<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>0<SPAN
lang=en-us>;
i><SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>19<SPAN
lang=en-us>;
i++)
<FONT face="Courier New" color=#000000
size=2>{
<FONT face="Courier New" color=#000000
size=2>A[i]=<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-i)<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2><3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorRed<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>IIf<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(<SPAN
lang=en-us><FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-i)><SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>3<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>
AND<SPAN
lang=en-us><FONT face="Courier New"
color=#000000 size=2><SPAN
lang=en-us> <FONT face="Courier New" color=#0000ff
size=2>Ref<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>(Tot,-i)<<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>5<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorYellow<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorGreen<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>);
<FONT face="Courier New" color=#000000
size=2>}
I tried
A+<FONT face="Courier New"
size=2>I and
that did not work either
<FONT face="Courier New"
size=2>"Error
3.
Condition in
IF, WHILE, FOR statements
has to be
Numeric or Boolean type.
You can not use
array here,
please use []
(array subscript operator)
to access array
elements<FONT face="Courier New"
size=2>"
The "A"s are
arrays, so the A[i] seemed like the right way to go, but then the Type
Mismatch.
I know the
answer is probably simple, but I can not see it.
<FONT face="Courier New"
size=2>Help?
<FONT face="Courier New"
size=2>KenSend
BUG REPORTS to bugs@xxxxxxxxxxxxxSend SUGGESTIONS to
suggest@xxxxxxxxxxxxx-----------------------------------------Post
AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: <A
href="">http://groups.yahoo.com/group/amiquote/messages/)--------------------------------------------Check
group FAQ at: <A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to the <A
href="">Yahoo! Terms of Service.
Yahoo! Groups Sponsor
ADVERTISEMENT
Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
|