Australian (ASX) Stock Market Forum

Amibroker Simple Backtests

aa = the HHV up until yesterday.

What you want is to find stocks where close >= yesterday's HHV(H,25).


What code have you got so far?
 
aa = the HHV up until yesterday.

What you want is to find stocks where close >= yesterday's HHV(H,25).


What code have you got so far?

All I've used so far is C == HHV(C,25) (using Amibroker)
the only other filters I've entered is things like liquitidy filters and close price > open price.


Why do go by the 25 day high of yesterday's stocks and not today's?

Is this because you're searching during market hours and want to place the trade before the end of the day?
I don't understand.
 
C==HHV will be too restrictive.

You want to know if C >= HHV for breakouts.

If you use today's data in the calculation of HHV, and today is a breakout day, then the close will rarely be >=H.


This needs a lot of work! Play around with optimizing, see what happens.


________________________________________________________________

OptimizerSetEngine("cmae");
SetBacktestMode( backtestRegularRaw );

Posqty = 10;
PositionSize = -100/PosQty;//
PositionScore = 100-C;

a = HHV(H,Optimize("HHV",17,1,50,1));
aa = Ref(a,-1);
z = SAR(Optimize("SAR1",.072,.001,.1,.001),Optimize("SAR2",.037,.001,.1,.001));

Buy = C<1 AND C>=aa AND V*O>500000;
Sell = Cross(z,C);
 
C==HHV will be too restrictive.

You want to know if C >= HHV for breakouts.

If you use today's data in the calculation of HHV, and today is a breakout day, then the close will rarely be >=H.


This needs a lot of work! Play around with optimizing, see what happens.


________________________________________________________________

OptimizerSetEngine("cmae");
SetBacktestMode( backtestRegularRaw );

Posqty = 10;
PositionSize = -100/PosQty;//
PositionScore = 100-C;

a = HHV(H,Optimize("HHV",17,1,50,1));
aa = Ref(a,-1);
z = SAR(Optimize("SAR1",.072,.001,.1,.001),Optimize("SAR2",.037,.001,.1,.001));

Buy = C<1 AND C>=aa AND V*O>500000;
Sell = Cross(z,C);

1. So what is the actual difference in meaning between the symbols:

C >= HHV
C == HHV

2. How do I enter the code of C>=HHV for minus 1 day rather than today as you mentioned? What does this do exactly?

3. What do you mean the close will rarely be >=H? By this do you mean the close price is likely to close below the high of the day so it won't be picked up?
 
1. C==HHV means the value of the C equals the value of the HHV. eg. C=10, H=10
C>=HHV means 'greater than or equal to', same as in maths. H = 10, C=10 or above.

2. See the code I wrote. Ref(a,-1). See help section Ref(x,n).

3. The close can't be higher than the day's high can it? It can only equal it or be lower than it.

4. Run that code through an optimization and tell me what figures it spits out.
 
1. C==HHV means the value of the C equals the value of the HHV. eg. C=10, H=10
C>=HHV means 'greater than or equal to', same as in maths. H = 10, C=10 or above.

2. See the code I wrote. Ref(a,-1). See help section Ref(x,n).

3. The close can't be higher than the day's high can it? It can only equal it or be lower than it.

4. Run that code through an optimization and tell me what figures it spits out.

Thanks for that. I'll put it through when I'm back from Sydney and get on Amibroker.
 
I managed to log on now actually.

1. When I ran the ==HHV and >=HHV both returned the same results. 44,809 matches using all my data. I'm not sure why this is?


2. When I ran the optimise with that code it produced all the same results. I don't know why. (see below).
I don't know if my settings are messed up or something. Even when I run a simple backtest, every trade comes out as a loser. I then played around with the settings and I cannot get even a slightly positive number for backtesting. Most results are between -0.1 and -0.9%. It's crazy.

optimise.jpg
 
This is a problem that is really pissing me off. Something is clearly wrong and I have no idea what. First I noticed it with backtesting and now with this where every single result was the same!!!!

Can somebody please help me if you know what could be wrong.
 
I managed to log on now actually.

1. When I ran the ==HHV and >=HHV both returned the same results. 44,809 matches using all my data. I'm not sure why this is?

Are you using C == HHV(C,20) compared to C >= HHV(C,20)? If so, yes, those will both return the same results. The close can never be greater than the highest close of the last 20 bars because the last 20 bars includes the current bar. EG. Imagine you're in a room full of people and everyone (including yourself) is measured to see who's the tallest (ie. what the highest value is). You (the current bar) can not be higher than the highest measured value because you were already measured in the included sample.

What Gringotts Bank is referring to is using >= in the context of comparing the close to yesterday's value of HHV(C,20), ie. excluding the current bar from the HHV(C,20) calculation. To do this you would insert your HHV(C,20) into ref( ,-1), ie. you would use ref(HHV(C,20),-1). The ref( ,-1) bit references the value 1 bar ago. ref( ,-2) references 2 bars ago, etc. If that's what you want to do. However for the purposes of just mucking around with Amibroker to see how it all works, there's nothing wrong with just using C == HHV(C,20) as you're doing now.

Personally I'd just use "greater than", and drop the equals, ie. C > ref(HHV(C,20),-1) for indicating a breakout, because if it's equal to the 20 bar high it hasn't really broken out.

Anyway, just take baby steps with it. You're not going to create a killer trading system overnight. Just learn the basics of the Amibroker language first. Have you got the Amibroker Users Guide?
 
Are you using C == HHV(C,20) compared to C >= HHV(C,20)? If so, yes, those will both return the same results. The close can never be greater than the highest close of the last 20 bars because the last 20 bars includes the current bar. EG. Imagine you're in a room full of people and everyone (including yourself) is measured to see who's the tallest (ie. what the highest value is). You (the current bar) can not be higher than the highest measured value because you were already measured in the included sample.

What Gringotts Bank is referring to is using >= in the context of comparing the close to yesterday's value of HHV(C,20), ie. excluding the current bar from the HHV(C,20) calculation. To do this you would insert your HHV(C,20) into ref( ,-1), ie. you would use ref(HHV(C,20),-1). The ref( ,-1) bit references the value 1 bar ago. ref( ,-2) references 2 bars ago, etc. If that's what you want to do. However for the purposes of just mucking around with Amibroker to see how it all works, there's nothing wrong with just using C == HHV(C,20) as you're doing now.

Personally I'd just use "greater than", and drop the equals, ie. C > ref(HHV(C,20),-1) for indicating a breakout, because if it's equal to the 20 bar high it hasn't really broken out.

Anyway, just take baby steps with it. You're not going to create a killer trading system overnight. Just learn the basics of the Amibroker language first. Have you got the Amibroker Users Guide?

Thanks for that. Makes a lot more sense now.

Ok I am still a little unsure about the exact code to enter. Is this it:

Filter =
C > HHV(C,20)
ref(HHV(C,20),-1);


Or do I need to add other lines to that (apart from the AddColumn...)
 
OptimizerSetEngine("cmae");
SetBacktestMode( backtestRegularRaw );

Posqty = 10;
PositionSize = -100/PosQty;//
PositionScore = 100-C;

a = HHV(H,Optimize("HHV",17,1,50,1));
aa = Ref(a,-1);
z = SAR(Optimize("SAR1",.072,.001,.1,.001),Optimize("S AR2",.037,.001,.1,.001));

Filter = Buy = C<1 AND C>=aa AND V*O>500000;
Sell = Cross(z,C);

Addcolumn(a,"HHV17",1.3);
Addcolumn(c,"last/close",1.3);
 
I noticed that has optimize in there. How do I do it for just a simple exploration of greater than highest Hightower of last 25 days from yesterdays day (so not including today)

Thanks
 
I noticed that has optimize in there. How do I do it for just a simple exploration of greater than highest Hightower of last 25 days from yesterdays day (so not including today)

Thanks

Filter = C > Ref(HHV(C,25),-1);

plus the AddColumn bit.
 
I am now using this to play around with things:


Filter =
C > Ref(HHV(C,25),-1)
AND C>O
AND C <10
AND V*C>500000;


AddColumn (C,"Close");
AddColumn (V,"Volume");
AddColumn (V*C,"Liquidity");



How do I update this so that it will ALSO search for the LLV of the last 25 days AND the C<O for these ones?
 
Do I simply do this?


Filter =
C > Ref(HHV(C,25),-1)
AND C>O
AND C <10
AND V*C>500000;

Filter =
C > Ref(LLV(C,25),-1)
AND C<O
AND C <10
AND V*C>500000;


AddColumn (C,"Close");
AddColumn (V,"Volume");
AddColumn (V*C,"Liquidity");



If so, how do I add a column so that in the Analysis window there is a column to tell me which ones are the HHV and which ones are the LLV?
 
I am now using this to play around with things:


Filter =
C > Ref(HHV(C,25),-1)
AND C>O
AND C <10
AND V*C>500000;


AddColumn (C,"Close");
AddColumn (V,"Volume");
AddColumn (V*C,"Liquidity");



How do I update this so that it will ALSO search for the LLV of the last 25 days AND the C<O for these ones?

Filter = ((C > Ref(HHV(C,25),-1) AND C>O) OR (C < Ref(LLV(C,25),-1) AND C<O))
AND C <10
AND V*C>500000;

AddColumn (C,"Close");
AddColumn (V,"Volume");
AddColumn (V*C,"Liquidity");
 
Filter = ((C > Ref(HHV(C,25),-1) AND C>O) OR (C < Ref(LLV(C,25),-1) AND C<O))
AND C <10
AND V*C>500000;

AddColumn (C,"Close");
AddColumn (V,"Volume");
AddColumn (V*C,"Liquidity");

Thanks for that. This Forum has sped up my understanding of code so much. A deep thanks to yourself and everyone else who has helped me :)
 
This is my current code


Filter = ((C > Ref(HHV(C,25),-1) AND C>O AND H>MA(C,40)) OR (C < Ref(LLV(C,25),-1) AND C<O AND L<MA(C,40)))

AND C < 10 AND V*C>500000;
Add Columns
AddColumn (C,"Close")
AddColumn (V,"Volume")
Add Column (V*C,"Liquidity")


It's still producing around 50-80 results a day!!!

I've had some useful advice on what I could add as filters, but does anyone have any codes that I can play around with that might be good filters for breakout trading?
 
It's still producing around 50-80 results a day!!!

Yes, but many of the results will be duplicates from the previous day(s). Eg. You'd be entering a trade the first time it shows up on your list, making a new high. You wouldn't also enter another position in the same stock the following day when it closes even higher, and again the day after that when it closes higher still.

One thing you could do would be to change the code so it only gives you the first new high, after it has been below the HHV for 1 or more days. Have a think how you'd code that. I find it often helps to draw the daily bars of the setup you're looking for on a piece of paper so you can more easily visualise what you're trying to code.
 
Top