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

[amibroker] ApplyStop Problem



PureBytes Links

Trading Reference Links

Hello all,

Could someone please help me to understand why my stop and profit targets are not working correctly in backtesting?

I have a basic system I am trying to backtest - it buys at the previous day's high/sells at the previous day's low and exits with a stop loss or a profit target of 50 pips/ticks. I have this running on 1M intra-day EURUSD data.

The problem is that my exits in a backtest range from +/-50 ticks (+/-0.0050) to +/-51 ticks (+/-0.0051). I don't understand why or what I am doing wrong.

Why is the code exiting at 51 ticks instead of 50?


Here is the code: (Note that I only have this going long right now.)
//...........................................................SYSTEM
//...................Settings
	SetOption("AllowSameBarExit", True);
	SetOption("ActivateStopsImmediately", False );
	SetOption("FuturesMode", True);
	SetOption("PriceBoundChecking", True);
	SetPositionSize(1,spsShares);
//...................Trade Logic
//Set Previous Day's High
	TimeFrameSet( inDaily );
	B_ENT = Ref(H,-1);
	TimeFrameRestore();
	BB_ENT = TimeFrameExpand (B_ENT, inDaily, expandFirst);
//Execute Buy @ Previous Day's High
	Buy = Cross (H, BB_ENT);
	Sell = 0;
	Buy = ExRem(Buy,TimeNum()==180000);
	BuyPrice = BB_ENT;
//...................STP & TGT
	ApplyStop(stopTypeLoss, stopModePoint, 0.00500, 1, True, 0);
	ApplyStop(stopTypeProfit, stopModePoint, 0.00500, 1, True, 0);

//...........................................................PLOT
//...................Chart Settings
	SetChartOptions(0,chartShowDates);
	_N(Title = (Name() + "  |  " + Date() + "  |  Open: " + O + "  |  " + "High: " + H + "  |  " + "Low: " + L + "  |  " + "Close: " + C));
//...................Plot Price
	Plot( C, "Close", colorBlack, styleBar);
	PlotShapes(Buy*shapeUpArrow,colorGreen,0,L);
	PlotShapes(Sell*shapeDownArrow,colorRed,0,H);
	Equity(1,0);
	PlotShapes( (Sell>0)* shapeDownArrow, colorRed, 0, H );

//...........................................................COMMENTARY
	printf("HIGH : ");
	WriteVal(BB_ENT,1.5);


Here is link to a screen shot that shows what is happening:
http://img246.imageshack.us/img246/5209/eurusdissue.jpg

You can see there wasn't a gap or anything; the backtest just exits at 51 ticks over instead of 50 ticks over.


I am new to AmiBroker coming from TradeStation, so I presume I am doing something wrong. This isn't a system that I trade; I use it as a baseline system to evaluate other systems against. If I can figure this out, I can start to move my other work over.

I have searched the list, looked through help and tried changing every setting I can think of but I can't get the code to consistently exit at a fixed stop/profit target of 0.0050. I would be seriously grateful if anyone could take a look and tell me what I am doing wrong as I have hit a wall with this.

Thanks,
Tim 



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/