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

RE: [amibroker] Counting the bars



PureBytes Links

Trading Reference Links

Title: Message
Graham,
You asked this question awhile back, and I've playing with it on and off six months now.
I think I've come up with something and have been using it for awhile.
 

function Hash()

{

C == Ref(C, -1) AND L == Ref(L, -1) AND H == Ref(H, -1) AND O == Ref(O, -1) AND V == Ref(V, -1);

}

Lookback = Param("lookback period", 100, 50, 200, 10);

goal1 = Param("goal", 10000, 1000, 100000, 5000);

ratio1 = Param("ratio", 0.85, 0.5, 1, 0.05);

goal2 = Param("goal2", 2000, 1000, 100000, 5000);

ratio2 = Param("ratio2", 0.95, 0.5, 1, 0.05);

firstbar = LastValue(ValueWhen(BarIndex() == (BarCount - Lookback), DateNum()));

Lasttenbars = LastValue(ValueWhen(BarIndex() == (BarCount - 10), DateNum()));

days = Cum(C * V > 0 AND DateNum() >= firstbar);

tradeabledays1 = Cum( Avg * V >= goal1 AND !Hash() AND DateNum() >= firstbar);

trading1 = Cum( Avg * V >= goal1 AND !Hash() AND DateNum() >= Lasttenbars) > 0;

LQ1 = tradeabledays1 /Days;

tradeabledays2 = Cum( Avg * V >= goal2 AND !Hash() AND DateNum() >= firstbar);

trading2 = Cum( Avg * V >= goal2 AND !Hash() AND DateNum() >= Lasttenbars) > 0;

LQ2 = tradeabledays2 /Days;

Filter=(LQ1 >= ratio1 AND trading1 AND LQ2 >= ratio2);

WhenBars = BarsSince( Cross(DateNum(), firstbar) );

AddColumn( firstbar, "date ?", 1 );

AddColumn( LQ1, "LQ1");

AddColumn(tradeabledays1, "total1");

AddColumn( LQ2, "LQ2");

AddColumn(tradeabledays2, "total2");

AddColumn(Days, "days");

AddColumn(BarCount, "Bars");

AddColumn(Cum(C*V > 0), "cum", 1.0);

AddColumn(Avg * V, "tran");

AddTextColumn(MarketID(1),"Market");

AddTextColumn(GroupID(1), "Group");

 

Paul Ho

 


From: Paul Ho [mailto:paultsho@xxxxxxxxxxxx]
Sent: Sunday, 23 January 2005 6:28 PM
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Counting the bars

its indeed quite tricky Graham,  I am not sure if you turnoff and on padding within AFL, if it is possible, you could use optimize to have 2 runs, the 1st run with padding selected to obtain value for XAOFB, and the second time with padding turn off to obtain LQ. I looked but could not find how AA turns it off.
Without that, One could use param to run it 2 times with out changing the code itself.
-----------------------------

XAOFB = ParamDate("Startdate", "2004-08-31");

run = Param("run", 0, 0, 1, 1); // run 1 is to obtain the XAOFB date

XAOPer = 100;

if (run ) {

XAOFB = LastValue(Ref(DateNum(),-100));

}

Per = BarsSince( Cross( DateNum(), XAOFB ) ) + 1;

LQ = LastValue(Per)/XAOPer;

Filter=LQ > 0.95;

WhenDate = ValueWhen( BarIndex()==(BarCount-101), DateNum() );

WhenBars = BarsSince( Cross(DateNum(), WhenDate) );

AddColumn( WhenDate, "date ?", 1 );

AddColumn( WhenBars, "bars=100 ?", 1 );

AddColumn( LQ, "LQ");

AddColumn(XAOFB, "XAOFB");

AddColumn(XAOPer, "XAOPer");

AddColumn(Per, "Per");

 
 
-----Original Message-----
From: Graham [mailto:kavemanperth@xxxxxxxxx]
Sent: Sunday, 23 January 2005 10:52 AM
To: amibroker@xxxxxxxxxxxxxxx
Subject: [amibroker] Counting the bars

I want to run and exploration over the past 100 bars of actual market
days in an unpadded database. However is does not seem to be as easy
as I thought to do it is a single step. If I do it straight off I get
different first dates for tickers as some days are not traded. but if
I reference it to padding to a reference ticker, eg an index, then
every ticker has the same number of bars in the reports whether they
traded all the time or not.
Essentially I want to explore for tickers that have trade more than
95% of the past 100 market days.
I can do it in 2 steps by finding the date of 100 days ago in the
index, then manually put this date into my explorations

Step 1, explore on index
XAOPer = 100;
XAOFB = ValueWhen( BarIndex()==(BarCount-1-XAOper), DateNum() );
Filter=1;
AddColumn( XAOFB, "datenum", 1 );

Step 2
XAOFB = 1040831; // manually enter from previous explore results
Per = BarsSince( Cross( DateNum(), XAOFB ) ) + 1;
LQ = ( LastValue(Per)/XAOPer ) > 0.95;


With this code I have tried the AA settings to pad and not pad, but
does not give me the right results as explained above

WhenDate = ValueWhen( BarIndex()==(BarCount-101), DateNum() );
WhenBars = BarsSince( Cross(DateNum(), WhenDate) );
Filter=1;
AddColumn( WhenDate, "date ?", 1 );
AddColumn( WhenBars, "bars=100 ?", 1 );




Hoping someone can help


--
Cheers
Graham
http://e-wire.net.au/~eb_kavan/


Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html




Check AmiBroker web page at:
http://www.amibroker.com/

Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html




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