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

[amibroker] Re: How to COUNT BARS since trade buy in EXPLORATION?



PureBytes Links

Trading Reference Links

Thomas,

Boy, I wish it were that easy; the problem is I have no "buy" to
reference.  This is a simple exploration.

1. I have a watchlist of stocks I have bought.  I update this list
every day to add new stocks and delete sold ones.

2. I am an EOD trader, so scan that list at the end of each day to see
if any of them generate a "Sell" signal.

3. Also, the "system" I am using says "Exit trade after x days,
regardless of performance, if other exits have not been already been
triggered.

So, while this works fine in BACKTESTING, I have not found a way to
implement it in an "exploration"

I am experimenting with BARINDEX(), and I think I can make it work by
generating the BARINDEX() on the day I bought the stock, and saving it
in my permanent array.  Then I simply subtract that number from the
daily BARINDEX() and I have the number of days in the trade.

The PROBLEM is making that automatic...since arrays CANNOT hold
STRINGS, there is no EASY way to code a loop to calculate stuff on a
given stock NAME.  For example, I would like to use a FOR-IF-ELSE
construct (code is representative only..you get the idea!):

SYMBOL(1-20) contains the ticker symbol names
BARIDX(1-20) contains the BARINDEX() at time of purchase
------------------
For i = 1 to 20

      if(SYMBOL(i)== NAME()), BARCOUNT[i] = BARINDEX() - BARIDX(i);
------------------
Essentially this compares the NAME() of the stock against the fixed
array SYMBOL(n) and if they are the same, calculates the BARCOUNT(n)
for that stock.

This general construct should work, but so far there is no
straightforward way to get ticker names into arrays.

Thanks for the tip!!

Roy

--- In amibroker@xxxxxxxxxxxxxxx, "Thomas Z." <tzg@xxx> wrote:
>
> Hi Roy,
>  
> i am not sure if i understood you correctly.
>  
> Don't you mean:  bars = barssince(buy);  
>  
> Maybe it is that simple :-)
>  
> Best regards
>  
> Thomas
> www.tradingbasis.com <http://www.tradingbasis.com/> 
>  
>  
> 
>   _____  
> 
> From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx]
On Behalf
> Of Roy Ewing
> Sent: Tuesday, July 18, 2006 12:27 PM
> To: amibroker@xxxxxxxxxxxxxxx
> Subject: [amibroker] How to COUNT BARS since trade buy in EXPLORATION?
> 
> 
> 
> I must be overlooking something, but am having trouble with counting
> the number of bars since a trade was opened.
> 
> Example:
> 
> I would like to run exploration and have one of the columns simply
> have a number telling me how many bars (trading days) I have held the
> stock. I don't need to go back a long way, my "system" is based
> shorter term swing-trading, 7-15 days.
> 
> I have manually built in arrays for each stock purchased, as in
> BDATE[1-20] = DATENUM (20 stocks, with buy date cvtd to valid DATENUM).
> BBOOK[1-20] = Purchase price of those 20 stocks
> BSYMB1-20 = The text of the SYM. Still can't use strings in
> arrays, so have to do it the long way.
> 
> Hurdle one is getting how many bars has it been between today (I use
> "DATENUM()" to get last bar datenum) , and the "BDATE[n]"?
> 
> I can do this:
> BDATE[13] = Date_To_Num("13072006") ; BSYMB13 = "XYZ" ; BBOOK[13] =
> 30.78 ;
> Diff = DateNum() - BDATE[13];
> 
> That gives me the total (calendar) days, but NOT the # of bars. I
> have to manually subtract out weekends, trading holidays, etc.
> ("Date_To_Num" is a function call. It is in the AFL library)
> 
> I have tried:
> 
> BS = BARSSINCE(DateNum() = BDATE[13]);
> 
> But that only produces a syntax error at the "=" sign.
> 
> I don't know enough coding yet to do it, but a function call would be
> nice where the "buy" date is sent to it and the # of bars "in trade"
> is returned.
> 
> Is there something simple I am overlooking?
> 
> Thanks.
> 
> Roy
>