Difficulté dans l’intégration d’une UT inferieure

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #202668 quote
    wlshr27
    Participant
    New

    Bonjour la commu, bonjour Nicolas.

    J’ai un code qui tourne en 35 minutes, j’aime ses entrées en positions et ses sorties, cependant, sur 500 trades, 9 ou 10 finissent en négatif sans parvenir à toucher leur breakeven ni leur trailing stop car en une seule bougie de 35 minute le marché se retourne brutalement.
    J’aimerais par conséquent passer en 5 minutes, tout en gardant mes entrées et sorties en 35 minutes et juste rajouter une condition de croisement de moyenne mobile sur l’UT 5 minutes pour me couvrir en cas de retournement, et ne pas avoir à attendre la cloture après 35 minutes.

    J’ai cru comprendre qu’il fallait lancer quoi qu’il arrive son backtest en UT inferieure (5minutes dans mon cas). Y’a t’il une solution pour rajouter une ligne de code en UT 5 minutes sans bouleverser toutes mes données en 35 minutes ? Si oui pourriez vous me donner une idée d’à quoi cela pourrait ressembler ?

     

    Voici mon code sans l’integration de l’UT 5 minutes =

    DEFPARAM CumulateOrders = False
    DEFPARAM FLATBEFORE = 144500
    DEFPARAM FLATAFTER = 225500
    noEntryBeforeTime = 144500
    timeEnterBefore = time >= noEntryBeforeTime
    noEntryAfterTime = 222000
    timeEnterAfter = time < noEntryAfterTime
    if timeEnterAfter  then
    
    
    A= 5
    V =7
    iMACD = MACD[11,26,9](close)
    DonchianSupA = highest[A](high)
    DonchianInfA = lowest[A](low)
    DonchianSupV = highest[V](high)
    DonchianInfV = lowest[V](low)
    iRSI= RSI[4](close)
    
    
    
    ca1 = iMACD > iMACD[1]
    ca2 = iMACD >= -0.4
    ca3 = close crosses over DonchianSupA[1]
    ca4 = iRSI > 63
    
    
    c1= ca1 AND ca2 AND ca3 and ca4
    IF c1 THEN
    buy 0.25 lot at market
    SET STOP PLOSS 8.8
    ENDIF
    
    cv1 = iMACD < iMACD[1]
    cv2 = iMACD <= -1
    cv3 = close crosses under DonchianInfV[1]
    cv4 = iRSI < 30
    
    c2 = cv1 AND cv2 AND cv3 and cv4 
    if c2 then
    SELLSHORT 0.25 LOT AT MARKET
    SET STOP PLOSS 10
    endif
    
    trailingstart = 5
    trailingstep = 3
    
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    
    IF LONGONMARKET THEN
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize  THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    
    IF SHORTONMARKET THEN
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
    
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF

    Merci et bonne semaine à tous !!!

    #202670 quote
    Nicolas
    Keymaster
    Master

    Pour cela, délocalise la gestion de tes ordres dans l’UT inférieure (ici le 5-minutes donc). Et indique dans le code que tes prises de positions sont toujours dans l’UT de la stratégie (35-minutes) en utilisant l’instruction TIMEFRAME:

    DEFPARAM CumulateOrders = False
    DEFPARAM FLATBEFORE = 144500
    DEFPARAM FLATAFTER = 225500
    
    timeframe(35 minutes,updateonclose)
    
    noEntryBeforeTime = 144500
    timeEnterBefore = time >= noEntryBeforeTime
    noEntryAfterTime = 222000
    timeEnterAfter = time < noEntryAfterTime
    if timeEnterAfter  then
    
    
    A= 5
    V =7
    iMACD = MACD[11,26,9](close)
    DonchianSupA = highest[A](high)
    DonchianInfA = lowest[A](low)
    DonchianSupV = highest[V](high)
    DonchianInfV = lowest[V](low)
    iRSI= RSI[4](close)
    
    
    
    ca1 = iMACD > iMACD[1]
    ca2 = iMACD >= -0.4
    ca3 = close crosses over DonchianSupA[1]
    ca4 = iRSI > 63
    
    
    c1= ca1 AND ca2 AND ca3 and ca4
    IF c1 THEN
    buy 0.25 lot at market
    SET STOP PLOSS 8.8
    ENDIF
    
    cv1 = iMACD < iMACD[1]
    cv2 = iMACD <= -1
    cv3 = close crosses under DonchianInfV[1]
    cv4 = iRSI < 30
    
    c2 = cv1 AND cv2 AND cv3 and cv4 
    if c2 then
    SELLSHORT 0.25 LOT AT MARKET
    SET STOP PLOSS 10
    endif
    
    timeframe(5 minutes)
    
    trailingstart = 5
    trailingstep = 3
    
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
    
    
    IF LONGONMARKET THEN
    IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize  THEN
    newSL = tradeprice(1)+trailingstep*pipsize
    ENDIF
    IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
    newSL = newSL+trailingstep*pipsize
    ENDIF
    ENDIF
    
    IF SHORTONMARKET THEN
    IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
    newSL = tradeprice(1)-trailingstep*pipsize
    ENDIF
    IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
    newSL = newSL-trailingstep*pipsize
    ENDIF
    ENDIF
    
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF

    Sous l’instruction TIMEFRAME(5 minutes) tu pourras ajouter ce que tu veux pour fermer l’ordre à chaque bougie de 5 minutes.

    EDIT: j’ai simplement ajouté les lignes 5 et 48.

    #202904 quote
    wlshr27
    Participant
    New

    Merci beaucoup Nicolas

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

Difficulté dans l’intégration d’une UT inferieure


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
wlshr27 @wlshr27 Participant
Summary

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

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 10/17/2022
Status: Active
Attachments: No files
Logo Logo
Loading...