MA crossover: entry + 15 points query

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #96725 quote
    CJB64
    Participant
    New

    Hi,

    Complete newbie here so sorry if this is a silly question. I have looked in the forum but can not find a way to code it. I am trying to do the following:

    Buy conditions:

    ma5 crosses over ma15 AND DI+ > DI-  then buy at *crossover price plus 15 points* at 5 per point

    Sell conditions:

    ma5 crosses under ma15 AND DI- > DI+ then buy at *crossover price minus 15 points* at 5 per point

    I am struggling to work out the part in asterixes!  So for example if ma5 crosses over ma15 at 12000 then providing the DI+ > DI-, I want to enter the trade at a price of 12015, hope that makes sense! Any help much appreciated!

    // 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 = 134000
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER = 180000
    
    // Prevents the system from creating new orders to enter the market or increase position size before the specified time
    noEntryBeforeTime = 134000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 170000
    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 = ExponentialAverage[5](close)
    indicator2 = ExponentialAverage[15](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = DIplus[14](close)
    indicator4 = DIminus[14](close)
    c2 = (indicator3 >= indicator4)
    
    IF (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    BUY  5 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator5 = ExponentialAverage[5](close)
    indicator6 = ExponentialAverage[15](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    indicator7 = ExponentialAverage[15](close)
    c4 = (close <= indicator7)
    
    IF c3 OR c4 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator8 = ExponentialAverage[5](close)
    indicator9 = ExponentialAverage[15](close)
    c5 = (indicator8 CROSSES UNDER indicator9)
    indicator10 = DIminus[14](close)
    indicator11 = DIplus[14](close)
    c6 = (indicator10 >= indicator11)
    
    IF (c5 AND c6) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT 5 PERPOINT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator12 = ExponentialAverage[5](close)
    indicator13 = ExponentialAverage[15](close)
    c7 = (indicator12 CROSSES OVER indicator13)
    indicator14 = ExponentialAverage[15](close)
    c8 = (close >= indicator14)
    
    IF c7 OR c8 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 10
    
    #96738 quote
    Nicolas
    Keymaster
    Master

    In this case you should use pending stop orders. But since they expire automatically on each new bar open and because we need to renew them continuously, how much long do you want them to “exist”?

    #96753 quote
    CJB64
    Participant
    New

    Hi Nicholas,

    Thanks for your help, deally they would exist until the ma’s crossover again and at that point would cancel the opposing trade and take the new trade (if it has passed the 15points from crossover price). Hope that makes sense!

    #96757 quote
    Nicolas
    Keymaster
    Master

    here is the code:

    // 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 = 134000
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER = 180000
    
    // Prevents the system from creating new orders to enter the market or increase position size before the specified time
    noEntryBeforeTime = 134000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // Prevents the system from placing new orders to enter the market or increase position size after the specified time
    noEntryAfterTime = 170000
    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 = ExponentialAverage[5](close)
    indicator2 = ExponentialAverage[15](close)
    c1 = (indicator1 CROSSES OVER indicator2)
    indicator3 = DIplus[14](close)
    indicator4 = DIminus[14](close)
    c2 = (indicator3 >= indicator4)
    
    IF (c1 AND c2) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    dir = 1 
    level = close+15*pointsize
    ENDIF
    
    if dir=1 then 
    buy 5 perpoint at level stop 
    endif
    
    // Conditions to exit long positions
    indicator5 = ExponentialAverage[5](close)
    indicator6 = ExponentialAverage[15](close)
    c3 = (indicator5 CROSSES UNDER indicator6)
    indicator7 = ExponentialAverage[15](close)
    c4 = (close <= indicator7)
    
    IF c3 OR c4 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator8 = ExponentialAverage[5](close)
    indicator9 = ExponentialAverage[15](close)
    c5 = (indicator8 CROSSES UNDER indicator9)
    indicator10 = DIminus[14](close)
    indicator11 = DIplus[14](close)
    c6 = (indicator10 >= indicator11)
    
    IF (c5 AND c6) AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    dir = -1
    level = close-15*pointsize
    ENDIF
    
    if dir=-1 then 
    sellshort 5 perpoint at level stop 
    endif 
    
    // Conditions to exit short positions
    indicator12 = ExponentialAverage[5](close)
    indicator13 = ExponentialAverage[15](close)
    c7 = (indicator12 CROSSES OVER indicator13)
    indicator14 = ExponentialAverage[15](close)
    c8 = (close >= indicator14)
    
    IF c7 OR c8 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET STOP pLOSS 10
    CJB64 thanked this post
    #96764 quote
    CJB64
    Participant
    New

    Fantastic, thanks Nicholas, I am not at screen at moment but will try it tomorrow. Thanks again!

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

MA crossover: entry + 15 points query


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
CJB64 @cjb64 Participant
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by CJB64
6 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/17/2019
Status: Active
Attachments: No files
Logo Logo
Loading...