Amibroker Questions

the blades

Experienced member
Messages
1,336
Likes
275
OK, I'm not sure if this has any legs - but an Amibroker forum has been previously requested. If there's any demand then this thread might be a measure. So I'll start :)....;

The following code is supposed to replicate the rythm pullback system documened in the poor2rich yahoo group. In short, it buys on the first positive day after dip then holds for a set number of days(based on a suppose inherent cycle in the index) before selling.

I've optimised the code for different holding periods, but as that number increases, the exposure decreases...shorely there's shome mistake?:eek:



PB=Optimize("PB",0.995,0.99,0.999,0.001);
Length=Optimize("Length",6,3,15,1);

Cond1=Ref(C,-1)<PB*Ref(C,-2);
Cond2=C>Ref(C,-1);


Buy=Cond1 AND Cond2;
Sell=BarsSince(Buy)==length;
length=BarsSince(Buy);

Short=O;
Cover=O;



Any ideas?

Cheers,
UTB
 
OK, I'm not sure if this has any legs - but an Amibroker forum has been previously requested. If there's any demand then this thread might be a measure. So I'll start :)....;

The following code is supposed to replicate the rythm pullback system documened in the poor2rich yahoo group. In short, it buys on the first positive day after dip then holds for a set number of days(based on a suppose inherent cycle in the index) before selling.

I've optimised the code for different holding periods, but as that number increases, the exposure decreases...shorely there's shome mistake?:eek:



PB=Optimize("PB",0.995,0.99,0.999,0.001);
Length=Optimize("Length",6,3,15,1);

Cond1=Ref(C,-1)<PB*Ref(C,-2);
Cond2=C>Ref(C,-1);


Buy=Cond1 AND Cond2;
Sell=BarsSince(Buy)==length;
length=BarsSince(Buy);

Short=O;
Cover=O;



Any ideas?

Cheers,
UTB


Hi Blades,

I'm currently at work but will take a look when I get home.

Couple of points though. Firstly, maybe we can get the thread renamed as initially I thought it was referring to some "Russian" software ;)

Seriously though, what is the following line doing? length=BarsSince(Buy); You already declared it at the start of the code and then use it in your Sell condition. What happens if you remove this line?

Chorlton
 
Hi Blades,

I'm currently at work but will take a look when I get home.

Couple of points though. Firstly, maybe we can get the thread renamed as initially I thought it was referring to some "Russian" software ;)

Seriously though, what is the following line doing? length=BarsSince(Buy); You already declared it at the start of the code and then use it in your Sell condition. What happens if you remove this line?

Chorlton

Crikey - what the hell is it with my spelling:D

I take your point about the line - I'll remove it. Actually I already repeated the testing and got different, more realistic results. I think I'd had something set-up wrong in the settings tab. I haven't checked through the trades to see if there's any errors, so I'll still make the change.

I'll also pm a mod re the title (edit - cheers Don).

UTB
 
Last edited:
Crikey - what the hell is it with my spelling:D

I take your point about the line - I'll remove it. Actually I already repeated the testing and got different, more realistic results. I think I'd had something set-up wrong in the settings tab. I haven't checked through the trades to see if there's any erros, so I'll still make the change.

I'll also pm a mod re the title.

UTB


Glad that the results are more meaningful now. :)

If you're not already doing so, I would highly recommend plotting Buy/Sell signals on the chart to help you identify the trades. Personally, I find it easier this way and helps in identifying potential errors...
 
Glad that the results are more meaningful now. :)

If you're not already doing so, I would highly recommend plotting Buy/Sell signals on the chart to help you identify the trades. Personally, I find it easier this way and helps in identifying potential errors...

yes another good suggestion, thanks. A seperate issue I'm having - when I look at the equity chart, I halways have a hige drop off at the RHS of the chart which isn't related to any trade but appears to be skewing the stats. Have you had any problems like this?

Cheers,
UTB
 
Glad that the results are more meaningful now. :)

If you're not already doing so, I would highly recommend plotting Buy/Sell signals on the chart to help you identify the trades. Personally, I find it easier this way and helps in identifying potential errors...

OK, I've ammended the code and I thought I should be getting the arrows - but nothing happened. The code is ;

PB=Optimize("PB",0.99,0.975,0.999,0.002);
Length=Optimize("Length",6,3,15,1);

Cond1=Ref(C,-1)<PB*Ref(C,-2);
Cond2=C>Ref(C,-1);


Buy=Cond1 AND Cond2;
Sell=BarsSince(Buy)==length;


Short=O;
Cover=O;

Plot(C,"c",colorBlack,styleCandle);
PlotShapes( Buy * shapeUpArrow, colorGreen);
PlotShapes( Sell * shapeDownArrow, colorRed);

e = Equity();
Plot(e,"Equity",colorGreen,styleLine|styleOwnScale);

any suggestions?

Cheers,
UTB
 
Last edited:
OK, I've ammended the code and I thought I should be getting the arrows - but nothing happened. The code is ;

PB=Optimize("PB",0.99,0.975,0.999,0.002);
Length=Optimize("Length",6,3,15,1);

Cond1=Ref(C,-1)<PB*Ref(C,-2);
Cond2=C>Ref(C,-1);


Buy=Cond1 AND Cond2;
Sell=BarsSince(Buy)==length;


Short=O;
Cover=O;

Plot(C,"c",colorBlack,styleCandle);
PlotShapes( Buy * shapeUpArrow, colorGreen);
PlotShapes( Sell * shapeDownArrow, colorRed);

e = Equity();
Plot(e,"Equity",colorGreen,styleLine|styleOwnScale);

any suggestions?

Cheers,
UTB

found the answer - "apply indicator" in the formula editor. I was expecting this to be generate through AA.

BUT.....as you've suggested, it exposes errors in the programme. Here, the sell day is always 1 day after they buy (should be 6), so the holding period isn't working. Can you spot any errors in this code Chorlton - when you have time?

Cheers,
UTB
 
Last edited:
found the answer - "apply indicator" in the formula editor. I was expecting this to be generate through AA.

BUT.....as you've suggested, it exposes errors in the programme. Here, the sell day is always 1 day after they buy (should be 6), so the holding period isn't working. Can you spot any errors in this code Chorlton - when you have time?

Cheers,
UTB

Blades,

I'll take a look tonight once I get home from work and post my findings.... In the meantime, take a look at the TradeDelay function in AB.
 
Blades,

I'll take a look tonight once I get home from work and post my findings.... In the meantime, take a look at the TradeDelay function in AB.

I see the problem but as yet I can't fix it. The sell is triggering 6 days after the last time a buy condition was hit, rather than 6 days after an original buy. So if those conditions happened every 3 days, a sell would never trigger because the 6 day rule wouldn't be hit.

UTB
 
I see the problem but as yet I can't fix it. The sell is triggering 6 days after the last time a buy condition was hit, rather than 6 days after an original buy. So if those conditions happened every 3 days, a sell would never trigger because the 6 day rule wouldn't be hit.

UTB

LOL.... Not this issue again!!!! This is similar to a problem I have with my own systems. Basically, in my systems I need to reference the original Buy but instead the latest Buy is used which sometimes causes problems with my Risk Management rules...

In your example, You need to remove the redundant Buys and calculate the exit at the SAME TIME, bar by bar. Consequently, there is only one way to solve this. Basically, the Sell condition needs to be placed in a loop.

I posted my original problem on a forum and got a detailed but slightly complicated reply. My code contained a lot of variables so I struggled to understand what was going on!!!!

However, your example is pretty straightforward, so I'll try and dig out the reply and play around with that code to hopefully help resolve this problem.

Give me an hour or so..........

Chorlton

PS. Can you PM your email address as I may have something of interest for you.......
 
I see the problem but as yet I can't fix it. The sell is triggering 6 days after the last time a buy condition was hit, rather than 6 days after an original buy. So if those conditions happened every 3 days, a sell would never trigger because the 6 day rule wouldn't be hit.

UTB

Hi Blades,

Ok mate, I think I've fixed the problem. As I mentioned in my last post, the issue was that the Sell Condition needed to be placed in a loop. I've managed to modify the code that was kindly supplied to me to fix one of my own problems and I think it will work. For future reference, Barssince function will always reference the last Buy so in certain cases (like this one) problems can arise.

Anyway, just replace your Sell condition with the following code and re-plot the signals.


Sell = False;
inTrade = False;
bcnt = 0;

for (i = 0; i < BarCount; i++)
{
if (inTrade)
{
Buy = False;
}

if (++bcnt == Length)
{
inTrade = False;
Sell = True;
}
else
{
if (Buy)
{
inTrade = True;
bcnt = 0;
}
}
}
 
Hi Blades,

Ok mate, I think I've fixed the problem. As I mentioned in my last post, the issue was that the Sell Condition needed to be placed in a loop. I've managed to modify the code that was kindly supplied to me to fix one of my own problems and I think it will work. For future reference, Barssince function will always reference the last Buy so in certain cases (like this one) problems can arise.

Anyway, just replace your Sell condition with the following code and re-plot the signals.


It's a good job your at the other side of the world or I'd kiss you:D

Thanks - worked a treat...I think. Definitely got the right delay in anyway.

Cheers,
UTB

PS - so much for an Amibroker forum - looks like it's me and you kid:) Oh, and email address on the way - I missed your earlier request.
 
Last edited:
It's a good job your at the other side of the world or I'd kiss you:D.

Err... A simple "Thanks" is more than sufficient ;)


PS - so much for an Amibroker forum - looks like it's me and you kid:) Oh, and email dress on the way - I missed your earlier request.

Thats fine with me. I'm sure as we explore AB and its language we'll be able to help out each other.... 2 heads being better than 1 and all that !!!

Hopefully, if we can keep this thread going, we may even draw some further interest from others. Afterall, considering the level of functionality that AB has & its relatively cheap purchase price, I'm genuinely surprised that others haven't decided to use it..... yet :cool:
 
Err... A simple "Thanks" is more than sufficient ;)




Thats fine with me. I'm sure as we explore AB and its language we'll be able to help out each other.... 2 heads being better than 1 and all that !!!

Hopefully, if we can keep this thread going, we may even draw some further interest from others. Afterall, considering the level of functionality that AB has & its relatively cheap purchase price, I'm genuinely surprised that others haven't decided to use it..... yet :cool:

Yes - I'm stunned at how good it seems, and gutted I've sat on it for years without use. I'm now trading from home, full time - so I've at least got some time to dedictae to it. Credit to you for working and learning in your spare time. In the end, I suppose I'm a lazy bugger.

BTW - something in the email for you - hope it's of some use. Sorry it's big.

Cheers,
UTB
 
OK - next issue.

The buys and sells are indicating correct on the chart. But when this is optimised, the winning and losing averge bars is nothing like the length parameter, which it should be fixed at. Even when I change the base setting to 15, the number of bars remains around 6 or 7.

Any ideas?

Cheers,
UTB
 
OK - next issue.

The buys and sells are indicating correct on the chart. But when this is optimised, the winning and losing averge bars is nothing like the length parameter, which it should be fixed at. Even when I change the base setting to 15, the number of bars remains around 6 or 7.

Any ideas?

Cheers,
UTB

Blades,

I've just modified the length variable to 12 and re-run the code. The Sell arrows are now 12 bars after the Buy signals, as expected. Not sure why you have having problems here :confused:
 
Not sure why you have having problems here :confused:

because I'm useless:)

I had the nbar stop setting switched on after your previous suggestion. It works now.

For your info, you can replace the code you supplied with;

Buy=ExRemSpan(Buy,length);
Sell = Ref(Buy,-length);

The exremspan function. I'm sure the looping has its place (I'll get into the material you sent later) but thought I should share this with you.

Cheers,
UTB
 
because I'm useless:)

I had the nbar stop setting switched on after your previous suggestion. It works now.

For your info, you can replace the code you supplied with;

Buy=ExRemSpan(Buy,length);
Sell = Ref(Buy,-length);


The exremspan function. I'm sure the looping has its place (I'll get into the material you sent later) but thought I should share this with you.

Cheers,
UTB

Hey Blades,

I wasn't even aware of the ExRemSpan function :eek: Nice one bud!!! I've taken a look in the online help and yes, for your application, it works a treat!!! :D

Well discovered ;)
 
Chorlton (or anyone else....?),

Any ideas about this?

When I portfolio backtest a trading system (in fact any system) and
have "trade list" selected in the report settings, I get a very limited
list of stocks in the list. I have set the maximum open positions
to "1000" so as not to limit this.

This only occurs if I backtest against a large portfolio - and the
stocks in the early part of the alphabet show on the list. (A,B C etc).

If I test on a limited ammount of stock, say the S&P500, I don't seem
to get this problem.

The smaller trade list gives me concerns about the acutaul results
being generated.

UTB
 
Chorlton (or anyone else....?),

Any ideas about this?

When I portfolio backtest a trading system (in fact any system) and
have "trade list" selected in the report settings, I get a very limited
list of stocks in the list. I have set the maximum open positions
to "1000" so as not to limit this.

This only occurs if I backtest against a large portfolio - and the
stocks in the early part of the alphabet show on the list. (A,B C etc).

If I test on a limited ammount of stock, say the S&P500, I don't seem
to get this problem.

The smaller trade list gives me concerns about the acutaul results
being generated.

UTB

mmm... not sure...

Some ideas/thoughts....

- What [SetOption] settings have you included in your actual code (if any) and what settings have you got selected in the Settings area of the Automatic Analysis window?

- If you vary the # of open positions (from a very small number.... say 5) and then increase it gradually does this make any difference to the number of trades returned? Do the number of trades also increase and then get capped at a specific number?

- Could this have something to do with the Position size of your trade vs your overall capital? Probably barking up the wrong tree here but say your position size for a trade is 10% of overall capital, you will only get 10 open trades at one time.


I'll have a play when I get a moment and see what else it might be & Apologies for not being that helpful at the moment :(

Chorlton
 
Top