LIMITER LE NOMBRE DE POSITIONS PRISES EN PYRAMIDAGE

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #66180 quote
    Toto le Heros
    Participant
    Veteran

    Bonjour,

    Ci-joint un petit exercice de pyramidage sur le DAX en UT=15min (short only pour les tests dans le contexte actuel…)

    DEFPARAM FLATAFTER            = 213000
    noEntryBeforeTime             = 091500
    timeEnterBefore = time >= noEntryBeforeTime
    noEntryAfterTime              = 213000
    timeEnterAfter = time < noEntryAfterTime
    daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Variables
    ordersize =    2
    TS        =   25
    SL        =   50
    TP        =   100
    
    //Condition to go short
    myMACD = MACD[12,26,9](close)
    short = myMACD crosses over 0
    
    //first order + //let's add another stop order while price continue to go lower (more than 15 points)
    IF (COUNTOFPOSITION<=ordersize) AND short AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT ordersize CONTRACTS AT MARKET
    SELLSHORT ordersize/2 CONTRACTS AT (CLOSE-30) STOP//should I write close instead of PositionPrice here ?
    ENDIF
    
    If ShortOnMarket THEN
    SELL AT (POSITIONPRICE-TP) LIMIT
    SELL AT (POSITIONPRICE+SL) STOP
    ENDIF
     
    //let's add another order while price continue to go lower (more than 15 points)
    IF ShortOnMarket AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry and (COUNTOFPOSITION<ordersize*1.5) THEN
    SELLSHORT ordersize/2 CONTRACTS AT (TRADEPRICE(1)-30) STOP
    ENDIF
    
    //trailing stop
    trailingstop = TS//Best 30
     
    //resetting variables when no trades are on market
    if not onmarket then
    MINPRICE = close
    priceexit = 0
    endif
     
    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if positionprice-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
     
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    

     

    Je ne suis pas loin de ce que je souhaite faire, mais je ne parviens pas à limiter le nombre de positions prises par le système à 3. (les 2 positions initiales et la position additionnelle)

    J’ai un problème de compréhension de l’instruction COUNTOFPOSITION visiblement…

    Votre aide me sera précieuse.

    D’avance merci,

    #66181 quote
    Nicolas
    Keymaster
    Master

    COUNTOFPOSITION est négatif pour les positions de vente à découvert et positif pour les achats. Il faut donc prendre en considération cette donnée dans ta condition de comparaison. Ou alors utiliser ABS(COUNTOFPOSITION) tout simplement.

    Il y a aussi COUNTOFSHORTSHARES.

    Toto le Heros thanked this post
    #66202 quote
    Toto le Heros
    Participant
    Veteran

    Merci beaucoup Nicolas.

    Ce n’est pas encore parfait mais je progresse grâce à ton précieux support.

    Je me heurte de nouveau à cette difficulté liée au fait que je souhaite placer (dans le même temps que mon premier ordre de vente) un ordre de vente STOP 6 points en dessous (pour préparer ma pyramide).

    Ca fonctionne si je rentre (close-6) mais j’aurais préféré utiliser (positionprice-6) pour considérer le spread et le slippage éventuel à l’ouverture de la bougie… Malheureusement dans ce cas le système est immédiatement arrêté sur le motif que j’ai essayé de placer un ordre avec un STOP ou une limite négative….

    Puis-je contourner ce problème stp ?

    DEFPARAM FLATAFTER            = 213000
    noEntryBeforeTime             = 091500
    timeEnterBefore = time >= noEntryBeforeTime
    noEntryAfterTime              = 213000
    timeEnterAfter = time < noEntryAfterTime
    daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // Variables
    ordersize =    2
    TS        =   10
    SL        =   15
    TP        =   35
    
    //Condition to go short
    myMACD = MACD[12,26,9](close)
    short = myMACD < myMACD[1]
    
    //first order + //let's add another stop order while price continue to go lower (more than 15 points)
    IF (abs(COUNTOFPOSITION)<ordersize) AND short AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry THEN
    SELLSHORT ordersize CONTRACTS AT MARKET
    MARK1=close
    SELLSHORT ordersize/2 CONTRACTS AT (close-6) STOP//should I write close instead of PositionPrice here ?
    EXITSHORT AT MARK1-TP LIMIT
    EXITSHORT AT MARK1+SL STOP
    ENDIF
    
    If ShortOnMarket and abs(COUNTOFPOSITION)=2 THEN
    EXITSHORT AT MARK1-TP LIMIT
    EXITSHORT AT MARK1+SL STOP
    ENDIF
    
    
    //let's add another order while price continue to go lower (more than 15 points)
    IF ShortOnMarket AND timeEnterBefore AND timeEnterAfter AND not daysForbiddenEntry and (abs(COUNTOFPOSITION)<ordersize*1.5) THEN
    SELLSHORT ordersize/2 CONTRACTS AT (TRADEPRICE(1)-6) STOP
    MARK2=(2*MARK1+CLOSE)/3
    EXITSHORT AT MARK1-TP LIMIT
    EXITSHORT AT MARK1+SL STOP
    ENDIF
    
    If ShortOnMarket and abs(COUNTOFPOSITION)=3 THEN
    EXITSHORT AT MARK2-TP LIMIT
    EXITSHORT AT MARK2+SL STOP
    ENDIF
    
    //trailing stop
    trailingstop = TS//Best 30
     
    //resetting variables when no trades are on market
    if not onmarket then
    MINPRICE = close
    priceexit = 0
    endif
     
    //case SHORT order
    if shortonmarket then
    MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
    if positionprice-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
    endif
    endif
     
    //exit on trailing stop price levels
    if onmarket and priceexit>0 then
    EXITSHORT AT priceexit STOP
    SELL AT priceexit STOP
    endif
    
    #66404 quote
    Nicolas
    Keymaster
    Master

    En essayant avec TRADEPRICE ?

    #66421 quote
    Toto le Heros
    Participant
    Veteran

    Merci de ta réponse Nicolas.

    De mémoire çà conduit à une fermeture immédiate de la stratégie et de la position avec la même erreur que POSITIONPRICE. Mais je vais réessayer. Seulement il semble qu’il y a qq bugs sur PRT DEMO ce matin (suite au chgt d’heure ?). Bref, je vais patienter un peu. A bientôt.

    #66424 quote
    Nicolas
    Keymaster
    Master

    En effet TRADEPRICE ne sera connu qu’au Close suivant..

    Toto le Heros thanked this post
    #66429 quote
    Toto le Heros
    Participant
    Veteran

    Ok, je comprends le principe. Du coup, je vais me contenter de l’approximation tradeprice=close pour la première barre après prise de position et affiner ensuite.

    MERCI

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

LIMITER LE NOMBRE DE POSITIONS PRISES EN PYRAMIDAGE


ProOrder : Trading Automatique & Backtests

New Reply
Author
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Toto le Heros
7 years, 11 months ago.

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