Australian (ASX) Stock Market Forum

Amibroker: Change Sell condition based on # of consecutive losses

Joined
9 October 2009
Posts
27
Reactions
0
Hi,

I'm not too bad with AFL coding but not sure where to start with a situation I want to try and code.
Imagine I have a sell condition such as:
period = 30;
Sell = cross(c,MA(c,period));

What I want to do is backtest some logic were if I'm trading and I have more than x number of consecutive loses I can change the period variable from 30 to say 10.

The idea is that if I'm on a bit of a losing streak due to poor trading conditions for my system I can tighten the sell citeria to limit drawdown. If I then win a trade the period variable resets to 30.

Would anyone have any idea how I can do this from a backtesting perspective. I'm thinking the custom backtester but not sure how I'd work out consecutive loses and then use this to change hthe sell criteria on the fly for the next trade?

Any ideas?

Thanks
 
I was looking into this and I think as a first step it might be easier to look at the consec losses and then just reduce the position size until I get y number of consec winners.
I can see via the custombacktester objects that I can work out the profit (and therefore whether it was a W or L) via the trade object. However, it looks like I then have to somehow go back to the signal object in order to then change the position size for subsequent trades, not really sure if this is the correct approach.
Any one with custom backtester knowledge out there to give me a few hints on this?

Thanks
 
I was looking into this and I think as a first step it might be easier to look at the consec losses and then just reduce the position size until I get y number of consec winners.
I can see via the custombacktester objects that I can work out the profit (and therefore whether it was a W or L) via the trade object. However, it looks like I then have to somehow go back to the signal object in order to then change the position size for subsequent trades, not really sure if this is the correct approach.
Any one with custom backtester knowledge out there to give me a few hints on this?

Thanks

Have you tried Marcin or TJ?

I asked them a very similar question a while back, but unfortunately the answer was above my level of understanding! Have you read this?
http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/

Marcin did offer this: "For individual symbols – you may also be tracking trades in a for loop or compare ValueWhen(Sell,C) - ValueWhen(Buy,C) and determine position-sizing based on that". Makes perfect sense but I don't know how to code that.

If you work it out, please let us know.
 
when you say 'have i tried mancin or TJ'?
What do you mean? How do I contact them?

I've read the user guide on it and I get it as I have a background in OO programming but it's more understanding how I'd do it rather than the actual coding of it.

Thanks
 
when you say 'have i tried mancin or TJ'?
What do you mean? How do I contact them?

I've read the user guide on it and I get it as I have a background in OO programming but it's more understanding how I'd do it rather than the actual coding of it.

Thanks

Have you paid for your copy of Amibroker?
 
I guess if you don't know who Marcin and TJ are, maybe you've got an illegal copy. If it's stolen, you're not going to get help from anyone
 
Yes, I have a paid copy. I know that TJ is the guy who developed Amibroker but I don't know who Mancin is - that doesn't automatically mean I have stolen a copy.
I know I can get support but I see support as something they would provide if there was a bug in the software, I didn't know it extended to helping the buyer understand the custom backtester with specific questions and answers? Maybe it does?
Anyway, if your sole response to my question is to accuse me of theft then maybe you shouldn't bother replying.
 
Do a search on "amibroker Custom BackTester Interface Rev 5 July 2007"

What you need to do is access the trades property as shown in code below from that document.
SetCustomBacktestProc("");if (Status("action") == actionPortfolio){bo = GetBacktesterObject(); // Get backtester objectbo.Backtest(); // Run backteststotalDays = 0; // Total number of winning daystotalTrades = 0; // Total number of winning tradesfor (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade()){ // Loop through all closed tradesif (trade.GetProfit() > 0) // If this was a winning trade{totalDays = totalDays + DayCount(trade.EntryDateTime, trade.ExitDateTime);totalTrades++;}} // End of for loop over all tradesavgWinDays = totalDays / totalTrades; // Calculate average win daysbo.AddCustomMetric("AvgWinDays", avgWinDays); // Add to results display​
}


 
Top