Ed -
I'd have to see the specific code for scale in/out to
be able to tell. As I mentioned, I was just optimizing the posted code. But, I
generally tell people that 95% of loops can be replaced with array logic.
There are a few things (say the 5%) that I've run into that require looping.
Nested looping, though, should be avoided at all costs, and a way can usually
be found around it.
You're right about ValueWhen. I used AMA2 on
purpose, though, because it has some other important uses in portfolio mixes
that I plan to show some examples of soon, and thought it would be good to
mention it.
Anyway, sounds like your moving along now.
--
Bruce
--- In amibroker@xxxxxxxxxps.com,
"Edward Pottasch" <empottasch@...> wrote:
>
> hi
Bruce,
>
> I had a look and the AMA2 use is clever but one could
also solve it using valuewhen, like, see below:
>
> like I said I
need to use loops because the scaleIn / scaleOut cycle possibly extends
further out in time then the next buy signal. That is also the reason why I
define BuyAdjusted because when I finish the scaleIn/scaleOut cycle the
BuyAdjusted will not be the same as the Buy array. In my opinion I can not use
these array based functions in this case because I do not know when a
scaleIn/scaleOut cycle will end. But I am happy I do not have to use the Osaka
plugin.
>
> thanks,
>
> regards, Ed
>
>
> SetTradeDelays(0,0,0,0);
>
> per = 10;
> perc
= Ref(ATR(10)/C*100,-1);
> TickSize = 0.1;
> nlev =
5;
>
> mc = MACD(12,26);
> mcs =
Signal(12,26,9);
>
> Buy = Cross(mc,mcs);
> Buy
= Ref(Buy,-1);
> BuyPrice = O;
>
> for (k = 0; k <=
nlev * 2; k++ )
> {
> nn = (k - nlev);
> tab = ValueWhen(
Buy, round((1 / TickSize) * (BuyPrice + BuyPrice / 100 * perc * nn)) *
TickSize);
> VarSet( "lev" + nn, tab );
> }
>
>
GraphXSpace = 5;
> SetChartOptions(0, chartShowDates);
>
Plot(C,"\nLast",colorWhite,64);
>
> for (i = 0; i <
nlev * 2; i++)
> {
> nn = (i - nlev);
> tab = VarGet( "lev"
+ nn );
> Plot( tab,"\nlev" + nn,colorGreen + i,1 );
> }
>
> PlotShapes(IIf(Buy ==
1,shapeUpArrow,shapeNone),colorGreen,0,L,-15);
>
PlotShapes(IIf(Buy ==
1,shapeHollowUpArrow,shapeNone),colorWhite,0,L,-15);
>
PlotShapes(IIf(Buy ==
1,shapeHollowSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
>
> // THIS SHOULD BE THE LAST STATEMENT IN THE PROGRAM
>
SetBarsRequired( sbrAll, sbrAll );
>
>
> ----- Original
Message -----
> From: Bruce
> To: amibroker@xxxxxxxxxps.com
> Sent: Tuesday, December 29, 2009 7:01 PM
> Subject: [amibroker]
Re: ABTool / multidimensional arrays
>
>
>
> Ed -
>
> OK, I'll go ahead and upload all 5 mod's in case you need
the OSAKA info in the future. It is in the files section as a file called "Ed
- MODS.zip"
>
> Let me note that I didn't try to analyze the
current use and possible future variations on the code. I just concentrated on
making it faster.
>
> I did it as a series of steps with the
following file names -
>
> MOD 1.afl - simply get rid of the
table save and load and return the table.
>
> MOD 2.afl - get rid
of the OSAKA plugin and use VarGet() and VarSet() arrays
>
>
Getting rid of the loops involves re-arranging the code a little. In the past,
I had detailed the pattern in an article on the AmibrokerU site and called it
"Inside-Out Coding Pattern". The bottom line is to get the bar loop as the
inner most loop so that it can be replaced with an array function. In your
case, though, the nested inner "j" loop is far more efficiently coded as an
IIf(). This reduces the code to two loops - an outer loop through the levels
and an inner bar loop.
>
> Mod 3.afl - gets rid of the inner J
loop - original code is commented out
> Mod 4.afl - get rid of the
commented out code (for clarity) - execution should be 100 msec or
less
>
> The last mod is a way to get rid of the bar loop. I
debated on whether or not to include it because it is an unusual use of the
AMA2() function. If Mod 4.afl is fast enough, I'd suggest maybe saving Mod
5.afl for another day. Also, I couldn't foresee how you might use "delay" in
the future, so I didn't account for the general case of other than 1, although
it can be be done.
>
> Mod 5.afl - get rid of the bar loop and
have only the level loop. Execution is very fast, but delay is assumed to be
1.
>
> Hope that helps -
>
> -- BruceR
>
> --- In amibroker@xxxxxxxxxps.com,
"Edward Pottasch" <empottasch@> wrote:
> >
> >
Bruce,
> >
> > tested with Varget and Varset and that works
fine, see attached file.
> >
> > Curious how you would
solve the scaling problem without loops still,
> >
> >
regards, Ed
> >
> >
> >
> > -----
Original Message -----
> > From: Bruce
> > To: amibroker@xxxxxxxxxps.com
> > Sent: Tuesday, December 29, 2009 5:20 PM
> > Subject:
[amibroker] Re: ABTool / multidimensional arrays
> >
> >
> >
> > Ed -
> >
> > I got interested
in this thread and your posted AFL over coffee this morning. Looked like an
interesting puzzle. Please take the following constructively. You can pass the
table from the procedure, but the bottom line is that you really do not need
OSAKA. Standard arrays (not static) via VarGet() and VarSet() could be used.
Another significant opportunity is to eliminate the looping - it is going to
run very slow with the nested bar loops.
> >
> > Anyway, if
you want to see it, let me know. If you've moved on with what you have, that's
fine, too.
> >
> > -- BruceR
> >
> > ---
In amibroker@xxxxxxxxxps.com,
"Edward Pottasch" <empottasch@> wrote:
> > >
>
> > hi Ton,
> > >
> > > I couldn't pass it
through the procedure. If defined within the procedure you need to save it to
a file to use it elsewhere in the code (as far as I know). If you do not need
procedures it just sits in the memory.
> > >
> > >
But the fact that this example code is so slow is due to the loop within a
loop. For the problem I am trying to solve there is no way around that. So if
Amibroker adds multidimensional arrays I guess it will not be faster but it
will be a lot easier,
> > >
> > > regards, Ed
>
> >
> > >
> > > ----- Original Message -----
> > > From: Ton Sieverding
> > > To: amibroker@xxxxxxxxxps.com
> > > Sent: Tuesday, December 29, 2009 4:59 PM
> > >
Subject: Re: [amibroker] Re: ABTool / multidimensional arrays
> >
>
> > >
> > >
> > >
> >
> Ed, thanks for the code. I've tried it. A very nice quick intro for
OSAKA. Just a simple question. Is there a way in OSAKA to write the table to
internal in stead of external memory ? Should be a hell of a lot faster
...
> > >
> > > Regards, Ton.
> > >
> > >
> > > ----- Original Message -----
>
> > From: Edward Pottasch
> > > To: amibroker@xxxxxxxxxps.com
> > > Sent: Tuesday, December 29, 2009 1:11 PM
> > >
Subject: Re: [amibroker] Re: ABTool / multidimensional arrays
> >
>
> > >
> > >
> > >
> >
> hi Ton,
> > >
> > > thanks for your suggestion,
I will remember it for future use. For now I seem to be able to get ahead with
the Osaka plugin. It would be nice if we could define multidimensional arrays
in Amibroker. I thought there have been requests for this but I can't find any
in the suggestions section.
> > >
> > > In my
example code it can be seen that you can use a "Osaka" table inside a
procedure but you can not pass it to the main program as a global variable
multidimensional array. Therefor it needs to be saved in a file and later
restored.
> > >
> > > regards, Ed
> > >
> > >
> > >
> > > ----- Original
Message -----
> > > From: Ton Sieverding
> > > To:
amibroker@xxxxxxxxxps.com
> > > Sent: Tuesday, December 29, 2009 1:02 PM
> > >
Subject: Re: [amibroker] Re: ABTool / multidimensional arrays
> >
>
> > >
> > >
> > >
> >
> Hi Ed. I know you will not like what I am suggesting but it works. At
least for me. Before using Static Arrays load a very long time series like the
SP500 and use this as a 'carrier' or 'feeder' for your Static Array ... I
assume you understand what I mean. I am using this trick for all cases where I
need long arrays ...
> > >
> > > Regards,
Ton.
> > >
> > >
> > > ----- Original
Message -----
> > > From: Edward Pottasch
> > > To:
amibroker@xxxxxxxxxps.com
> > > Sent: Tuesday, December 29, 2009 11:31 AM
> > >
Subject: Re: [amibroker] Re: ABTool / multidimensional arrays [1
Attachment]
> > >
> > >
> > >
>
> >
> > > hi,
> > >
> > > I wanted
to use multi dimensional arrays so that I can use a number of levels as a
variable. It is impossible in Amibroker to define a variable number of arrays,
or I do not know how. For instance I tried as a variable: nlev = 4;
>
> >
> > > for (k = 0; k <= nlev * 2; k++)
> >
> {
> > > nn = (k - nlev);
> > > global "lev" +
nn;
> > > "lev + nn = Null;
> > > }
> > >
> > > this does not work. So it seems you can not define a
variable number of "normal" arrays.
> > >
> > >
Therefor I moved to static arrays. That seemed to work at first but I
encountered problems I did not understand and now I find this in the manual:
"static array variables store only as many bars as there are currently in use
by given chart." Even though I use setbarsrequired(-2,-2) or
setbarsrequired(sbrall) the values inside the static arrays seem to vary.
It depends where you drop your cursor, what part of the chart you display how
they get filled. I thought there was something wrong in my code, drives you
nuts but the values in these static arrays seem all over the place, pretty
much useless for my purposes. Attached code what I was trying to do. Also I
get different results when using setbarsrequired(-2,-2) and
setbarsrequired(sbrall).
> > >
> > > Now I
turned to the Osaka plugin but I find that you can fill and restore only 1
element at a time. You can not get an entire row at once. Am I right?
>
> >
> > > thanks, Ed
> > >
> > >
> > >
> > > ----- Original Message -----
>
> > From: Herman
> > > To: amibroker@xxxxxxxxxps.com
> > > Sent: Monday, December 28, 2009 9:12 PM
> > >
Subject: Re: [amibroker] Re: ABTool / multidimensional arrays
> >
>
> > >
> > >
> > > The changes made
by Tomasz to the OSAKA plugin are documented in the readme.
> > >
> > > herman
> > >
> > >
> >
>
> > > Edward Pottasch wrote:
> > >
>
> > ok thanks. I only find it in the 3-rd party area. Seems to be
unchanged. Didn't know Tomasz improved it. Looks the same from when I tried it
a few years ago. It has very little documentation. Will try again some
day.
> > >
> > > to reefbreak: will have a look. For
now I am able to solve my problem using static arrays. I am writing a
complicated scaling in and out system, at least complicated to code where at
the entry signal I define levels for scaling in and out. It looks like I can
do without these multi dimensional arrays and static arrays do the
job.
> > >
> > > rgds, Ed
> > >
>
> >
> > >
> > > ----- Original Message -----
> > > From: Herman
> > > To: amibroker@xxxxxxxxxps.com
> > > Sent: Monday, December 28, 2009 5:03 PM
> > >
Subject: Re: [amibroker] Re: ABTool / multidimensional arrays
> >
>
> > >
> > >
> > > btw, if you
haven't tried the OSAKA plugin yet you should give it a try. Tomasz improved
it some time in the past and it gives, if you use it is intended to be used,
high performance multi-column sorting. It is fast and has full capability to
save/read/import tables to/from files - also very fast. It offers an unlimited
number of columns, this may enable you to simulate multi dimensional tables in
a two dimensional field.
> > >
> > > I think there
are some ready to run examples in file section.
> > >
>
> > If you haven't used this plugin you are missing out on some great
functions! I encourage you to try it.
> > >
> > >
herman
> > >
> > >
> > >
> >
> reefbreak_sd wrote:
> > >
> > > You didn't
state your application, so I don't know if it is relevant, but I posted a 2
dimensional sort routine in message 136551. This routine reverse sorts tickers
and an indicator value, and keeps the pairs together to be printed in the
Interpretation window.
> > >
> > > ReefBreak
>
> >
> > > --- In amibroker@xxxxxxxxxps.com,
"Edward Pottasch" <empottasch@> wrote:
> > > ok thanks
Herman.
> > >
> > > regards, Ed
> > >
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From:
Herman
> > > To: amibroker@xxxxxxxxxps.com
> > > Sent: Monday, December 28, 2009 11:21 AM
> > >
Subject: Re: [amibroker] ABTool / multidimensional arrays
> > >
> > >
> > >
> > > The last I heard was
that the developer stopped supporting it and that Tomasz wrote at some point
that ABTools wasn't compatible with AB. It would be risky to use it.
>
> >
> > > herman
> > >
> > >
Edward Pottasch wrote:
> > >
> > > hi,
> >
>
> > > I was looking into multidimensional arrays again. I
know there is the Osaka plugin but never quite figured out how to use it.
However, I found this post:
> > >
> > > http://finance.groups.yahoo.com/group/amibroker/message/40135
>
> >
> > > all the way from 2003. This ABTool seems just
what I need and easy to understand. However it seems to have been removed.
Anyone know the history on this? Why it has been removed? What is currently
the status with multidimensional arrays in Amibroker?
> > >
> > > thanks, Ed
> > >
> > >
>
> >
> > >
> > >
> > >
------------------------------------
> > >
>
> > **** IMPORTANT PLEASE READ ****
> > > This group is for
the discussion between users only.
> > > This is *NOT* technical
support channel.
> > >
> > > TO GET TECHNICAL SUPPORT
send an e-mail directly to
> > > SUPPORT {at}
amibroker.com
> > >
> > > TO SUBMIT SUGGESTIONS
please use FEEDBACK CENTER at
> > > http://www.amibroker.com/feedback/
>
> > (submissions sent via other channels won't be considered)
>
> >
> > > For NEW RELEASE ANNOUNCEMENTS and other news
always check DEVLOG:
> > > http://www.amibroker.com/devlog/
>
> >
> > > Yahoo! Groups Links
> > >
>
>
>