High volume of instant failing trades
Forums › ProRealTime English forum › ProOrder support › High volume of instant failing trades
- This topic has 7 replies, 2 voices, and was last updated 5 years ago by
robertogozzi.
-
-
11/17/2020 at 12:16 AM #150723
Hello All,
I’m starting to learn how to use ProRealCode to create an automated trading programme and have come across a high volume of trades when backtesting that look to have instantly closed out but I’m at a loss as to why they are occurring. I started off by using the Simplified Creation option and picked my combination of indicators – this has worked to an extent but only less than 50% are successful – the ‘instant kill’ trades are what is throwing me off which I cannot work out what the issue is (programme per below):
Has anyone ever encountered this before and if so, any ideas as to what is wrong? thanks in advance!
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Prevents the system from creating new orders to enter the market or increase position size before the specified timenoEntryBeforeTime = 063000timeEnterBefore = time >= noEntryBeforeTime// Prevents the system from placing new orders to enter the market or increase position size after the specified timenoEntryAfterTime = 205800timeEnterAfter = time < noEntryAfterTime// Prevents the system from placing new orders on specified days of the weekdaysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0// Conditions to enter long positionsindicator1 = Volumec1 = (indicator1 > 500)indicator2 = ExponentialAverage[8](close)indicator3 = ExponentialAverage[21](close)c2 = (indicator2 > indicator3)IF (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 3 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator4 = MACDline[12,26,9](close)c3 = (indicator4 >= 9.5)IF c3 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator5 = Volumec4 = (indicator5 > 500)indicator6 = ExponentialAverage[8](close)indicator7 = ExponentialAverage[21](close)c5 = (indicator6 < indicator7)IF (c4 AND c5) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENSELLSHORT 3 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator8 = MACDline[12,26,9](close)c6 = (indicator8 <= -6)IF c6 THENEXITSHORT AT MARKETENDIF// Stops and targetsSET STOP pTRAILING 4SET TARGET pPROFIT 2011/17/2020 at 1:35 AM #150732It’s because your conditions are met every candlestick, so many trades are entered.
Try using more strict settings.
Moreover, exiting when MACD is in your own direction is a bit awkward! You exit LONG trades when MACD >= 9.5, I’d say you would exit LONG trades when it’s below zero, wouldn’t you? (the opposite for SHORT trades)
Besides this, maybe setting a crossover of the two averages, instead of simply checking that one is greater than the other (which leads to so many trades because checking it’s > occurs almost always, while a crossover occurs every N bars).
It’s a start, don’t be discoureged! Read many topics, study many pieces of code, use part of them to build your own strategy spending time and efforts to achieve better results.
Usually a strategy crossover, simply put, is not likely to yield good results, you can add a filter, maybe enter when, after a crossover, price retraces and touches again the average(s).
Learning from (& copying) other strategies will be of great help!
1 user thanked author for this post.
11/17/2020 at 9:48 AM #150755Appreciate it Roberto!
I’ve been looking at creating the automated programme over the weekend so I’m still getting to grips with it. I’ve not got a programming background hence trying to pick this up is proving difficult but I’m not gonna give up – I see the promise in this. It’s just getting the darn thing to work and work consistently. Whatever combination of indicators used will generate either lower volume, greater accuracy but lower return or the opposite! granted, I expect losing trades – I guess it’s just striking a good balance.
Ideally, I just want it to do what’s worked relatively well for me manually – execute and hold through the momentum of trend until it turns. Trying to get it done as a programme is my challenge :/
11/17/2020 at 10:21 AM #150760Yes, what I meant with MACD is that (see attached pic) in an uptrend exiting when it’s ABOVE a certain small value means it will be closed soon, much earlier than the end of the uptrend! (the opposite for downtrends).
11/19/2020 at 1:39 AM #150908Appreciate the advice! I’ve been trialling different setup to reduce the frequency of those trades which instantly open and close with more validation. I am however, perplexed as to how I can add more validation to prevent weird trades from happening.
Example; I have setup BUY criteria to trigger on price being higher than 2 periods earlier, my shorter term MA is trending above my longer term MA and there is volume. The criteria was met however it opened a buy when the momentum was fading and it came off of highs. Any suggestions on how I can avoid that? I keep thinking I need validation which effectively says ‘only trigger if there is consecutively trending close prices’ but no idea how to include this.
11/19/2020 at 1:16 PM #150958Would you mind posting your latest code?
11/19/2020 at 3:27 PM #150977Sure. See below. This kind of approach works quite well manually but replicating with conditions, etc..into an automated programme for me as a complete novice programmer 🙁
123456789101112131415161718192021222324252627282930313233343536373839// Conditions to enter long positionsindicator1 = ExponentialAverage[100](close)c1 = (close > indicator1[2])indicator2 = ExponentialAverage[8](close)indicator3 = ExponentialAverage[100](close)c2 = (indicator2 > indicator3[1])c3 = (close >= close[2])IF (c1 AND c2 AND c3) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENBUY 3 CONTRACT AT MARKETENDIF// Conditions to exit long positionsindicator4 = RSI[14](close)c4 = (indicator4 > indicator4[10])IF c4 THENSELL AT MARKETENDIF// Conditions to enter short positionsindicator5 = ExponentialAverage[100](close)c5 = (close < indicator5[2])indicator6 = ExponentialAverage[8](close)indicator7 = ExponentialAverage[100](close)c6 = (indicator6 < indicator7[1])c7 = (close <= close[2])IF (c5 AND c6 AND c7) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THENSELLSHORT 3 CONTRACT AT MARKETENDIF// Conditions to exit short positionsindicator8 = RSI[14](close)c8 = (indicator8 < indicator8[10])IF c8 THENEXITSHORT AT MARKETENDIF11/19/2020 at 3:43 PM #150978You can avoid accumulating positions by adding:
1AND Not OnMarketto your conditions at lines 9 and 29.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on