RicxParticipant
Junior
This is my first backtest, just trying to create a simple test to take a look at sell-offs in S&P500 during the last 45 minutes on Fridays.
It seems that I am missing something as I don’t get any results.. I want to look at in in the 5 minutes timeframe and I’ve put in MA8 and MA16, I want to enter a short position (and vice versa for long) when MA8 crosses under MA16 and I want it to exit the position when price goes over MA8 or 10 minutes after closing time of the stock exchange (which in my case is 22:10 as I’m located in GMT+1). Attached you can see a pic of what I’m looking to capture, however the attached pic is of a Thursday but it is just to show you what I’m looking for.
What am I missing?
Thanks in advance for any help! 🙂
// Definition of code parameters
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
DEFPARAM FLATBEFORE = 212500
// Cancel all pending orders and close all positions at the "FLATAFTER" time
DEFPARAM FLATAFTER = 221000
// Prevents the system from creating new orders to enter the market or increase position size before the specified time
noEntryBeforeTime = 212500
timeEnterBefore = time >= noEntryBeforeTime
// Prevents the system from placing new orders to enter the market or increase position size after the specified time
noEntryAfterTime = 221000
timeEnterAfter = time < noEntryAfterTime
// Prevents the system from placing new orders on specified days of the week
daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// Conditions to enter long positions
indicator1 = Average[8](close)
indicator2 = Average[16](close)
c1 = (indicator1 CROSSES OVER indicator2)
IF c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
BUY 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit long positions
indicator3 = Average[8](close)
c2 = (close < indicator3)
IF c2 THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
indicator4 = Average[8](close)
indicator5 = Average[16](close)
c3 = (indicator4 CROSSES UNDER indicator5)
IF c3 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
// Conditions to exit short positions
indicator6 = Average[8](close)
c4 = (close > indicator6)
IF c4 THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets
SET STOP pTRAILING 10
SET TARGET pPROFIT 30
Something wrong in your conditions:
graph c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry coloured (0,200,0)
graph c3 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry coloured (200,0,0)
Don’t return any valid signals in backtests. You should test each of all your conditions, to know which one prevent a signal to be valid.
RicxParticipant
Junior
Thanks for answering!
What do you mean by testing all of the conditions? Am I only testing one right now?
I think Nicolas means for you to backtest 1 condition and then include a 2nd condition and then a 3rd etc. When you include a condition which stops trades then you know that is the condition with the error?
This is all conditions that trigger a BUY order:
c1 AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry
All these conditions are not met at the same time and that’s why you never get any long entry. I suggest to GRAPH one condition by one in backtests to know why it happens.