Australian (ASX) Stock Market Forum

Amibroker FAQ

Just seen this post.

Code:
switch( Name() ) {
    case "CCC": datecond = dn <= 1140201;  break;
    case "EEE": datecond = dn >= 1141101;  break;
    default: datecond = true; break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = Cross( m, Close )  AND datecond;
Short = Cover = 0;

Variable dn stands for

Code:
 dn = DateNum();

I am trying to marry a technical analysis overlay to fundamental analysis. I am a subscriber to a newsletter that provides various recommendations that are FA based.

My aim is to use this FA and overlay a momentum strategy to enhance outcomes.

I have a historical record of recommendations from this newsletter and I have been writing an AFL to test ideas. With this historical record I have symbols coming in at various stages and then leaving at a later date. On occasions the same symbol will then rejoin.

Any ideas on code that will allow a trade on a symbol from a certain date, exclude it at a later date and then allow a trade further on.

The above code partially works for new entries and exits, however it doesn't cater for a code which exits and then re-enters.

Also it doesn't give a sell condition for a code that is removed from the FA coverage

Any additional code would be gratefully received - Thanks
 
I'm not sure whether I understand correctly.
But if you wanna exclude a certain period then simply extend upper mentioned datecond variable.

For example if you wanna exclude year 2014:
Code:
datecond = dn < 1140101 OR dn > 1141231;

Or if you wanna set a specific date range before 2015 and then wanna proceed from 2015 onwards:
Code:
datecond = ( dn >= 1100101 AND dn < 1140101 ) OR dn >= 1150101;
 
I'm not sure whether I understand correctly.
But if you wanna exclude a certain period then simply extend upper mentioned datecond variable.

For example if you wanna exclude year 2014:
Code:
datecond = dn < 1140101 OR dn > 1141231;

Or if you wanna set a specific date range before 2015 and then wanna proceed from 2015 onwards:
Code:
datecond = ( dn >= 1100101 AND dn < 1140101 ) OR dn >= 1150101;

That is perfect! Thanks
 
I'm not sure whether I understand correctly.
But if you wanna exclude a certain period then simply extend upper mentioned datecond variable.

For example if you wanna exclude year 2014:
Code:
datecond = dn < 1140101 OR dn > 1141231;

Or if you wanna set a specific date range before 2015 and then wanna proceed from 2015 onwards:
Code:
datecond = ( dn >= 1100101 AND dn < 1140101 ) OR dn >= 1150101;

Hi Trash, could I get some more help here, your code has given me 98% of my objective.

Code:
dn = DateNum();
switch( Name() ) {
    case "ACR": datecond = ( dn >= 1110302 AND dn < 1120821 ) ;  break;
       default: datecond = true; break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = Cross( m, Close )  AND datecond;
Short = Cover = 0;

When I run this backtest for a period that goes after 21 August 2012, a trade initiated with a buy on 13 August 2012 does not close out and remains open.

How can I get the trade to close immediately after the symbol is removed, in this case on 21 August 2012.
 
Hi Trash, could I get some more help here, your code has given me 98% of my objective.

Code:
dn = DateNum();
switch( Name() ) {
    case "ACR": datecond = ( dn >= 1110302 AND dn < 1120821 ) ;  break;
       default: datecond = true; break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = Cross( m, Close )  AND datecond;
Short = Cover = 0;

When I run this backtest for a period that goes after 21 August 2012, a trade initiated with a buy on 13 August 2012 does not close out and remains open.

How can I get the trade to close immediately after the symbol is removed, in this case on 21 August 2012.


Code:
dn = DateNum();

switch( Name() ) {
	case "ACR":
		enddate = 1120821;
		datecond = ( dn >= 1110302 AND dn < enddate );
		exitdatecond = dn >= enddate;
		break;

	default:
		datecond = true;
		exitdatecond = false;
		break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;
Short = Cover = 0;
 
Code:
dn = DateNum();

switch( Name() ) {
	case "ACR":
		enddate = 1120821;
		datecond = ( dn >= 1110302 AND dn < enddate );
		exitdatecond = dn >= enddate;
		break;

	default:
		datecond = true;
		exitdatecond = false;
		break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND datecond; 
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;
Short = Cover = 0;

Thanks for that - it works a treat. Will continue with my testing but that has helped me out no end.

I will see whether I can develop this concept to allow me a second entry and exit.
 
Thanks for that - it works a treat. Will continue with my testing but that has helped me out no end.

I will see whether I can develop this concept to allow me a second entry and exit.

Hi TJW11,

Did you have any luck here, I've tried a number of attempts at coding the second entry/exit but with no success. I would be interested if you have an outcome.

One of the codes I tried, amongst others was:

Code:
dn = DateNum();

switch( Name() ) {
	case "ACR":
		enddate = 1120821;
		datecond = ( dn >= 1110302 AND dn < enddate );
		exitdatecond = dn >= enddate;
		break;

                case "ACR":
		enddate1 = 1141231;
		datecond1 = ( dn >= 1140101 AND dn < enddate1 );
		exitdatecond1 = dn >= enddate1;
		break;


	default:
		datecond = true;
		exitdatecond = false;
                datecond1 = true;
		exitdatecond1 = false;
		break;
}


period = 20; 
m = MA( Close, period );
Buy = Cross( Close, m ) AND (datecond OR datecond1); 
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond OR exitdatecond1;
Short = Cover = 0;

I had a look at https://www.aussiestockforums.com/forums/showthread.php?t=7206 in case that would help educate me on how to code this. I guess I am pretty challenged unless the code is pretty basic!
 
CNHTractor - no I haven't been able to figure this out

Are you talking about 2 different entry and exit conditions as in the following example or are taking about something totally different?

Entry1 OR Entry2 along with Exit1 OR Exit2.

Alternatively

Entry1 AND Exit1 followed by ReEntry2 AND Exit2
 
You have to use OR but not AND.


Code:
// example by trash 
// https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=122&p=878422&viewfull=1#post878422

dn = DateNum();

switch( Name() ) {
	case "ACR":
		enddate1 = 1120821;
		reentry = 1140101;
		enddate2 = 1141231;
		//
		datecond = ( dn >= 1110302 AND dn < enddate1 ) OR
				   ( dn >= reentry AND dn < enddate2 );
		//		   
		exitdatecond1 = dn >= enddate1 AND dn < reentry; 
		exitdatecond2 = dn >= enddate2;
		//
		exitdatecond = exitdatecond1 OR exitdatecond2;
		break;

	default:
		datecond = true;
		exitdatecond = false;
		break;
}


SetPositionSize( 1, spsShares );

period = 20; 
m = MA( Close, period );

Buy = Cross( Close, m ) AND datecond; 
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;

Short = Cover = 0;
 
You have to use OR but not AND.


Code:
// example by trash 
// https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=122&p=878422&viewfull=1#post878422

dn = DateNum();

switch( Name() ) {
	case "ACR":
		enddate1 = 1120821;
		reentry = 1140101;
		enddate2 = 1141231;
		//
		datecond = ( dn >= 1110302 AND dn < enddate1 ) OR
				   ( dn >= reentry AND dn < enddate2 );
		//		   
		exitdatecond1 = dn >= enddate1 AND dn < reentry; 
		exitdatecond2 = dn >= enddate2;
		//
		exitdatecond = exitdatecond1 OR exitdatecond2;
		break;

	default:
		datecond = true;
		exitdatecond = false;
		break;
}


SetPositionSize( 1, spsShares );

period = 20; 
m = MA( Close, period );

Buy = Cross( Close, m ) AND datecond; 
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;

Short = Cover = 0;

Hi Trash,

I've had a look at your coding this morning - that is brilliant

Thanks heap for your input here!


rnr - thanks for your consideration as well

As a "challenged" Amibroker user your knowledge has been invaluable
 
You have to use OR but not AND.


Code:
// example by trash 
// https://www.aussiestockforums.com/forums/showthread.php?t=1679&page=122&p=878422&viewfull=1#post878422

dn = DateNum();

switch( Name() ) {
	case "ACR":
		enddate1 = 1120821;
		reentry = 1140101;
		enddate2 = 1141231;
		//
		datecond = ( dn >= 1110302 AND dn < enddate1 ) OR
				   ( dn >= reentry AND dn < enddate2 );
		//		   
		exitdatecond1 = dn >= enddate1 AND dn < reentry; 
		exitdatecond2 = dn >= enddate2;
		//
		exitdatecond = exitdatecond1 OR exitdatecond2;
		break;

	default:
		datecond = true;
		exitdatecond = false;
		break;
}


SetPositionSize( 1, spsShares );

period = 20; 
m = MA( Close, period );

Buy = Cross( Close, m ) AND datecond; 
Sell = ( Cross( m, Close ) AND datecond ) OR exitdatecond;

Short = Cover = 0;

Hi Trash

I was actually asking CNHTractor and TJW11 exactly what they meant by the comment "second entry and exit" and not referring to the code you posted.
 
Hi All,

I've got the "IB_Controller" working just fine with my Auto-Trade code. Now, I want to get the same set-up with MT4 brokers ---- there are simply lots of folks that don't have $10K to open an account (been there myself a few times over the years).

I have never worked with MT4, and don't have a clue how to write code for that platform. I don't mind learning some new things, just don't want a steep learning curve (if I can help it). I've spent several hours searching the web for help, but just don't find many recent posting about the AB-MT4 process (other than DDE data feeds, etc.).

I'm hoping someone here could point me in a direction for what I seek. I've looked thru the MT4 website at EA and Utility programs (free and purchase), but don't see anything like what the IB_Controller provides. I presume this is called an API or Bridge?

Thanks,
RutheezKey
 
Hello,

I have a small query in regards to downloading data for Indices through yahoo finance.
I have downloaded the data for australian stocks through Amiquote.
However, I wanted data for index such as - XAO.
I am not sure what ticker should be used. I have tried XAO.AX , AORD.AX, but it doesn't work. Amiquote still gives the error symbol not found.
Could someone please assist with this?
I just want to play around with some basic strategies, before I subscribe to Norgate's premium data.

Thank You :)
 
Hello,

I have a small query in regards to downloading data for Indices through yahoo finance.
I have downloaded the data for australian stocks through Amiquote.
However, I wanted data for index such as - XAO.
I am not sure what ticker should be used. I have tried XAO.AX , AORD.AX, but it doesn't work. Amiquote still gives the error symbol not found.
Could someone please assist with this?
I just want to play around with some basic strategies, before I subscribe to Norgate's premium data.

Thank You :)


^AORD

Others :
^AXHJ
^AXFJ
^AXSO
 
Top