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

Re: [amibroker] Nested For-Loop problems



PureBytes Links

Trading Reference Links

Hello,

AddColumn function does just that: Adds column to the output list.

You have two nested loops and this will generate many thousands
of iterations with each iteration adding new column.

If you are trying to run your code with database that has 1000 bars
your code will attempt to add 100'000 columns (not lines but COLUMNS).
(one hundred thousands columns). And this of course not supported.

When asking a question, consider what is written here:
http://www.catb.org/~esr/faqs/smart-questions.html

especially worth consideration is:

"
Describe the goal, not the step
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: "nmolchanoff" <knowing@xxxxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Sunday, October 19, 2003 2:29 AM
Subject: [amibroker] Nested For-Loop problems


> Hello,
>
> I was having a problem with an exploration that utiliized a nested
> for-loop.  After much trouble-shooting, I realized that the body of
> my code inside the loop was fine; it executes perfectly when not in
> the loop.
>
> So I then tried to do just a simple test loop like this:
>
>
> for( i = BarCount - per ; i < BarCount-1; i++ ) {
>     for( j=0.850; j<=0.950; j= j+0.001 ) {
> AddColumn(i, "I", 1.0);
> AddColumn(j, "J", 1.3);
>     }
> }
>
> And it crashes the system...  It crashes as soon as I hit "Explore"
> or "Check."
>
> If I separate the two loops, they both execute perfectly,  but as
> soon as I nest them: Wham! Down she goes.
>
> Anyone know what might be causing this?
>
>
> Here is a copy of the crash dump and full source code:
>
> Crash Dump:
> ------------------------------------------------------------------
>
> AmiBroker version 4.44.0
>  ( cooltool.dll 4.44.0,  mfc42.dll 6.0.8665,  msvcrt.dll 6.1.8924 )
>
> Microsoft Windows 2000 version 5.0 (Build 2195)
> Service Pack 2.0
> Common Controls: 5.81
>
> Unhandled exception
> Type: CSysException
> Code: c0000005
> Description: ACCESS VIOLATION
> Address: 447456
>
> AddColumn(i, "I", 1.0);
>
> AddColumn(j,"J", 1.3);
>
> }
>
> }
> ^
>
> (occurred during AFL formula execution)
>
> AFL Parser status:
> Processing stage: EXECUTE
> Formula ID: 0 ()
> Action 5 (BACKTEST)
>
> Additional information:
>
> Number of stock loaded: 25388
> Currently selected stock: GENR
> Number of quotes (current stock): 2511
>
> Workspace:
> Data source = (default), Data local mode = 0, NumBars = 2600
>
> Preferences:
> Data source = QP2 , Data local mode = 1, NumBars = 2600
>
> Command history:
> 2828 - Shows Analyser - a tool to test systems & explore market--Auto-
> Analyser
>
> Cache manager stats:
> Number of list elements: 3
> Number of map elements: 3
> Hash table size: 5987
>
> Memory status:
>   MemoryLoad: 53 %
>   TotalPhys:       261668K  AvailPhys:       120372K
>   TotalPageFile:  1288600K  AvailPageFile:  1112636K
>   TotalVirtual:   2097024K  AvailVirtual:   1862540K
>
> Last Windows message:
> HWnd: 0x1402ce
> Msg: 0x0110
> wParam: 0x000f03e2
> lParam: 0x00000000
>
>
>
>
> Complete Source:
> ------------------------------------------------------------------
>
>
> per = 65;
>
> MAvol = MA(V, per);
>
> Minvol = 100000;
>
> MinPrice = 1.00;
>
> MaxPrice = 30.00;
>
> MinIrc = 2;
>
> R1 = ATR(per);
>
> irc = (r1/C)*100;
>
> L1 = Ref(L, -1);
>
> C2 = Ref(C, -2);
>
> breakeven = 0.01;
>
> Filter = (BuyPrice >= MinPrice) AND (BuyPrice <=MaxPrice) AND (V >=
> Minvol) AND (MAvol >= Minvol) AND (irc >= MinIrc);
>
> AddTextColumn(FullName(),"Name");
>
> AddColumn(MarketID(0), "Mkt", 1.0);
>
> AddTextColumn(MarketID(1), "Market");
>
> AddColumn(SectorID(0), "Sectr", 1.0);
>
> AddTextColumn(SectorID(1), "Sector");
>
> AddColumn(IndustryID(0), "Ind", 1.0);
>
> AddTextColumn(IndustryID(1), "Industry");
>
> AddColumn(C, "Price", 1.2);
>
> AddColumn(MAvol/1000, "Vol/K", 1.0);
>
> AddTextColumn(Name(), "Ticker");
>
> AddColumn(R1, "1R", 1.2);
>
> AddColumn(irc, "1R/C", 1.2);
>
> AddColumn(per, "per", 1.0);
>
>
>
>
> for( i = BarCount - per ; i < BarCount-1; i++ ) {
>
> for( j=0.850; j<=0.950; j= j+0.001 ) {
> AddColumn(i, "I", 1.0);
> AddColumn(j,"J", 1.3);
> }
> }
>
>
>
> /*
>
> for( i = BarCount - per ; i < BarCount-1; i++ ) {
>
>     for( j=0.850; j<=0.950; j= j+0.001 ) {
>
>         AddColumn(Sum(IIf((L1[i] < C2[i]* j) AND (Filter[i] ), 1,
> 0),per), "Trades" + j, 1.0);
>
>         AddColumn(Sum(IIf((L1[i] < C2[i]* j) AND (Filter[i] ) AND (O
> [i]/(C2[i]* j)-1 > breakeven), 1, 0),per), "Wins" + j, 1.0);
>
>         AddColumn(Sum(IIf((L1[i] < C2[i]* j) AND (Filter[i] ) AND (O
> [i]/(C2[i]* j)-1 > breakeven), 1, 0),per)/ Sum(IIf((L1[i] < C2[i]
> *0.850) AND (Filter), 1, 0),per), "Win%" + j, 1.2);
>
>         AddColumn(Sum(IIf((L1[i] < C2[i]* j) AND (Filter[i] ), ((O[i]/
> (C2[i]* j)-1)*100), 0),per), "Net%" + j, 1.2);
>
>     }
>
> }
> */
>
> ------------------------------------------------------------------
>
> Thanks in advance for any Ideas or Suggestions.
>
>
> Regards,
>
> Nick Molchanoff
>
>
>
>
>
>
> 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 http://docs.yahoo.com/info/terms/
>
>
>


------------------------ 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.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

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 http://docs.yahoo.com/info/terms/