PureBytes Links
Trading Reference Links
|
Ken,
Yes, now it is much more clear.
You can simplify your code using for loop that
way:
<FONT
color=#000000>for<FONT
color=#000000>( i = 19; i
>= 0<FONT
color=#000000>; i-- ) { array = <FONT
color=#0000ff>Ref(
bTot, -i ); bkColor = IIf<FONT
color=#000000>( array <3<FONT
color=#000000>,colorRed<FONT
face="Courier New">,
<FONT
color=#0000ff>IIf(array ><FONT
color=#ff00ff>3 <FONT
color=#000000>AND array < <FONT
color=#ff00ff>5,
colorYellow<FONT
color=#000000>,colorGreen<FONT
face="Courier New">) ); <FONT
color=#0000ff> AddColumn( <FONT
color=#0000ff>Ref(BTot,-i),<FONT
color=#ff00ff>"-"+i,<FONT
color=#ff00ff>1.0,<FONT
color=#000000>colorBlack<FONT face="Courier New"
color=#000000>,bkColor); }
<FONT face="Courier New"
size=2>
This will give all
20 columns from -19 to 0.
<FONT face="Courier New"
size=2>
Hope this helps.
Best regards,Tomasz Janeczkoamibroker.com
<BLOCKQUOTE
>
----- Original Message -----
<DIV
>From:
Ken Close
To: <A title=amibroker@xxxxxxxxxxxxxxx
href="">amibroker@xxxxxxxxxxxxxxx
Sent: Tuesday, November 11, 2003 11:56
AM
Subject: RE: [amibroker] Re: Repetitive
Statements with FOR (?)
You guys are great,
and I apologize for not describing the high-<SPAN
lang=en-us><FONT face=Verdana
size=2>level<FONT
face=Verdana size=2>
goal.
There is an "animal"
in the FastTrack world called a "Cheese" chart, a glimpse of which is
attached. I also think that Bill Barack posted code for this in the
files area. In making a cust<SPAN
lang=en-us>om system<SPAN
lang=en-us> using
this<FONT face=Verdana
size=2> cheese chart<SPAN
lang=en-us> construction<SPAN
lang=en-us>,
I <FONT face=Verdana
size=2>needed to use much<SPAN
lang=en-us> more complex color
combinations<FONT
face=Verdana size=2>. P<SPAN
lang=en-us>lus<SPAN
lang=en-us> I
saw<FONT face=Verdana
size=2> the opportunity to practice something I do not use -- for
loops.
I could construct
(and have constructed the code that makes the attached) with a long series of
statements with Ref(XXX,-y) , 19 of them.<SPAN
lang=en-us> I copy one of
them, and then use Search/Replace to quickly alter each remaining
statement. <SPAN
lang=en-us> I thought I could make smaller
code<FONT face=Verdana
size=2> without copy/paste/edit.
In my example, I am
creating the color variable, A0, A1, A2, etc<SPAN
lang=en-us> (which is shown
as nc19, nc18<FONT
face=Verdana size=2>,<SPAN
lang=en-us> etc below)<SPAN
lang=en-us>
Then later, I use it
in an AddColumn Statement, like this
<FONT face="Courier New" color=#0000ff
size=2>AddColumn<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>(BTot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>19<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>),<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>"-19"<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>1.0<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorBlack<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,nc19);
<FONT face="Courier New" color=#0000ff
size=2>AddColumn<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>(BTot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>18<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>),<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>"-18"<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>1.0<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorBlack<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,nc18);
<FONT face="Courier New" color=#0000ff
size=2>AddColumn<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>(BTot,-<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>17<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>),<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>"-17"<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff00ff
size=2>1.0<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,<SPAN
lang=en-us><FONT face="Courier New" color=#ff0000
size=2>colorBlack<SPAN
lang=en-us><FONT face="Courier New" color=#000000
size=2>,nc17);
This is my actual
AddColumn code, but in my simplified example, I changed ncX to Ax, and BTot
was Tot (which of course is defined further up in the
logic).
<FONT face=Arial color=#000000
size=2><<...>> <SPAN
lang=en-us>
Does this make it
more clear?
<FONT face=Verdana
size=2>Ken
-----Original
Message-----From: Tomasz Janeczko [<A
href="">mailto:amibroker@xxxxxx]Sent: Tuesday,
November 11, 2003 5:19 AMTo: amibroker@xxxxxxxxxxxxxxxSubject: Re:
[amibroker] Re: Repetitive Statements with FOR (?)<SPAN
lang=en-us>
<FONT face=Verdana
size=2>Dimitris,
Problem is that I
don't know what exactly Ken was after.
I provided some
explanation based on wild guesses.
Let us wait for Ken
to get back to us, describing the high-level goal
so we can help him
better.
Best
regards,
Tomasz
Janeczko
<FONT face=Verdana
size=2>amibroker.com
----- Original
Message -----
From: "DIMITRIS
TSOKAKIS" <TSOKAKIS@xxxxxxxxx>
To:
<amibroker@xxxxxxxxxxxxxxx>
Sent: Tuesday,
November 11, 2003 10:48 AM
Subject: [amibroker]
Re: Repetitive Statements with FOR (?)
>
Tomasz,
> As I
see
>
A1=Ref(A0,-1);
>
A2=Ref(A0,-2);
>
etc
> which, in last
analysis, is array A0 and nothing more.
> Dimitris
Tsokakis
> --- In
amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <amibroker@xxxx>
>
wrote:
> > Repetitive
Statements with FOR (?)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:
> >
> > function
mycolor( array, shift )
> >
{
> > array
= Ref( array, shift );
> > color
= IIf( array<3,colorRed,array > 3 AND array
>
<5,colorYellow,colorGreen);
> >
> >
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 );
> >
> > 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
Janeczko
> >
amibroker.com
> >
----- Original Message -----
> >
From: Ken Close
> >
To: 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(xx,-20)
> >
> >
Instead of
> >
> >
A0 = IIf(Tot<3,colorRed,IIf(Tot>3 AND
>
Tot<5,colorYellow,colorGreen);
> >
> >
A1 = IIf(Ref(Tot,-1)<3,colorRed,IIf(Ref(Tot,-1)>3 AND
Ref(Tot,-1)
>
<5,colorYellow,colorGreen);
> >
> >
A2 = IIf(Ref(Tot,-2)<3,colorRed,IIf(Ref(Tot,-2)>3 AND
Ref(Tot,-2)
>
<5,colorYellow,colorGreen);
> >
> >
And repeat this 19 times, back 19 days;
> >
> >
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 "Type
Mismatch, number expected but array found."
> >
> >
> >
> >
for(i=0; i>19; i++)
> >
> >
{
> >
> >
A[i]=IIf(Ref(Tot,-i)<3,colorRed,IIf(Ref(Tot,-i)>3 AND
Ref(Tot,-i)
>
<5,colorYellow,colorGreen);
> >
> >
}
> >
> >
I tried A+I and that did not work either
> >
> >
"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"
> >
> >
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.
> >
> >
Help?
> >
> >
Ken
> >
> >
>
> Yahoo! Groups Sponsor
>
>
ADVERTISEMENT
>
>
>
>
>
>
> >
> >
Send BUG REPORTS to bugs@xxxx
> >
Send SUGGESTIONS to suggest@xxxx
> >
-----------------------------------------
> >
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 Yahoo! Terms of
>
Service.
>
>
>
> Send BUG REPORTS
to bugs@xxxxxxxxxxxxx
> Send 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 <A
href="">http://docs.yahoo.com/info/terms/
>
>
>
<FONT face=Verdana
size=2>------------------------ Yahoo! Groups Sponsor
---------------------~-->
Buy Ink Cartridges or
Refill Kits for your HP, Epson, Canon or Lexmark
Printer at
MyInks.com. Free s/h on orders $50 or more to the US &
Canada.
<A
href="">http://www.c1tracking.com/l.asp?cid=5511
<A
href="">http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
<FONT face=Verdana
size=2>---------------------------------------------------------------------~->
Send BUG REPORTS to
bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to
suggest@xxxxxxxxxxxxx
<FONT face=Verdana
size=2>-----------------------------------------
Post AmiQuote-related
messages ONLY to: amiquote@xxxxxxxxxxxxxxx
(Web page: <A
href="">http://groups.yahoo.com/group/amiquote/messages/)
<FONT face=Verdana
size=2>--------------------------------------------
Check group FAQ at:
<A
href="">http://groups.yahoo.com/group/amibroker/files/groupfaq.html
Your use of Yahoo!
Groups is subject to <A
href="">http://docs.yahoo.com/info/terms/
Send
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.
|