SA 40 Long + Short Strategy

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #88898 quote
    Vicari0us
    Participant
    Average

    Hey all,

    Uploading my first strategy to the community.

    I know there is a lot of work still to be done on this one, but here is what I have so far.

    It performs really well in my local market with a spread of 35 Points on the H1 timeframe.

    Performance is trash when going back further than 2 years. The disgusting chop zone between 2014 and 2016 is a killer. (see attachment)

    Anyway, credit to Casenova for his wisper long strategy and to Nicolas for his trailing stop function.

    //-------------------------------------------------------------------------
    // Main code : H1 Buy and Sell on SA 40
    //-------------------------------------------------------------------------
    // Definition of code parameters
    DEFPARAM CumulateOrders = false // Cumulating positions deactivated
    //daysForbiddenEntry = OpenDayOfWeek = 1 //OR OpenDayOfWeek = 0
    
    // Money Management
    atr = AverageTrueRange[14](close)
    accountbalance = 10000 //Starting acc balance
    liveaccountbalance = accountbalance + strategyprofit
    lotsize = max(2,round(((liveaccountbalance * 0.1) / (atr * 1.2)) /4))
    
    
    //====================================================================================//
    
    // Conditions to enter long positions
    c1 = (close[3] <= high[4])
    c2 = (close[3] >= low[4])
    c3 = (close[2] <= high[3])
    c4 = (close[2] >= low[3])
    c5 = (close[1] <= high[2])
    c6 = (close[1] >= low[2])
    
    c2HLong = close >= trend2H
    
    // Work Out the Highs
    if high[4] > high[3] then
    ath = high[4]
    else
    ath = high[3]
    endif
    if high[2] > ath then
    ath = high[2]
    else
    ath = ath
    endif
    if high[1] > ath then
    ath = high[1]
    else
    ath = ath
    endif
    
    c7 = (close > ath)
    
    buycondition = c1 AND c2 AND c3 AND c4 AND c5 AND c6 and c7 and c2hlong //and c10 //and c9
    
    
    IF buycondition then//and not daysForbiddenEntry THEN
    buy lotsize CONTRACT AT MARKET
    set stop ploss 270
    ENDIF
    
    //====================================================================================//
    
    // Conditions to enter short positions
    ARDOWN = AroonDown[14]
    ARUP = AroonUp[14]
    c1 = (ardown CROSSES OVER arup)
    
    timeframe (2H)
    trend2H = supertrend[7.4,17]
    c2HShort = close <= trend2H
    
    timeframe (default)
    
    IF c1 and c2HShort then //and not daysForbiddenEntry then //and c2 and c3 and c4  THEN
    SELLSHORT lotsize CONTRACT AT MARKET
    SET STOP pLOSS 225
    ENDIF
    
    //====================================================================================//
    
    //trailing stop function
    trailingstart = 70 //trailing will start @trailinstart points profit
    trailingstep = 60 //trailing step to move the "stoploss"
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*4 THEN
    newSL = tradeprice(1)+trailingstep*4
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*4 THEN
    newSL = newSL+trailingstep*4
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*4 THEN
    newSL = tradeprice(1)-trailingstep*4
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*4 THEN
    newSL = newSL-trailingstep*4
    ENDIF
    
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    //************************************************************************
    
    GRAPH newSL as "trailing"
    Sa40-Results.png Sa40-Results.png screen-1547718574p8cl4.png screen-1547718574p8cl4.png
Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.

SA 40 Long + Short Strategy


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Vicari0us @vicari0us Participant
Summary

This topic contains 1 voice and has 0 replies.

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