Australian (ASX) Stock Market Forum

Dump it Here

What sort of results do you get running that code on ASX? Or, would you share your AB code please, so we can try it?


Instead of this:

First Rank all tickers by their 200 day ROC and take the top 50 stocks from this ranked list

Rank these top 50 stocks by their 100 day ROC and take the top 25 from this 2nd ranked list

From this final list of 25 stocks, Rank them by their 50 day ROC and take the top 10 stocks


could you weight them in a single line?

eg.

rank = 2*ROC(c,200) + 10*ROC(c,100) + 20*ROC(c,50)

or whatever weighting you like. This would obviously give more weighting to recent performance.

As promised, this is my basic dual momentum rotational code, please let me know if you spot any errors.

I'm still working on a system that conducts multiple sorting runs to see if I can get it to work... debugging amibroker can be a real pain tbh...

C++:
//==================================
//     Basic Dual Momentum System   ===
//     AFL By Willzy                 ===
//==================================

// Be sure to set your trade settings in the settings window because for Rotational Trading Mode, the script code will not work.
// ie BuyPrice = Open, SellPrice = Open.

//     --- Include Files --- //
#include_once "Formulas\Norgate Data\Norgate Data Functions.afl"

// --- Functions --- //

//OptimizerSetEngine("cmae");
SetBacktestMode( backtestRotational );

//--- Rotation settings
nPos = 10;//Optimize("nPos",5,3,20,1);
worstRankHeld = 10;//Optimize("worstRankHeld",15,5,20,1);
SetOption("BuyDelay",1);
SetOption("MaxOpenPositions", nPos);
SetOption("WorstRankHeld",worstRankHeld);

//--- account Settings
SetOption( "CommissionMode", 2 );
SetOption( "CommissionAmount", 0 );

//--- All Positions Use Max Available Equity - Compounded Returns
posSize = 100/(nPos);
SetOption("InitialEquity",100000);
SetPositionSize(posSize,spsPercentOfEquity);

// Set Price Arrays for price and vol filters
CloseArray = NorgateOriginalCloseTimeSeries();
VolumeArray = NorgateOriginalVolumeTimeSeries();
priceFilter = CloseArray >= 10;   
                        
//--- Set foreign symbol for the indexFilter and Constituents
indexSymbol = "$NDX";

//--- Symbol exists within index at the time
canTrade = NorgateIndexConstituentTimeSeries(indexSymbol);

//--- index Filter
index = Foreign( "$NDX", "Close" );
indexPeriod = 200;
indexFilter = index > MA(index,indexPeriod);

//--- rankingScore
symScore = 0.4 * ROC(C,63) + 0.2*ROC(C,126) +  0.2*ROC(C,189) + 0.2*ROC(C,252);

//---symbol moving up
symbolFilter = C>MA(C,200) AND symScore > 0;

//--- Final Score Function
posScore =     Max(0,
                canTrade *
                priceFilter *
                indexFilter *
                symbolFilter *
                symScore
                ) ;


//--- rotate only at beginning of the month
Monthly = TimeFrameExpand(1, inMonthly, expandPoint);

PositionScore = IIf(monthly, Ref(posScore,-1), scoreNoRotate);

Filter = 1;
AddColumn( ROC(C,63), "ROC 50",1.4, colorBlack);
AddColumn( ROC(C,126), "ROC 100",1.4, colorBlack);
AddColumn( ROC(C,189), "ROC 250",1.4, colorBlack);
AddColumn( ROC(C,252), "ROC 500",1.4, colorBlack);
AddColumn( indexFilter, "indexFilter",1.4, colorBlack);
AddColumn( symScore, "symScore",1.4, colorBlack);
AddColumn( posScore, "posScore",1.4, colorBlack);
AddColumn( Close, "Close",1.4, colorBlack);
AddColumn( DayOfWeek(), "dayOfWeek",1.1, colorBlack);
 
Willzy,
this is my version of rotational trading (actually, I've found it somewhere). It's very primitive compared to yours.
I've backtested it on ASX100 historical constituents since 2010, 13 years.

//////////

SetBacktestMode( backtestRotational );

SetOption("InitialEquity", 100000);
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", 9.5); // SelfWealth

SetTradeDelays( 1, 1, 1, 1);

Totalpositions = 10;

SetOption("WorstRankHeld", 20);
SetOption("MaxOpenPositions", Totalpositions );
PositionSize = -100 / Totalpositions ;

LastDayOfMonth = IIf( (Month() == Ref( Month(), 1) AND (Month() != Ref( Month(), 2)) ), 1, 0);
TradeDay = LastDayOfMonth ;

Rank = ROC(C, 250) * [ this contains the code for historical ASX100 constituents ]; // not using Norgate

PScore = IIf(Rank < 0, 0, Rank );
PositionScore = IIf(TradeDay , PScore , scoreNoRotate);

/////////

I don't trust it although I can't find any mistake in the code. The results are too good to be true.
But these things are highly parameter-sensitive, and you are using a lot of them. There is another worry. Try starting a few months either way and you double or halve the returns. I haven't made it trade on different days, e.g. 1st day or middle of the month and that's even more degrees of freedom.
Try it with 8 or 12 positions instead of 10, never mind your finessing of the ROC() lookback period.

If I'm wrong about this, I'll be ecstatic and be trading it right away.
 
Willzy,
this is my version of rotational trading (actually, I've found it somewhere). It's very primitive compared to yours.
I've backtested it on ASX100 historical constituents since 2010, 13 years.

//////////

SetBacktestMode( backtestRotational );

SetOption("InitialEquity", 100000);
SetOption("CommissionMode", 2);
SetOption("CommissionAmount", 9.5); // SelfWealth

SetTradeDelays( 1, 1, 1, 1);

Totalpositions = 10;

SetOption("WorstRankHeld", 20);
SetOption("MaxOpenPositions", Totalpositions );
PositionSize = -100 / Totalpositions ;

LastDayOfMonth = IIf( (Month() == Ref( Month(), 1) AND (Month() != Ref( Month(), 2)) ), 1, 0);
TradeDay = LastDayOfMonth ;

Rank = ROC(C, 250) * [ this contains the code for historical ASX100 constituents ]; // not using Norgate

PScore = IIf(Rank < 0, 0, Rank );
PositionScore = IIf(TradeDay , PScore , scoreNoRotate);

/////////

I don't trust it although I can't find any mistake in the code. The results are too good to be true.
But these things are highly parameter-sensitive, and you are using a lot of them. There is another worry. Try starting a few months either way and you double or halve the returns. I haven't made it trade on different days, e.g. 1st day or middle of the month and that's even more degrees of freedom.
Try it with 8 or 12 positions instead of 10, never mind your finessing of the ROC() lookback period.

If I'm wrong about this, I'll be ecstatic and be trading it right away.
Hi Algo,

I may be wrong but I think you have a future leak with your posScore, you might be okay but I think with the rotational trading mode, the set trade delays fn will not work.

U need to set it in the settings window, a quick way to test is to use ref(Rank,-1) as your pScore

Let me know if that helps!

Cheers
 
Happy 4th Birthday @Skate with your "Dump it Here" thread ?.
It's a cracker of a thread with lots of great content for lots of different traders and at the same time at different levels of experience. If you can't pick up something here that's beneficial to you I'd be very surprised. Thank you for your many posts of information, it's much appreciated by many :xyxthumbs.
Also before it's too late, Merry Christmas to you, your family and all the ASF members that follow, support and comment in your thread .
 
Happy 4th Birthday @Skate with your "Dump it Here" thread ?.
It's a cracker of a thread with lots of great content for lots of different traders and at the same time at different levels of experience. If you can't pick up something here that's beneficial to you I'd be very surprised. Thank you for your many posts of information, it's much appreciated by many :xyxthumbs.
Also before it's too late, Merry Christmas to you, your family and all the ASF members that follow, support and comment in your thread .

@debtfree, thank you for your ongoing kind words. I have appreciated each & every one of your birthday wishes for each of the last 4 years.

Merry Christmas
It goes without saying, I wish you & the many contributors to this thread a Merry Christmas & a very prosperous New Year.

Merry Christmas.jpg

Skate.
 
Hi Algo,

I may be wrong but I think you have a future leak with your posScore, you might be okay but I think with the rotational trading mode, the set trade delays fn will not work.

U need to set it in the settings window, a quick way to test is to use ref(Rank,-1) as your pScore

Let me know if that helps!

Cheers

Willzy, you're right, there must be a future leak, only I haven't found it yet. Ref -1) in the PositionScore doesn't fix it. Neither does ROC(Open) instead of Close. In fact, everything I've tried so far seems to confirm that this system is quite profitable. I know intuitively that this must be wrong.

It's important that you, yes, you should find out what's wrong with this code. You want to use a much more complicated strategy based on the same basic code to trade or invest real money.

If I have some spare time this weekend I'll have another go at it. But in my opinion trading systematically with holding times of months is trading randomly. You will not have enough trades in an entire lifetime to prove statistically that it's not just luck that produced your profits.

Discretionary trading with skill and good judgement is an entirely different proposition and a talented trader can be very profitable.

The original code was found here:

For anyone else using AmiBroker this could be a good learning experience. My flawed code is very simple. Just imagine trying to find a mistake in hundreds of lines with several indicators and dozens of parameters.

AmiBroker is full of traps for young players.
 
Daily rituals
There is nothing like routine to keep you active & above what's happening in the world of trading. Each morning I enjoy reading @bigdog's "nyse-dow-jones-finished-today-at" thread, @barney's "price-sensitive-announcements" & @ducati916's worldly posts. There is always a section of Duc's daily posts that I particularly enjoy reading & that's the musing of "Flippe Flye". (a skilled trader by any measure)

This year has been tough
You only have to read the Twitter posts of one of our ASF members who reported today that his YTD PnL: was down (-$983,811) (yikes!!) whilst at the same time posting charts confirming others are doing poorly as well. I guess surrounding yourself with similar poor performancers makes you feel somewhat better about your own trading.

Trading has not been all "Doom & Gloom" for everyone
Dr. Fly has achieved good trading results this year that's worthy of a post in itself.

Skate.
 
Not everyone has traded poorly
See, it's not all gloom & doom as Mr "Flippe Flye" is one trader who has performed extremely well this year. I should also point out that Dr. Fly is a licensed professional & by law has the right to offer investment advice.

Dr. Fly remarked: Trading requires skill
"I closed at another RECORD HIGH not because of luck or due to some sort of fluke — but skill. Markets are broken — but I am no longer concerned. It seems everything I do now works and I cannot lose money — even if I tried. Ergo, smooth sailing for House Fly from here until the end of the year. I’d be remiss if I did not boast about my market exploits. After all, if I didn’t — how else would you come to realize your skills are in fact INFERIOR to mine?

Dr. Fly's equity curve
YTD gains are approaching 60%, a remarkable difference from what's being reported elsewhere.

Dr Fly.jpg


Skate.
 
20Kay Gold Logo.jpg

No "Buy Signals" this week
The "Percentage Index Indicator" is still below 50%, currently sitting at 38%. The "Moving Average" Index Filter is on (the bottom of the two ribbons) but until both ribbons are green the strategy is restricted in generating buy signals.

XAO.jpg

Skate.
 
Not everyone has traded poorly
See, it's not all gloom & doom as Mr "Flippe Flye" is one trader who has performed extremely well this year. I should also point out that Dr. Fly is a licensed professional & by law has the right to offer investment advice.

Dr. Fly remarked: Trading requires skill
"I closed at another RECORD HIGH not because of luck or due to some sort of fluke — but skill. Markets are broken — but I am no longer concerned. It seems everything I do now works and I cannot lose money — even if I tried. Ergo, smooth sailing for House Fly from here until the end of the year. I’d be remiss if I did not boast about my market exploits. After all, if I didn’t — how else would you come to realize your skills are in fact INFERIOR to mine?

Dr. Fly's equity curve
YTD gains are approaching 60%, a remarkable difference from what's being reported elsewhere.

View attachment 150583


Skate.
"It seems everything I do now works and I cannot lose money — even if I tried".

This....

is a belief.

I've been in that place. Probably most experienced traders have been in that place where everything you touch turns to gold. It's an amazing feeling. But purple patches are mind-generated. Money is created with the mind, not a system. It looks very much like it's the system that's creating the endless flow of profits, but it's an illusion.

It's only because I have not mastered my own mind that I still rely so heavily on my system. But 100% discretion is the ultimate form of trading, imo. Most others here will disagree, but I'm very confident about this!
 
It looks very much like it's the system that's creating the endless flow of profits, but that's an illusion.

@Gringotts Bank, you may be correct. I've often said whilst watching sports "that's got to be a fluke" but they seem to fluke it 100% of the time. I believe some traders are better than others & I don't believe there is enough thinking "about" why they are.

I've put my trading success down to the strategies I trade
I find using metrics as part of my "buy condition" to be beneficial. Over the years I've made my share of indicators. Those indicators may not be perfect but they tend to fluke the results that I'm after more times than they don't.

My "Percentage Position Up" indicator & my "Ulcer Up" indicator
Both these indicators go a long way in helping me achieve profitability. My "Percentage Up Indicator" & the relationship it creates is shown on the chart below.

Winner.jpg

The "Percentage Indicator"
When the "percentage indicator" is above 50% there is a corresponding rise in the ASX All Ordinaries Index. Restricting the "buy condition" to only when the "Percentage Up Indicator" is above 50% helps avoid the nasties created by using an "Index Filter" in isolation. (which, by-the-way IMHO is better than none)

I believe there is a correlation
The "Percentage Up Index Filter" above 50% & the All Ordinaries pops at the same time. I don't believe this is a "fluke" or an "illusion" but a defined "correlation". Restricting trading during these periods (above 50%) gives you a fighting chance of profitably, which is basically "the name of the game".

XAO.jpg

Skate.
 
@Gringotts Bank, you may be correct. I've often said whilst watching sports "that's got to be a fluke" but they seem to fluke it 100% of the time. I believe some traders are better than others & I don't believe there is enough thinking "about" why they are.

I've put my trading success down to the strategies I trade
I find using metrics as part of my "buy condition" to be beneficial. Over the years I've made my share of indicators. Those indicators may not be perfect but they tend to fluke the results that I'm after more times than they don't.

My "Percentage Position Up" indicator & my "Ulcer Up" indicator
Both these indicators go a long way in helping me achieve profitability. My "Percentage Up Indicator" & the relationship it creates is shown on the chart below.

View attachment 150591

The "Percentage Indicator"
When the "percentage indicator" is above 50% there is a corresponding rise in the ASX All Ordinaries Index. Restricting the "buy condition" to only when the "Percentage Up Indicator" is above 50% helps avoid the nasties created by using an "Index Filter" in isolation. (which, by-the-way IMHO is better than none)

I believe there is a correlation
The "Percentage Up Index Filter" above 50% & the All Ordinaries pops at the same time. I don't believe this is a "fluke" or an "illusion" but a defined "correlation". Restricting trading during these periods (above 50%) gives you a fighting chance of profitably, which is basically "the name of the game".

View attachment 150592

Skate.
Say someone ran a research project. 100 people with a similiar level of experience/knowledge, and gave them each $100k to trade in whichever way they choose for 3 months, and they get to keep the profits. I reckon I'd be able to tell you who will be in the top ten by the end of the project before it starts. And I think others could do it too, just that most people don't think this way.
 
Say someone ran a research project. 100 people with a similiar level of experience/knowledge, and gave them each $100k to trade in whichever way they choose for 3 months, and they get to keep the profits. I reckon I'd be able to tell you who will be in the top ten by the end of the project before it starts. And I think others could do it too, just that most people don't think this way.
First, let's be clean, i know what you ean.but not sure about your scenario
->If they keep the profits but not pay the losses, it is a very different behaviour /trading to an investor/trader using his her own money.
Whereas i am nearly out of the market and in cash today, in that scenario i would be 100% invested; all on for a xmas rally with specs and 1c shares.
This is also the difference between investing/trading your money vs a trader working for a bank or fund which will gain from profit but at worst will be sacked on losses..most probably not even .
 
First, let's be clean, i know what you ean.but not sure about your scenario
->If they keep the profits but not pay the losses, it is a very different behaviour /trading to an investor/trader using his her own money.
Whereas i am nearly out of the market and in cash today, in that scenario i would be 100% invested; all on for a xmas rally with specs and 1c shares.
This is also the difference between investing/trading your money vs a trader working for a bank or fund which will gain from profit but at worst will be sacked on losses..most probably not even .
Either way would work. Even if they used their own money or had to pay for losses.
 
The Turtle experiment resulted in a number of the group breaking the rules. A breach of discipline. Had they all traded 100% to the rules, then allowing for slippage in execution, their results would have been the same. Random events in this context are extrinsic to the individual. Thus must affect the entire group.

An intrinsic variation [random event] in a failure to execute to instructions, is a breach of discipline. The reason that they breached instructions may well be that they did not 'believe' but that is irrelevant to the question in this case: their belief or disbelief, had no direct impact on the profitability of the system [or not as the case maybe]. Their belief was that they could out-trade the system. This was proven to be false.

@ducati916 made a great post about why trading results vary between traders
Giving the traders the same strategy, the results will vary for a variety of reasons as Duc details. I've even posted that having "Peter Brock's" car wouldn't mean you would win a race at Bathurst back in the days when he was unbeatable.


Skate.
 
@ducati916 made a great post about why trading results vary between traders
Giving the traders the same strategy, the results will vary for a variety of reasons as Duc details. I've even posted that having "Peter Brock's" car wouldn't mean you would win a race at Bathurst back in the days when he was unbeatable.


Skate.
That second part was actually my quote, not ducati's.
 
Top