[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Newbie - strange problem in the trading system



PureBytes Links

Trading Reference Links

I have recently started coding the AFL.
I am trying to build a simple system which will buy @ 20% or more bellow
year high and sell @ 10% profit
Here is the code...

_SECTION_BEGIN("test");


/*firstly some basics common*/
SetBarsRequired(10000,10000); /* this ensures that the charts include all
bars AND NOT just those on screen */
SetFormulaName("Test1 System"); /*name it for backtest report identification
*/
SetTradeDelays( 1, 1, 1, 1 ); /* delay entry/exit by one bar */
SetOption( "initialequity", 100000 ); /* starting capital */
PositionSize = -10; /* trade size will be 10% of available equty */
SetOption( "MaxOpenPositions", 10 ); /* I don't want to comit more than 60%
of Equity at any one time */
SetOption( "CommissionMode", 1 ); /* set commissions AND costs as $ per
trade */
SetOption( "CommissionAmount", 0.059); /* commissions AND cost */
SetOption( "ReverseSignalForcesExit", False);
SetOption( "UsePrevBarEquityForPosSizing", 1 ); /*set the use of last bars
equity for trade size*/

//Trade system
/*
Buy when today's close is 20% or more bellow from 52 week high
Sell when today's Close is more than 10% of the buying price
There is no stop loss
*/

yrHi = HHV(High,260);

Buy = (yrHi*0.8) >= C;
//Sell = Cross( C, ValueWhen(Buy,C)*1.1);
Sell = C > (ValueWhen(Buy,C)*1.1);


//Filter = Buy OR Sell;
Filter = 1;

Buy   = ExRem(Buy, Sell);
Sell  = ExRem(Sell, Buy);

AddTextColumn( FullName(), "Company Name" );
AddColumn( Buy, "Buy");
AddColumn( Sell, "Sell");
AddColumn( C, "Close", 1.1 );
AddColumn( yrHi, "52wk High", 1.1 );
AddColumn( yrHi*0.8, "Buy@/Bellow");
AddColumn( (yrHi*0.8) >= C, "(yrHi*0.8) >= C");

_SECTION_END();

The Buy and Sell signals are generated properly, but strangely ExRem calls
remove first few Buy signals and then buys at some arbitrary signals. If I
try to comment out ExRem calls, it buys properly but then excess signals are
not getting removed. I have gone through many examples but everything seems
to be correct in the code.

Also, it sells at around 50% loss (which is not coded!)

Can somebody guide me as to what is wrong with the code? I am using
Amibroker 4.80.1.

Thanks & Regards,
PS

Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.409 / Virus Database: 268.14.11/542 - Release Date: 11/20/2006