High volume of instant failing trades

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #150723 quote
    CapnCrunch77
    Participant
    Junior

    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!

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // Prevents the system from creating new orders to enter the market or increase position size before the specified time
    noEntryBeforeTime = 063000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 205800
    timeEnterAfter = time < noEntryAfterTime
    
    // Prevents the system from placing new orders on specified days of the week
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Conditions to enter long positions
    indicator1 = Volume
    c1 = (indicator1 > 500)
    indicator2 = ExponentialAverage[8](close)
    indicator3 = ExponentialAverage[21](close)
    c2 = (indicator2 > indicator3)
    
    IF (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 3 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator4 = MACDline[12,26,9](close)
    c3 = (indicator4 >= 9.5)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator5 = Volume
    c4 = (indicator5 > 500)
    indicator6 = ExponentialAverage[8](close)
    indicator7 = ExponentialAverage[21](close)
    c5 = (indicator6 < indicator7)
    
    IF (c4 AND c5) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT 3 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator8 = MACDline[12,26,9](close)
    c6 = (indicator8 <= -6)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pTRAILING 4
    SET TARGET pPROFIT 20
    ProRealCode-Test-Trades.png ProRealCode-Test-Trades.png
    #150732 quote
    robertogozzi
    Moderator
    Master

    It’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!

    CapnCrunch77 thanked this post
    #150755 quote
    CapnCrunch77
    Participant
    Junior

    Appreciate 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 :/

    #150760 quote
    robertogozzi
    Moderator
    Master

    Yes, 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).

    x-5.jpg x-5.jpg
    #150908 quote
    CapnCrunch77
    Participant
    Junior

    Appreciate 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.

    #150958 quote
    robertogozzi
    Moderator
    Master

    Would you mind posting your latest code?

    #150977 quote
    CapnCrunch77
    Participant
    Junior

    Sure.  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 🙁

    // Conditions to enter long positions
    indicator1 = 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 THEN
    BUY 3 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator4 = RSI[14](close)
    c4 = (indicator4 > indicator4[10])
    
    IF c4 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator5 = 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 THEN
    SELLSHORT 3 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator8 = RSI[14](close)
    c8 = (indicator8 < indicator8[10])
    
    IF c8 THEN
    EXITSHORT AT MARKET
    ENDIF
    #150978 quote
    robertogozzi
    Moderator
    Master

    You can avoid accumulating positions by adding:

    AND Not OnMarket

    to your conditions at lines 9 and 29.

    CapnCrunch77 thanked this post
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

High volume of instant failing trades


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 7 replies,
has 2 voices, and was last updated by robertogozzi
5 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 11/17/2020
Status: Active
Attachments: 2 files
Logo Logo
Loading...