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

Re: [amibroker] On Scalar Values and Arrays



PureBytes Links

Trading Reference Links

Hi Jeff - I understand, it is not incomprehensible    8 - )
 
I guess you still need to decide on your exit strategy, but for now I think this will do what you are looking for - see what you think, feel free to edit as desired.
 
Steve
 

BuyCondsVol = Ref( V, -1 ) > 5 * Ref( MA( V, 50 ), -1 ) AND Ref( MA( V, 50 ), -1 ) >= 100000;

BuyCondsPrice = Ref( C, -1 ) > Ref( O, -1 ) AND Ref( C, -1 ) > 1 AND Ref( C, -1 ) > Ref( C, -2 ) AND Ref( O, -1 ) > Ref( C, -2 );

Buy = BuyCondsVol AND BuyCondsPrice; // mark buy signal

EnterLong = Ref( Buy, -1 ); // enter on day following buy sig

EntryDate = ValueWhen( EnterLong, DateNum() );

EntryPrice = ValueWhen( EnterLong, Open ); // entry price is Open

MaxHigh = HighestSince( EnterLong, High );

BarsToMaxHigh = BarsSince( EnterLong ) - HighestSinceBars( EnterLong, High );

MinLow = LowestSince( EnterLong, Low );

BarsToMinLow = BarsSince( EnterLong ) - LowestSinceBars( EnterLong, Low );

Filter = 1;

AddColumn( Open, "Open" );

AddColumn( High, "High" );

AddColumn( Low, "Low" );

AddColumn( Close, "Close" );

AddColumn( Volume, " Volume" );

AddColumn( Buy, "Buy Sig" );

AddColumn( EnterLong, "Entry" );

AddColumn( EntryDate, "Entry Date", 1.0 );

AddColumn( EntryPrice, "Entry Price" );

AddColumn( BarsSince( EnterLong ), "BS Entry" );

AddColumn( MaxHigh, "Max H/Trade" );

AddColumn( BarsToMaxHigh, "Bars/Max H" );

AddColumn( MinLow, "Min L/Trade" );

AddColumn( BarsToMinLow, "Bars/Min L" );

 

----- Original Message -----
Sent: Monday, April 10, 2006 1:15 AM
Subject: Re: [amibroker] On Scalar Values and Arrays

Steve,
Thank you so much for going to all that trouble. Just as an aside, my FILTER statement is my BUY statement.
 
When I use your code with one symbol it works exactly as you said. However, I'm not sure how I can work it into what I'm trying to do. Ideally, I would like to backtest a trading strategy that buys after a high volume gap up. I'm not sure about much after that. Do I want to sell at a certain percentage of gain? How close should stops be? In addition, I have a few other metrics that I want to analyze to see if they have any correlation to the maximum gain and maximum loss each high volume gap has. But those are really beside the point. I really don't understand the backtester in AB, but I do okay with MSAccess. So I had hoped to build a table of all the stocks that have gapped up on over 5X average 50day volume. In order to build that table I would need to know the highest and lowest price each stock attained and how long it took to get there. In order to use the code you've written, I would have to generate tables for every stock and then parse the data out.
 
When I use your code for all stocks, over all quotations, I only get the high of the entry day. Correspondingly, all BarsSince numbers are 0. I was hoping for something like:
Symbol, EntryDate, OpenonEntry, MaxHigh, BarsTilMaxHigh, MinLow, BarsTilMinLow. A sample might look something like:
 
AETH, 3/30/2006, 3.57, 3.95, 5, 3.49, 0
 
I realize I'm probably not making much sense, and if you just wanted to give up on me I wouldn't blame you. I'll keep plugging away.
 
Jeff

Steve Dugas <sjdugas@xxxxxxxxxxx> wrote:
Hi - I played with the code and found a mistake, the new code below should work for the simple example I provided. I can't see your BUY statement and don't know how it relates to your FILTER statement, so your own code may still have other problems I don't know about. If you run this code in explorer as I did, set for current ticker, n=100, it will display the last 100 bars of your arrays - this is a good way to see when the value of your arrays is not what you expect and is a good way to debug problems. You could also do it with charts by replacing AddColumn statements with Plot statements. I have attached a picture showing the results of my test. Good luck!
 
Steve
 
Buy = Cross( Close, MA( Close, 10 ) );
MaxHigh = HighestSince( Buy, High );
BarsToMaxHigh = BarsSince( Buy ) - HighestSinceBars( Buy, High );
Filter = 1;
AddColumn( Buy, "Buy" );
AddColumn( High, "High" );
AddColumn( MaxHigh, "Max High" );
AddColumn( BarsSince( Buy ), "BS Buy" );
AddColumn( HighestSinceBars( Buy, High ), "BS MaxHigh" );
AddColumn( BarsToMaxHigh, "Bars To Max High" );
 
----- Original Message -----
Sent: Sunday, April 09, 2006 4:19 PM
Subject: Re: [amibroker] On Scalar Values and Arrays

Hi Steve,
Thank you for responding. Unfortunately, that very straightforward and intuitive solution doesn't seem to work. It appears to be returning the high of the day after the signal. That's probably a result of the way I have "Buy" defined. My "Buy" is defined to tell me the day after the signal day. Here's the code:
 
VolFilter=Ref(V,-1)>5*Ref(MA(V,50),-1) AND Ref(MA(V,50),-1)>=100000;
PriceFilter=Ref(C,-1)>Ref(O,-1) AND Ref(C,-1)>1 AND Ref(C,-1)>Ref(C,-2) AND Ref(O,-1)>Ref(C,-2);
 
Filter=Volfilter AND PriceFilter;// AND FundFilter;
 
MaxHigh=HighestSince(Filter,High);
PeriodstoMaxHigh=BarsSince(Filter)-BarsSince(MaxHigh);
 
I think that, because HighestSince() is an array, I would have to reference some part of the array; thus the use of LastValue().


Steve Dugas <sjdugas@xxxxxxxxxxx> wrote:
Hi - Wouldn't something like this work?

MaxHigh = HighestSince( Buy, High );
BarsToMaxHigh = BarsSince( Buy ) - BarsSince( MaxHigh );

Steve

----- Original Message -----
From: "fatboycato" <fatboycato@xxxxxxxxx>
To: <amibroker@xxxxxxxxxxxxxxx>
Sent: Sunday, April 09, 2006 12:50 PM
Subject: [amibroker] On Scalar Values and Arrays


> Well, I'm about to put on my clown suit, get my AK-47, and climb the
> bell tower. It seems to me there is a legitimate reason to reference
> a particular value in an array in explorations. I'll try to give a
> specific example to exactly what I'm searching for, but I think this
> array-to-scalar problem is going to plague me everywhere.
>
> Trading System:
> Buy on the open the day after a high volume gap up.
> Analysis questions:
> 1) What is the maximum high the stock attained after the signal day,
> and how many days did it take to get to the maximum high?
> 2) What is the minimum low the stock attained after the signal day,
> and how many days did it take to get to the minimum low?
>
> I'm having no problem identifying the signal day, it's finding the
> data to answer the questions where I fail. I can get the answer to
> question number one with:
> MaxHigh=LastValue(HighestSince(Filter,H,1),1);
> PeriodstoMaxHigh=(BarCount-LastValue(HighestSinceBars
> (Filter,H,1),1))-BarIndex()-1;
>
> But this makes the assumption that a stock will always go up
> because "LastValue()" only looks at the last occurence when the
> criteria were satisfied. An assumption I could probably live with,
> but there should be a better way of doing this.
>
> Regardless, this solution doesn't work for finding the answer to
> Analysis question #2 because, again, LastValue() only looks at the
> last time the criteria were met. Therefore, the MinLow is going to
> be the lowest value the stock attained after the last signal day.
>
> I thought I could put in a loop to iterate through each successive
> day after each signal day and check if it's making higher highs or
> lower lows - no luck. Ref() is an array, SelectedValue() is the last
> occurence, ValueWhen() is an array, can't use High[] because I won't
> know what goes between the brackets because, even though I can get
> AA to return the correct barindex, BarIndex() is an array.
>
> I'm sure there's something easy I'm missing because closing a
> position based on yesterday's levels is a fairly common exit
> strategy (isn't it?). Wouldn't AB be able to compare today's prices
> against yesterday's prices and decide if they're higher or lower?
>
> Thank you in advance for any help you can give.
>
> Jeff
>
>
>
>
>
>
> Please note that this group is for discussion between users only.
>
> To get support from AmiBroker please send an e-mail directly to
> SUPPORT {at} amibroker.com
>
> For other support material please check also:
> http://www.amibroker.com/support.html
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
>
>



Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+ countries) for 2¢/min or less.


New Yahoo! Messenger with Voice. Call regular phones from your PC and save big.


Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html





YAHOO! GROUPS LINKS