Hello,

You are doing things wrong way.
Leave the processing to the backtester.
Generate BUY/Sell signals FIRST, REGARDLESS of score,
and assign the score to PositionScore
AmiBroker will sort all signals based on their score and then decide 
which ones
are FIRST (top ranked) and trade them.
It will NOT trade all signals, but only top-ranked ones.
The amount is controllable by the user using MaxOpenPositions.
You don't need to do this processing on your own, it is all built-in
and many times faster than you could ever do in your formula.
You don't need any custom backtester code to do the ranking and trading 
top-N symbols as
it is integral and built in part of the backtest process.
Why re-invent the wheel ?

It is explained here:
http://www.amibroker.com/guide/h_portfolio.html


Best regards,
Tomasz Janeczko
amibroker.com

On 2010-04-09 08:47, mkecera wrote:
> Hello,
>
> Thank you.
>
> I came up with the code below. So signal array has ALL the symbols sorted or 
> just the ones which passed the BUY rules? Because I want to sort ALL the 
> symbols first and then apply some BUY rules on the first five symbols.
>
> Again thanks for your help.
>
> SetCustomBacktestProc("");
> if (Status("action") == actionPortfolio)
>       {
>      bo = GetBacktesterObject();      
>      bo.PreProcess(); 
>      for (i = 0; i<  BarCount; i++)   
>      {
>        Counter[i]=0;
>          for (sig = bo.GetFirstSignal(i); sig; sig = bo.GetNextSignal(i))
>          {    
>                Counter[i]=Counter[i]+1;
>                       if (Counter[i]>5){sig.PosSize=0;}
>            }  
>          bo.ProcessTradeSignals(i);   
>      }        
>      bo.PostProcess();
> }
>
>
> --- In [email protected], Tomasz Janeczko<gro...@...>  wrote:
>    
>> Hello,
>>
>> Using GetFirstSignal/GetNextSignal methods.
>> When you iterate using those functions you will get the list of
>> symbols sorted by absolute value of positionscore.
>> For more info see:
>> http://www.amibroker.com/guide/a_custombacktest.html
>> and
>> http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
>>
>> Best regards,
>> Tomasz Janeczko
>> amibroker.com
>>
>> On 2010-04-08 22:23, mkecera wrote:
>>      
>>> Fast response! Thank you. Can you be more specific on how to access 
>>> rankings using custom backtester?
>>>
>>> --- In [email protected], Tomasz Janeczko<groups@>   wrote:
>>>
>>>        
>>>> Hello,
>>>>
>>>> Oh my God! It does not only re-iterates for all stocks BUT repeating it
>>>> for ALL bars
>>>> A MUST-READ is this: http://www.amibroker.com/guide/x_performance.html
>>>>
>>>> Follow advice given in the article and MOVE LOOP INVARIANTS OUTSIDE THE
>>>> LOOP !
>>>>
>>>> Better yet REMOVE THIS code altogether.
>>>> You don't need this.
>>>> Instead use PositionScore that does the ranking for you !
>>>> This is a 2nd must read:
>>>> http://www.amibroker.com/guide/h_portfolio.html
>>>>
>>>> If you need to access rankings use custom backtester - the signal array
>>>> will have all symbols sorted by absolute
>>>> value of position score on bar by bar basis - it will be many orders of
>>>> magnitude
>>>> faster than your code.
>>>>
>>>> Best regards,
>>>> Tomasz Janeczko
>>>> amibroker.com
>>>>
>>>> On 2010-04-08 21:52, mkecera wrote:
>>>>
>>>>          
>>>>> Hi All,
>>>>>
>>>>> I am using the function below to get ranking of particular stock in the 
>>>>> watchlist according to defined function. Problem is that for backtest its 
>>>>> too slow as it recalculates for each stock.
>>>>>
>>>>> Is there a way to store the rankings once and then just read them or pass 
>>>>> them between different stocks during portfolio backtest?
>>>>>
>>>>> Any pointers are greatly appreciated. Thank you.
>>>>>
>>>>> function GetValue(index)
>>>>>   {
>>>>>   return C[index];
>>>>>   }
>>>>>
>>>>> for (z=1; z<=BarCount-1; z++)
>>>>> {
>>>>>   local List;
>>>>>
>>>>>       List = CategoryGetSymbols( categoryWatchlist, WatchlistNumber );
>>>>>
>>>>>       for( i = 0; ( SymbolNumber= StrExtract( List, i ) ) != ""; i++ )
>>>>>       {
>>>>>   SetForeign(SymbolNumber);
>>>>>   TemporaryValue = GetValue(z);
>>>>>   RestorePriceArrays();
>>>>>   TickersValue[i] = TemporaryValue;
>>>>>       }
>>>>>
>>>>>   MyPosition[z]=0;
>>>>>   for( n = 0; n<=i; n++ )
>>>>>       {
>>>>>   
>>>>> MyPosition[z]=IIf(MyValue[z]<TickersValue[n],MyPosition[z]+1,MyPosition[z]);
>>>>>       }
>>>>> }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ------------------------------------
>>>>>
>>>>> **** 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
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>            
>>>>
>>>>          
>>>
>>>
>>> ------------------------------------
>>>
>>> **** 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
>>>
>>>
>>>
>>>
>>>
>>>        
>>      
>
>
>
> ------------------------------------
>
> **** 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
>
>
>
>
>    

Reply via email to