Help: Autotrade making incorrect trades?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #192026 quote
    jp2002
    Participant
    New

    I made a pretty basic auto trading algo that trades off both 200DEMA and supertrend. It looks something like this

    // 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 = 100000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 163000
    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 = DEMA[200](close)
    c1 = (close > indicator1)
    indicator2 = SuperTrend[3,12]
    c2 = (close > indicator2)
    
    IF (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY 250 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator3 = SuperTrend[3,12]
    c3 = (indicator3 >= close)
    
    IF c3 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator4 = DEMA[200](close)
    c4 = (close <= indicator4)
    indicator5 = SuperTrend[3,12]
    c5 = (close <= indicator5)
    
    IF (c4 AND c5) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT 250 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator6 = SuperTrend[3,12]
    c6 = (close >= indicator6)
    
    IF c6 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP %LOSS 2
    SET TARGET %PROFIT 6

     

    It ran well in backtesting so I thought i’d enter a position with it today and test it out. Unfortunately it doesn’t follow my code???

    https://ibb.co/mX5wrhv

    As you can see from the picture I uploaded, it entered a short position at 215, which doesn’t make sense as the price wasn’t under the 200DEMA line which I specified it should. Why is this? I am really confused

    #192030 quote
    GraHal
    Participant
    Master

    I set up chart for NVIDIA on 15M TF (spreadbet) and price has been below DEMA since about 15:15 today … see attached at red arrowhead?

    What time did your Algo take the trade?

    DEMA.png DEMA.png
    #192032 quote
    robertogozzi
    Moderator
    Master

    From the attached pic I can’t see the time and date of entry, and the values of the price and indicators, so I can’t replicate exactly.

    Moreover “It looks something like this“, isn’t accurate. To compare results the code must be absolutely IDENTICAL to the one you used.

    My backtests are all good, though.

    I suggest that you add these lines to your code, maybe this will help detect something wrong (though they only work in backtests):

    graph (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AS "Long"
    graph (c4 AND c5) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry AS "Short"
    #192035 quote
    jp2002
    Participant
    New

    Hey, thanks for the reply.

     

    The trade happened at 10:45am US time, which would be 3:45pm UK Time. For some reason my DEMA line is glitched? Its completely different to yours.

    https://ibb.co/cJ3PtNs

    From this image here, it shows my DEMA line only crossed above price at 11:45am US time, which is 4:45pm UK time. This is consistent with my graph on tradingview. How come yours is different?

    Screenshot-2022-04-21-at-18-28-00.jpg Screenshot-2022-04-21-at-18-28-00.jpg
    #192036 quote
    jp2002
    Participant
    New

    My code is exact, the same one I ran the backtest with I ran the automated trading program with. I’m just confused as to why it’s not following my instructions

    #192040 quote
    GraHal
    Participant
    Master

    For some reason my DEMA line is glitched? Its completely different to yours.

    Try it on Spreadbet as you are showing NVIDIA on CFD?

    It shouldn’t make any difference, except the figures shown for Price (multiplied by 100 on SB)

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

Help: Autotrade making incorrect trades?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
jp2002 @jp2002 Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by GraHal
3 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/21/2022
Status: Active
Attachments: 2 files
Logo Logo
Loading...