Ajouter un stop suiveur

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #87439 quote
    Pinkybouh
    Participant
    Junior

    Bonjour,

    Serait il possible d’ajouter un stop suiveur dans ce code?

    La réflexion serait la suivante:

    Si la position est positive de 15 points, alors ajouter un stop suiveur à 5 points avec un min garanti de 10 points.

    Merci de vos retours,

    DEFPARAM CumulateOrders = false
    // TAILLE DES POSITIONS
    REINV = 0
    LEVIER = 3
    CAPITALinit = 5000
    IF REINV = 0 THEN
    n = levier
    ELSIF REINV = 1 THEN
    capital = CAPITALinit + strategyprofit
    n = (capital / CAPITALinit)*levier
    IF n < 1 THEN
    n=1
    ENDIF
    n = round(n)
    ENDIF
    //HEURES DE TRADING
    rangestart = 092500
    rangeend = 172500
    //Target & SL & RSI
    ShortSL = 50
    ShortTP = 37
    LongSL = 55
    LongTP= 40
    LevelRSI = 56
    //MOYENNE MOBILES
    mm2= ExponentialAverage[27]
    mm1= ExponentialAverage[7]
    mm3= ExponentialAverage[100]
    // SHORTS
    cv1 = mm1 < (close[1])
    cv2 = mm1 < mm2
    cv3 = RSI[3] < LevelRSI
    cv4 = mm3 < mm1
    CONDVENTE = cv1 and cv2 and cv3 and cv4
    
    IF time > rangestart and time < rangeend and CONDVENTE then
    Sellshort n CONTRACT at market
    SET STOP PLoss ShortSL
    SET TARGET PPROFIT ShortTP
    ENDIF
    
    // EXIT SHORT
    c1v = mm1 crosses over mm3
    
    IF c1v THEN
    ExitShort AT MARKET
    ENDIF
    
    // LONGS
    ca1 = mm1 > (close[1])
    ca2 = mm1 > mm2
    ca3 = RSI[3] > LevelRSI
    ca4 = mm1 > mm3
    CONDACHAT = ca1 and ca2 and ca3 and ca4
    
    IF time > rangestart and time < rangeend and CONDACHAT then
    Buy n CONTRACT at market
    SET STOP PLoss LongSL
    SET TARGET PPROFIT LongTP
    ENDIF
    
    // EXIT LONG
    c1v = mm1 crosses under mm3
    
    IF c1v THEN
    ExitShort AT MARKET
    ENDIF
    
    #88053 quote
    Renato Moscardini
    Participant
    Junior

    Bonjour,

    J’ai aussi galéré avec les stop suiveurs. Il existe bien sûr le SET STOP TRAILING. Mais lorsqu’on calcule dynamiquement les valeurs, les résultats sont parfois étranges.

    J’ai trouvé un bout de code qqpart sur ce site qui fonction étonnamment bien pour le times frames courts, car il est ajusté seulement à l’appel du code, donc à la barre du time frame utilisé.

    En espérant que cela puisse aider

     

    //trailing stop function
    trailingstart = 20
    trailingstep = 5
    
    //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*pipsize THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
    
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    
    SET STOP %LOSS 0.3
    Nicolas thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

Ajouter un stop suiveur


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Pinkybouh @pinkybouh Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Renato Moscardini
7 years, 2 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 12/19/2018
Status: Active
Attachments: No files
Logo Logo
Loading...