Hi guys,
Ive been at this for well over a week now and cant seem to crack it or find anything on the forum that answers my questions.
Short question – how do I set the backtester to prioritize the applystop exit signal over the sell exit signal if both are triggered on the entry bar?
Long description -
I am working on a simple strategy to start with that is pretty much a momo trend following strategy which has a tight stop.
The idea is to enter on the open of the buy signal and if the price pulls back more than 1.5% from the open then exit the position intraday on the same bar (the stop). If not, then the position keeps running until either a) price eventually goes 1.5% below the entry price and hits the stop or b) price closes 2% under the 50dma. Pretty simple idea.
The problem im having is that if it enters on a bar that ends up being a huge red candle and slices through the 50dma, the exits are executed on the close of that bar which is the sell signal, not at the MAX stop from entry price which is set at 1.5%.
So how can I rectify this. I have tried so many changes that I cant even remember where I began.
Ive only recently purchased Amibroker and started this so im definitely a newb but im learning as much as I can, have read Bandys manual and have tried everything within my knowledge before coming here for help.
Not looking for a fish, just someone to show me how to cast a line. Appreciate the help in advance.
This is the simple version of the code with all the buy parameters removed.
SetBacktestMode(backtestRegularRaw);
setoption( "AllowSameBarExit", True );
//I have tried using different sell trade delays but it delays the stop too i think
SetTradeDelays(0,0,0,0);
SetOption("ActivateStopsImmediately", True );
//EntryParams = //(Basically buys strong open)
Filter = Entryparams;
Buy = Entryparams;
BuyPrice = Open;
//I have tried exit types 0,1 and 2.
ApplyStop( stopTypeLoss, stopModePercent, 1.5, 1);
Sell = Close < 0.98*MA(C, 50);
SellPrice = Close;
//Sell = 0;
//I have tried to use applystop for the Sell trigger too but it doesnt work either (also doesnt allow using a variable to exit applystop on backtestregularraw)
//SellStop = C < 0.98*MA(C, 50);
//ApplyStop( stopTypeLoss, stopModePoint, SellStop, 1);
SetPositionSize( 20, spsPercentOfEquity );