Long et short en même temps

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #248422 quote
    PRC_2021
    Participant
    Average

    Bonjour,
    Pouvez m’indiquer pourquoi mes positions s’ouvrent et se ferment aussitôt.

    Merci

    
    if Achat and Not OnMarket then
    // POUR UN ACHAT
    //Ordre Achat
    BUY 1 CONTRACT AT MARKET
    SLFinance = 1
    SLA = LOW//close-lowest[2](close[1])
    TP1A = close + (abs(close - SLA) * 1)
    TP2A = close + (abs(close - SLA) * 2)
    SET STOP pLOSS SLA
    ELSIF Vente and Not OnMarket THEN
    //Ordre VENTE
    SELLSHORT 1 CONTRACT AT MARKET
    SLFinance = 1
    SLV = HIGH//close-highest[2](close[1])
    TP1V = close - (abs(SLV - close) * 1)
    TP2V = close - (abs(SLV - close) * 2)
    SET STOP pLOSS SLV
    ENDIF
    
    //SL et TP pour la position d'achat
    if longonmarket and close >= TP1A and SLFinance = 1 then
    sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    //SL et TP pour la position de vente
    If shortonmarket and close >= TP1V and SLFinance = 1 then
    buy abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    GRAPHONPRICE SLV  coloured("Red")
    GRAPHONPRICE TP1V coloured("Blue")
    GRAPHONPRICE TP2V coloured("GREEN")
    Sans-titre-3.png Sans-titre-3.png
    #248432 quote
    robertogozzi
    Moderator
    Master

    Sur la ligne 29, vous ne devez PAS utiliser « BUY », car elle sert à ouvrir une position longue (et donc à clôturer la position courte actuelle).
    Pour sortir d’une position courte, vous devez utiliser « EXITSHORT» :

    EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    Iván González thanked this post
    #248433 quote
    PRC_2021
    Participant
    Average

    Merci Roberto mais malgré ce changement cela est toujours pareil. Il doit y avoir quelque chose d’autre

    If shortonmarket and close >= TP1V and SLFinance = 1 then
    EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    #248434 quote
    PRC_2021
    Participant
    Average
    DEFPARAM CUMULATEORDERS = false
    
    TIMEFRAME(5 Minute)
    //Réinitialisation VALEUR
    if Not OnMarket THEN
    SLFinance = 0
    //SL = 0
    //TP1 = 0
    //TP2 = 0
    endif
    
    niveau = 23460
    
    Achat = open < niveau and close > niveau+2*pipsize
    Vente = open > niveau and close < niveau+2*pipsize
    
    if Achat and Not OnMarket then
    // POUR UN ACHAT
    //Ordre Achat
    BUY 1 CONTRACT AT MARKET
    SLFinance = 1
    SLA = LOW//close-lowest[2](close[1])
    TP1A = close + (abs(close - SLA) * 1)
    TP2A = close + (abs(close - SLA) * 2)
    SET STOP pLOSS SLA
    ELSIF Vente and Not OnMarket THEN
    //Ordre VENTE
    SELLSHORT 1 CONTRACT AT MARKET
    SLFinance = 1
    SLV = HIGH//close-highest[2](close[1])
    TP1V = close - (abs(SLV - close) * 1)
    TP2V = close - (abs(SLV - close) * 2)
    SET STOP pLOSS SLV
    ENDIF
    
    //SL et TP pour la position d'achat
    if longonmarket and close >= TP1A and SLFinance = 1 then
    sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    
    //SL et TP pour la position de vente
    If shortonmarket and close >= TP1V and SLFinance = 1 then
    EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    
    GRAPHONPRICE SLV  coloured("Red")
    GRAPHONPRICE TP1V coloured("Blue")
    GRAPHONPRICE TP2V coloured("GREEN")
    
    #248435 quote
    JC_Bywan
    Moderator
    Master

    Bonjour,

    Dans le code du post d’en-tête, si ta ligne 21 pour un achat dit:

    if longonmarket and close >= TP1A and …

    par analogie j’aurais imaginé ta ligne 28 non pas: If shortonmarket and close >= TP1V and …

    mais plutôt: If shortonmarket and close <= TP1V

    A tester.

    #248436 quote
    PRC_2021
    Participant
    Average

    Bonjour JC,

    Non ce n’est pas cela non plus 🙁

    #248438 quote
    JC_Bywan
    Moderator
    Master

    Les set stop ploss ne sont pas ok non plus, car tu leur as mis un niveau alors que cette commande s’attend à une distance en points, par exemple close-SLA plutôt que SLA

    Je ne juge pas de la validité ou pas de ton stop, mais de la nature de la valeur que tu as associé à la commande ploss, c’est-à-dire si j’enlève le terme SLA de la discussion pour ne pas être ambigu: “set stop ploss (close-low)” serait correct là où “set stop ploss low” (puisque ton SLA=low) ne n’est pas.

    (et à la vente “set stop ploss high-close” serait correct là où “set stop ploss high” (puisque ton slv=high) ne n’est pas.)

    Iván González thanked this post
    #248439 quote
    JC_Bywan
    Moderator
    Master
    #248447 quote
    PRC_2021
    Participant
    Average

    Entendu, je vais tester cela.

    Par contre, lorsque j’affiche ces données sur le graphique, elles sont correctement identifiées grâce à “GRAPHONPRICE ” comme tu peux le voir sur la pj.

    GRAPHONPRICE SLV coloured(“Red”)
    GRAPHONPRICE TP1V coloured(“Blue”)
    GRAPHONPRICE TP2V coloured(“GREEN”)

    Sans-titre-4.png Sans-titre-4.png
    #248449 quote
    PRC_2021
    Participant
    Average

    J’ai essayé ce code mais ne fonctionne pas. Pourtant celui ci m’avait l’air correct … Je souhaite simplement le SL au dessus /dessous de la bougie précédente et ensuite Tp *1 et *2

    DEFPARAM CUMULATEORDERS = false
    
    TIMEFRAME(5 Minute)
    //Réinitialisation VALEUR
    if Not OnMarket THEN
    SLFinance = 0
    //SL = 0
    //TP1 = 0
    //TP2 = 0
    endif
    
    niveau = 23460
    
    Achat = open < niveau and close > niveau+2*pipsize
    Vente = open > niveau and close < niveau+2*pipsize
    
    if Achat and Not OnMarket then
    // POUR UN ACHAT
    //Ordre Achat
    BUY 1 CONTRACT AT MARKET
    SLFinance = 1
    SLA = abs(close - Low[1])                        //low//close-lowest[2](close[1])
    TP1A = SLA*2                                     //close + (abs(close - SLA) * 1)
    TP2A = SLA*3                                     //close + (abs(close - SLA) * 2)
    SET STOP pLOSS SLA
    ELSIF Vente and Not OnMarket THEN
    //Ordre VENTE
    SELLSHORT 1 CONTRACT AT MARKET
    SLFinance = 1
    SLV = abs(close - High[1])
    TP1V = SLV*2                                        //close - (abs(SLV - close) * 1)
    TP2V = SLV*3                                        //close - (abs(SLV - close) * 2)
    SET STOP pLOSS SLV
    ENDIF
    
    //SL et TP pour la position d'achat
    if longonmarket and close >= TP1A and SLFinance = 1 then
    sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    //SL et TP pour la position de vente
    If shortonmarket and close >= TP1V and SLFinance = 1 then
    EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    
    GRAPHONPRICE SLV  coloured("Red")
    GRAPHONPRICE TP1V coloured("Blue")
    GRAPHONPRICE TP2V coloured("GREEN")
    
    #248492 quote
    PRC_2021
    Participant
    Average

    Personne n’as d’idée ?

    #248493 quote
    JS
    Participant
    Senior

    Tu calcules : SLA = abs(Close – Low[1])
    Ce calcul donne un nombre de points, donc pas un niveau de prix mais bien un nombre de points (par exemple 10 points).
    Ensuite, tu ecris :
    If LongOnMarket and Close >= TP1A and SLFinance = 1 then
    Tu verifies alors si Close est superieur ou egal a un nombre de points.
    Mais Close est naturellement toujours superieur a une valeur exprimee en points (SL), ce qui fait que ta position est immediatement cloturee partiellement (abs(CountOfPosition) / 2).

    #248496 quote
    JS
    Participant
    Senior

    Voici le code modifié avec l’utilisation de niveaux de prix…

    DEFPARAM CUMULATEORDERS = false
    
    TIMEFRAME(5 Minute)
    //Réinitialisation VALEUR
    if Not OnMarket THEN
    SLFinance = 0
    //SL = 0
    //TP1 = 0
    //TP2 = 0
    endif
    
    niveau = 42000 //Dow Jones
    
    Achat = open < niveau and close > niveau+2*pipsize
    Vente = open > niveau and close < niveau+2*pipsize
    
    if Achat and Not OnMarket then
    // POUR UN ACHAT
    //Ordre Achat
    BUY 1 CONTRACT AT MARKET
    SLFinance = 1
    SLA = Close-abs(Close - Low[1])                        //low//close-lowest[2](close[1])
    TP1A = Close+2*(abs(Close-Low[1]))                                     //close + (abs(close - SLA) * 1)
    TP2A = Close+3*(abs(Close-Low[1]))                                     //close + (abs(close - SLA) * 2)
    SET STOP Price SLA
    ELSIF Vente and Not OnMarket THEN
    //Ordre VENTE
    SELLSHORT 1 CONTRACT AT MARKET
    SLFinance = 1
    SLV = Close+abs(close - High[1])
    TP1V = Close-2*(abs(Close-High[1]))                                        //close - (abs(SLV - close) * 1)
    TP2V = Close-3*(abs(Close-High[1]))                                        //close - (abs(SLV - close) * 2)
    SET STOP Price SLV
    ENDIF
    
    //SL et TP pour la position d'achat
    if longonmarket and close >= TP1A and SLFinance = 1 then
    sell abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    //SL et TP pour la position de vente
    If shortonmarket and close <= TP1V and SLFinance = 1 then
    EXITSHORT abs(COUNTOFPOSITION)/2 CONTRACTS AT MARKET
    set stop BREAKEVEN
    SLFinance = 2
    endif
    
    
    GRAPHONPRICE SLV  coloured("Red")
    GRAPHONPRICE TP1V coloured("Blue")
    GRAPHONPRICE TP2V coloured("GREEN")
    PRC_2021 thanked this post
    #248509 quote
    PRC_2021
    Participant
    Average

    Bonjour JS,

    Merci pour tes retours. Effectivement, oui j’affichais un niveau de prix et non un nombre de point.

    J’ai relancé l’algo, j’ai maintenant juste un soucis de le Stop Loss qui ne s’affiche pas sur le plus Haut/bas de la bougie précédente mais environ 30pts au dessus comme tu peux le voir sur la piece jointe.

    Sais tu de quoi cela peux venir ?

    Merci encore pour ton aide.

    Sans-titre-5.png Sans-titre-5.png
    #248513 quote
    JS
    Participant
    Senior

    Salut,


    Lorsqu’un ordre est passe, le stop loss (SL) depend de la taille de la bougie precedente : SLV = Close + abs(Close - High[1])

    Le SL est donc variable et depend de la distance entre Close et High[1]

    Une grande distance entraine un SL plus large…

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

Long et short en même temps


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
PRC_2021 @manu35250 Participant
Summary

This topic contains 17 replies,
has 4 voices, and was last updated by PRC_2021
8 months, 1 week ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 06/20/2025
Status: Active
Attachments: 3 files
Logo Logo
Loading...