Short positions keep closing

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #192985 quote
    Jaanboy321
    Participant
    Average

    Hi Guys,

    I can’t work out why this code keeps closing the positions (shorts at the moment) before the MA/EMA crosses. The results show a number of opens and closes (eg9.30am-11am BST  yesterday on the Sp 500) when the MA/EMA never crosses- any ideas where I’m going wrong? Many thanks to anyone who can point out my error!

    Regards,

    John

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    ONCE UKAMopenstart = 093000
    ONCE UKAMopenfinish =123000
    ONCE UKAMexit =143000
    
    ONCE USPMopenstart = 173000
    ONCE USPMopenfinish =201500
    
    // Conditions to enter long positions
    indicator1 = ADX[14]
    c1 = (indicator1[1] > 20.46)
    indicator2 = Average[3](close)
    indicator3 = ExponentialAverage[9](close)
    c2 = (indicator2[1] > indicator3[1])
    indicator4 = ExponentialAverage[9](close)
    indicator5 = Average[20](close)
    c3 = (indicator4[1] > indicator5[1])
    
    IF (time>=UKAMopenstart AND time<=UKAMopenfinish) OR (time>=USPMopenstart AND time<=USPMopenfinish)AND  c1 AND c2 AND c3 THEN
    BUY 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator6 = Average[3](close)
    indicator7 = ExponentialAverage[9](close)
    c4 = (indicator6[1] < indicator7[1])
    
    IF c4 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator8= ADX[14]
    c5 = (indicator8[1] > 20.46)
    indicator9 = Average[3](close)
    indicator10 = ExponentialAverage[9](close)
    c6 = (indicator9[1] < indicator10[1])
    indicator11 = ExponentialAverage[9](close)
    indicator12 = Average[20](close)
    c7 = (indicator11[1] < indicator12[1])
    
    IF (time>=UKAMopenstart AND time<=UKAMopenfinish) OR (time>=USPMopenstart AND time<=USPMopenfinish)AND c5 AND c6 AND c7 THEN
    SELLSHORT 1 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator13 = Average[3](close)
    indicator14 = ExponentialAverage[9](close)
    c8 = (indicator13[1] crosses over indicator14[1])
    
    IF  c8 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    #192987 quote
    Jaanboy321
    Participant
    Average

    FYI, I’m using the 15minute charts 🙂

    #192988 quote
    robertogozzi
    Moderator
    Master

    It should only occur on LONG trades, as line 27 has no CROSSOVER provision, unlike line 50.

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

Short positions keep closing


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Jaanboy321 @jaanboy321 Participant
Summary

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

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 05/10/2022
Status: Active
Attachments: No files
Logo Logo
Loading...