Australian (ASX) Stock Market Forum

Developing a mechanical system from scratch

heres a few more from the scans tonite.....
 

Attachments

  • IVC.jpg
    IVC.jpg
    83.3 KB · Views: 147
  • IFL.jpg
    IFL.jpg
    80.5 KB · Views: 147
  • MBL.jpg
    MBL.jpg
    82.2 KB · Views: 148
So why can't we tack on a simple code such as this onto Lesm's code....

Buy = Open > Ref( Close , -1 );

Sell = 0;

Short = Open < Ref( Close , -1 );

Cover = 0;

I needs some help with your code Lesm, how to i make your the cond, and then add the simple triggers?

Cheers,
 
Attached is a bit of a montage of some of the historical entries I identified so others can get a feel for it.

I added one thing to the code - the fourth day in the sequence closes higher than the high of the first day (ie. you'd enter on day 5 of the sequence).

After looking at this on many historical charts, my empirical observation is that it probably makes it untradeable. If we are to keep an EOD system, perhaps we should look to trade it by setting buy triggers a tick or two above the high of the first bar o/n after day 3 of the sequence rather than waiting for the confirmation of the break on day 4 then enter on day 5.

Short term trading is well out side my comfort zone, so I'd be very interested to hear feedback on the above points.

PS. Wooooo! Post 1000. I was really hoping it would be something more profound - it certainly took me long enough to reach the milestone. Cheers Joe for a great forum!
 

Attachments

  • entries.GIF
    entries.GIF
    15.4 KB · Views: 143
Hi Can,

I am still playing around with it at the moment.

Have included a bit of a framework to define some of the system options and what is displayed in the AA results table.

The ATR approach wasn't too successful, so I have gone back to a very simplistic approach using a single EMA as starter.

Digesting ASXG's and Doc's comments at the moment and going back through Nick's as well.

Will post where I am at for the moment, as a work in progress. Tech was also going to work on some coding. The combined effort will be interesting in reaching the final system.

Haven't put in the Sell and Cover conditions as yet, but this should give you something to work with. You can replace the EMA with your buy conditions.

Need to go back through the charts and look at the behaviour in more detail.

As Doc mentioned you need to get a feel for it, as this will assist in better defining a more effective trigger point.

Code:
/* 

ASF Sample System Development 2 Inside days

*/

// Define system options - can modify these as required

SetChartOptions( 2, chartShowDates|chartShowArrows ); 
SetBarsRequired(10000,10000); 
SetTradeDelays( 1, 1, 1, 1);
SetOption( "initialequity", 100000 );
SetOption( "MaxOpenPositions", 10 ); 
SetOption( "PriceBoundChecking", 1 ); 
SetOption( "CommissionMode", 1 ); 
SetOption( "CommissionAmount", 0.1 ); 

BuyPrice = SellPrice = Open;
ShortPrice = CoverPrice = Open;
PositionSize = -10; // always invest 10% of the current Equity 

// Define and initialise variables

ATRMult = 3.5;
ATRPeriod = 14;

// Check if 2 Inside days occur

InsideDay1 = H < Ref(High,-1) AND Low > Ref(Low,-1);
InsideDay2 = Ref(High,-1)< Ref(High,-2) AND Ref(Low,-1)> Ref(Low,-2);
InsideDayCond = InsideDay1 == 1 AND InsideDay2 == 1;

/*
Notes:

To Do:

Add in a liquidity filter
Consider prerequisite conditions for trade entry

From Nick's post:

Consider an appropriate reference point.

Possibility of using n ATR:
if entry condition met then look for entry trigger;
if High is exceeded by n ATR then enter long;
if Low is exceeded by n ATR then enter Short;
*/

// Long side - buy and sell conditions

// Buy Condition

BuySig = InsideDayCond AND High > EMA(C,35);
 
// Sell Condition 
 
// SellSig = condition.......

Buy = BuySig;

//Buy = ExRem(BuySig, SellSig); 
//Sell = ExRem(SellSig, BuySig);

// Short side - short and cover conditions

// Short Condition

ShortSig = InsideDayCond AND Low < EMA(L,35);
 
// Cover Condition

// CoverSig = condition .......

Short = ShortSig;

//Short = ExRem(ShortSig, CoverSig);
//Cover = ExRem(CoverSig, ShortSig);


// Lists exploration results conforming to our buy/sell OR short/cover criteria
 
//Filter = Buy OR Sell OR Short OR Cover;

Filter = Buy OR Short;

AddColumn(Buy, "Buy", 1, colorDefault,IIf(Buy,colorGreen,colorDefault));
//AddColumn(Sell, "Sell", 1, colorDefault,IIf(Sell,colorRed,colorDefault));
AddColumn(Short, "Short", 1, colorDefault,IIf(Short,colorGreen,colorDefault));
//AddColumn(Cover, "Cover", 1, colorDefault,IIf(Cover,colorRed,colorDefault));
AddColumn(Open, "Open", 4.3); 
AddColumn(Low, "Low", 4.3);
AddColumn(High, "High", 4.3);
AddColumn(Close, "Close", 4.3);
 
This is doing my head in!!!!:banghead:

I can't get it to buy on the next bar after the insidedaycond.

It keeps buying on inside bar 1.....

Enough for tonite...my GF and i have been trying to figure it out....she's catching onto AFL faster than me.

Cheers,
 
Mine will be metastock format.

We can convert to AB. Can will appreciate any input

Nick,

I have been looking at the charts of the stocks selected, using an exploration over the last 20 days, and they have quite interesting characteristics.

Have a couple of questions for you.

Would it be worthwhile considering an approach similar to the ID/NR4Day system as described by Connors and Raschke?

(Have already set up a variant based on this approach to see out it works out)

There are some similarities here. One difference is that we are looking for two inside days as opposed to one.

This is an interesting exercise.
 
Would it be worthwhile considering an approach similar to the ID/NR4Day system as described by Connors and Raschke?
I believe this has been discussed over at reefcap. Nick may be able to provide more info.
 
This is doing my head in!!!!:banghead:

I can't get it to buy on the next bar after the insidedaycond.

It keeps buying on inside bar 1.....

Enough for tonite...my GF and i have been trying to figure it out....she getting it (AFL) faster than me.

Cheers,

Will have a closer look.

At least there are multiple eyes looking at this and we can check it out.

Do you have SetTradeDelays (1, 1, 1, 1) in your code?

Or if not, in Automatic Analyser (AA) under the Trades Tab in the Buy and Sell delay settings do you have them set to "1"?

Otherwise, AB will buy/sell on the current bar/day if the delay settings are set to "0".

Have a good night.
 
Have done some more work on this.

Still need to work on the Sell and Cover conditions, as well as stops and reviewing the existing conditions.

Using a 'buy stop' and 'sell stop' may be worthwhile considering, as well as running an initial tight stop.

Any input or suggestions appreciated.

Have a full on morning tomorrow, so will not be able to look at this again until some time in the afternoon.

Code:
/* 

ASF Sample System Development

 2 Inside days AND 6/100 Historical Volatility Ratio

*/

// Define system options can modify these as required

SetChartOptions( 2, chartShowDates|chartShowArrows ); 
SetBarsRequired(10000,10000); 
SetTradeDelays( 1, 1, 1, 1);
SetOption( "initialequity", 100000 );
SetOption( "MaxOpenPositions", 10 ); 
SetOption( "PriceBoundChecking", 1 ); 
SetOption( "CommissionMode", 1 ); 
SetOption( "CommissionAmount", 0.1 ); 

BuyPrice = SellPrice = Open;
ShortPrice = CoverPrice = Open;
PositionSize = -10; // always invest 10% of the current Equity 

// Setup Conditions

VolumeCond = EMA(V * C, 21) > 500000; // Ensure at least $500k of money flow for 21 periods
EMABuyCond = EMA(C, 35);
EMAShortCond = EMA(L, 35);

// BuyTrigCond = O > Ref(L,-1); not used in this version

// NR4DAY
// NR4Day = (H - L) < Ref(LLV(H-L,3),-1); // not used in this version

// 6/100 Historical Volatility
HVSixOneHundred = (StDev(log(C/Ref(C,-1)),6)*100*sqrt(256)) / (StDev(log(C/Ref(C,-1)),100)*100*sqrt(256));
HVRatioCond = HVSixOneHundred < 0.5;

// Check if 2 Inside days occur

InsideDay1 = H < Ref(High,-1) AND Low > Ref(Low,-1);
InsideDay2 = Ref(High,-1)< Ref(High,-2) AND Ref(Low,-1)> Ref(Low,-2);
InsideDayCond = InsideDay1 == 1 AND InsideDay2 == 1;

// Long side - buy and sell conditions

// Buy Condition

BuySig = InsideDayCond AND HVRatioCond AND VolumeCond AND C > EMABuyCond ;
 
// Sell Condition 
 
// SellSig = condition.......

Buy = BuySig;

//Buy = ExRem(BuySig, SellSig); 
//Sell = ExRem(SellSig, BuySig);

// Short side - short and cover conditions

// Short Condition

ShortSig = InsideDayCond AND HVRatioCond AND VolumeCond AND Low < EMAShortCond;
 
// Cover Condition

// CoverSig = condition .......

Short = ShortSig;

//Short = ExRem(ShortSig, CoverSig);
//Cover = ExRem(CoverSig, ShortSig);

// Define Stoploss Conditions

ApplyStop(stopTypeLoss, stopModePercent, amount = 10 );

// Lists exploration results conforming to our buy/sell OR short/cover criteria
 
//Filter = Buy OR Sell OR Short OR Cover;

Filter = Buy OR Short;

AddColumn(Buy, "Buy", 1, colorDefault,IIf(Buy,colorGreen,colorDefault));
//AddColumn(Sell, "Sell", 1, colorDefault,IIf(Sell,colorRed,colorDefault));
AddColumn(Short, "Short", 1, colorDefault,IIf(Short,colorGreen,colorDefault));
//AddColumn(Cover, "Cover", 1, colorDefault,IIf(Cover,colorRed,colorDefault));
AddColumn(Open, "Open", 4.3); 
AddColumn(Low, "Low", 4.3); // 
AddColumn(High, "High", 4.3); // 
AddColumn(Close, "Close", 4.3); //
 
well done guys, I was losing hope on this thread for a while

.. as Kenny would say, "good on you" ... to those pushing this thread forward.
 
well done guys, I was losing hope on this thread for a while

.. as Kenny would say, "good on you" ... to those pushing this thread forward.


AH.

A metastock coding expert!
Want to lend a hand?
 
lesm,
Another variant of that theme could be something as simple as:

If range today < range[yesterday] and range[yesterday] > range[day before]

It's still the contracting range theory, but means the individual highs and lows can be outside each other. The NR7 or NR4 is exactly the same theory. By extending the range contraction you will see a decline in trade frequency. If trading a broader range of instruments this may be beneficial.

We're using range expansion to enter, so it may be beneficial to use a reverse range expansion as an exit. We can discuss this later.

In the interim, here is your benchmark. A short term system that works on all stocks. This has a 1-day hold time, uses EOD data, $10k per trade and includes comm's.

absdb5.png
 
Morning all, welcome aboard Weird.

Thanks again Lesm and Nick!

I pulled this out of the scan with the recent changes above....i'm still signaling on the wrong day, after I changed the settings...thanks for tip the Lesm...not sure where i'm still wrong here.

I think i've learned more about Amibrokers testing features over the last couple of days than i could have on my own thats for sure!

I still can't backtest this though...something to do with the buy/sell signals?

:eek: - sorry folks, still very green.

cheers,
 

Attachments

  • adblesm3.jpg
    adblesm3.jpg
    66.4 KB · Views: 130
I still can't backtest this though...something to do with the buy/sell signals?

There is no sell condition.

Add:

Sell = 0;

Edit: Even though Applystop is in the code, you still have to have a Sell. Adding Sell = 0; just makes the backtester happy, it doesn't do anything! :D
 
This is doing my head in!!!!:banghead:

I can't get it to buy on the next bar after the insidedaycond.

It keeps buying on inside bar 1.....

Instead of working like Metastock and trying to delay the actual buying to the next day you could instead run checks on [bar-1] and issue your buy signal on [bar].

For example:

for (bar = 1; bar < BarCount; bar++) // start a loop that begins at bar #1 and increments a bar at a time until last bar
{
InsideDay1 = High[bar-1] < High[bar-2] AND Low[bar-1] > Low[bar-2];
InsideDay2 = High[bar-2] < High[bar-3] AND Low[bar-2] > Low[bar-3];
YesterdaysInsideDayCond = InsideDay1 == 1 AND InsideDay2 == 1;

// If double inside day condition met yesterday...
if (YesterdaysInsideDayCond == 1)
{
// ...buy at today's open
Buy[bar] = 1;
BuyPrice[bar] = Open;
}
}

This could be tidied up a bit eg. the YesterdaysInsideDayCond turned into a function and called instead of the code sitting inside the loop, but it ought to work okay as it is.

ASX.G
 
There is no sell condition.

Add:

Sell = 0;

Edit: Even though Applystop is in the code, you still have to have a Sell. Adding Sell = 0; just makes the backtester happy, it doesn't do anything! :D

As a good habit put this at the top of your AB code, just before the beginning of your buy/sell/short/cover loop:

Buy = Sell = Short = Cover = 0;
 
Nick that was to be the basis of my code.

Youve got me fossicking in the Library for Joe Ross's books!
More little snippets of experience.
Thanks.
 
Not sure if this is all ok but heres a report....
 

Attachments

  • BTLesm3ASF.jpg
    BTLesm3ASF.jpg
    74.6 KB · Views: 140
Top