Mettre un robot en pause temporairement

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #219810 quote
    RICOU
    Participant
    New

    Bonjour ,

    pour continuer mon développement de stratégie, peut on mettre un robot en pause pendant 5 mn par exemple après la clôture d’une position?

    Si oui quel type de code dois je utiliser?

    Merci,

    #219912 quote
    Nicolas
    Keymaster
    Master

    On peut compter en terme de bougies par exemple:

    //1)
    waitbar = 5
    
    //2)
    if not onmarket and (onmarket[1] or longtriggered or shorttriggered) then 
     lastindex = barindex
    endif 
    
    //3)
    gotrading = barindex-lastindex >= waitbar 
    

    Explication du code dans l’ordre:

    1. définition du paramètre pour la quantité de barres à attendre après un ordre
    2. test si on est plus au marché alors qu’on l’était à la barre précédente et enregistrement du barindex
    3. variable booléenne (à mettre dans ta chaîne de conditions pour ouvrir une position) qui teste si on a suffisamment de barres depuis le dernier trade
    #219958 quote
    RICOU
    Participant
    New

    Bonjour Nicolas,

    merci pour la réponse mais cela ne fonctionne pas , peut être que j’ai mal positionné le code, ci joint le détail.

    DEFPARAM cumulateorders = false
    DEFPARAM FlatAfter =200000
    tradestart = time > 090000
    Tradeend= time < 140000
    joursdetrading = dayofweek>=1 and dayofweek<=6
    TakeProfit = 30
    //
    waitbar = 5
    if not onmarket and (onmarket[1] or longtriggered or shorttriggered) then
    lastindex = barindex
    endif
    gotrading = barindex-lastindex >= waitbar
    //
    MM100 = Average[100](close)
    IF MM100 > MM100[20]and joursdetrading AND tradestart AND tradeend THEN
    BUY 3 SHARES AT MARKET
    ENDIF
    IF MM100 < MM100[20] and joursdetrading AND tradestart AND tradeend THEN
    SELLSHORT 3 SHARES AT MARKET
    ENDIF
    SET STOP %LOSS 0.1
    SET TARGET PPROFIT TakeProfit

    #219994 quote
    Nicolas
    Keymaster
    Master

    La variable gotrading n’est pas utilisé dans tes conditions pour ouvrir les positions. Il faut l’ajouter à ta chaîne IF AND THEN

    #220008 quote
    RICOU
    Participant
    New

    Merci Nicolas, le code fonctionne très bien sur une stratégie simple en revanche dès que ça se complique un peut ça ne va plus.

    je te joins ici le développement sur lequel je travaille actuellement la base est ton indicateur “Supertrend+CCI” :

    DEFPARAM CumulateOrders = false // Cumul des positions désactivé
    // System closes all orders at 00.00 No new orders allowed until "FLATBEFORE" time
    DEFPARAM FLATBEFORE = 090000
    // Cancel all orders and close all positions at "FLATAFTER" Time
    DEFPARAM FLATAFTER = 180000
    joursdetrading = dayofweek>=1 and dayofweek<=5
    // No new orders or enlarging position before
    noEntryBeforeTime = 090000
    timeEnterBefore = time >= noEntryBeforeTime
    
    // No new orders or enlarging positions after
    noEntryAfterTime = 180000
    timeEnterAfter = time < noEntryAfterTime
    // --- settings
    CCIPeriod = 50 // Période de l'indicateur CCI
    ATRPeriod = 5 // Période de l'indicateur ATR
    Level = 0 // Niveau d'activation du CCI
    // --- fin des paramètres
    //
    waitbar = 3
    if not onmarket and (onmarket[1] or longtriggered or shorttriggered) then
    lastindex = barindex
    endif
    gotrading = barindex-lastindex >= waitbar
    //
    icci = CCI[CCIPeriod](typicalPrice)
    iatr = AverageTrueRange[ATRPeriod](close)
    TrendUp = 0.0
    TrendDown = 0.0
    SignUp = 0.0
    SignDown = 0.0
    
    if (icci >= Level and icci[1] < Level) then
    TrendUp = TrendDown[1]
    endif
    
    if (icci <= Level and icci[1] > Level) then
    TrendDown = TrendUp[1]
    endif
    
    if (icci > Level) then
    TrendUp = low - iatr
    
    if (TrendUp < TrendUp[1] and icci[1] >= Level) then
    TrendUp = TrendUp[1]
    endif
    endif
    
    if (icci < Level) then
    TrendDown = high + iatr
    
    if (TrendDown > TrendDown[1] and icci[1] <= Level) then
    TrendDown = TrendDown[1]
    endif
    endif
    
    if (TrendDown[1] <> 0.0 and TrendUp <> 0.0) then
    SignUp = TrendUp
    
    endif
    
    if (TrendUp[1] <> 0.0 and TrendDown <> 0.0) then
    SignDown = TrendDown
    endif
    st = max(TrendUp, TrendDown)
    
    // Conditions de trading
    longCondition = TrendUp > 0.0
    shortCondition = TrendDown > 0.0
    
    // Entrée en position longue
    if (longCondition)AND joursdetrading and gotrading then
    Buy 3 CONTRACT at market
    endif
    // Entrée en position courte
    if (shortCondition)AND joursdetrading and gotrading then
    Sellshort 3 CONTRACT at market
    endif
    // Sortie de position longue
    if (shortCondition)AND joursdetrading and gotrading then
    Sellshort 3 CONTRACT at market
    endif
    // Sortie de position courte
    if (longCondition)AND joursdetrading and gotrading then
    Buy 3 CONTRACT at market
    endif
    SET STOP %LOSS 0.25
    #220014 quote
    Nicolas
    Keymaster
    Master

    Pour moi ça fonctionne, si je graph gotrading, je remarque bien qu’elle retourne 0 durant 3 chandeliers dés qu’un ordre se ferme (voir image).

    go-trading.png go-trading.png
    #220021 quote
    RICOU
    Participant
    New

    Quand je fais un back test sur la journée d’aujourd’hui voilà ce que ça donne, on voit bien qu’une position s’ouvre dès la fermeture de la précédente ??

    Back-test-29-aout.jpg Back-test-29-aout.jpg Back-test-29-aout-bis.jpg Back-test-29-aout-bis.jpg
    #220068 quote
    Nicolas
    Keymaster
    Master

    Merci de m’indiquer timeframe et instrument.

    #220077 quote
    RICOU
    Participant
    New

    Dax 5 mn

    #220128 quote
    Nicolas
    Keymaster
    Master

    C’est normal, les positions sont clôturées par l’ouverture d’une nouvelle position inverse. Donc à aucun moment nous n’avons plus était au marché et dans ce cas pas d’attente.

    Pour mémoire, la demande initiale était: “peut on mettre un robot en pause pendant 5 mn par exemple après la clôture d’une position?”

    #220131 quote
    RICOU
    Participant
    New

    Merci beaucoup pour la réponse c’est très clair, en revanche y a t il une possibilité pour décaler le déclenchement de la suivante afin d’éviter ces ouvertures/fermetures consécutives?

    #220174 quote
    Nicolas
    Keymaster
    Master

    Donc cela modifierait ta stratégie, si il y a une condition pour ouvrir un ordre inverse alors que nous sommes déjà au marché, il ne faut pas l’ouvrir ?

    #220175 quote
    RICOU
    Participant
    New

    Oui par exemple, on peut essayer. Si tu pouvais me faire la modification du code ça serait sympa. Merci

    #220327 quote
    KumoNoJuzza
    Participant
    New

    Pour éviter qu’un short ferme et long et vice-versa, ajoute Not Onmarket dans tes conditions. J’ai oublié de l’intégrer dans une stratégie live et j”ai perdu de l’argent bêtement.

    Exemple:

    if Not Onmarket AND (longCondition)AND joursdetrading and gotrading then
    Buy 3 CONTRACT at market
    endif

    Je ne sais pas si tu peux ouvrir 2 positions dans le même sens. Ca donnerait:

    if Not ShortOnMarket AND (longCondition) AND joursdetrading and gotrading then
    Buy 3 CONTRACT at market
    endif

     

    Nicolas thanked this post
    #220371 quote
    RICOU
    Participant
    New

    Merci , je vais regarder ça.

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

Mettre un robot en pause temporairement


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
RICOU @ricou Participant
Summary

This topic contains 14 replies,
has 3 voices, and was last updated by RICOU
2 years, 6 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 08/26/2023
Status: Active
Attachments: 3 files
Logo Logo
Loading...