"SAFE MODE"

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

    Bonjour,

    Je cherche un moyen simple de remplacer le TP d’une stratégie par 0 dans le cas où le trade part dans la mauvaise direction (sauver le trade : “SAFE MODE”).

    L’idée est simple. Pour un LONG, dès que le + haut d’une barre clôturée est inférieure à la position prise => SAFE MODE (même principe pour un SHORT avec le + bas).

    Je ne comprends pas pourquoi cela ne fonctionne pas (pourtant la fonction GRAPH montre que le SAFEMODE est bien enclenché…)

    Un exemple ici sur le BRENT avec une condition basique sur le RSI.

    Merci de votre aide;)

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    
    // long entry parameter
    ONCE longRSI=30
    
    // short entry parameter
    ONCE shortRSI=70
    
    // position and money management
    ONCE positionSize = 1
    
    ONCE NUMBAR=0
    ONCE SAFEMODE=0
    
    ONCE trailingStartLong = 10
    ONCE trailingStartShort = 10
    
    ONCE stopLoss = 3         // in %
    ONCE takeProfit = 5       // in %
    ONCE TPSAFE=0
    
    // conditions to enter long positions
    c1 = RSI crosses over longRSI
    
    IF c1 AND NOT ONMARKET THEN
    BUY positionSize CONTRACT AT MARKET
    ENDIF
    
    // conditions to enter short positions
    c2 = RSI crosses under shortRSI
    
    IF c2 AND NOT ONMARKET THEN
    SELLSHORT positionSize CONTRACT AT MARKET
    ENDIF
    
    //trailing stop
    //resetting variables when no trades are on market
    IF NOT ONMARKET THEN
    MAXPRICE = 0
    MINPRICE = close
    priceexit = 0
    ENDIF
    
    //case SHORT order
    IF SHORTONMARKET THEN
    MINPRICE = MIN(MINPRICE, close) //saving the MFE of the current trade
    IF tradeprice(1) - MINPRICE >= trailingStartShort * pointsize THEN //if the MFE is higher than the trailingstop then
    priceexit = MINPRICE + trailingStartShort * pointsize //set the exit price at the MFE + trailing stop price level
    ENDIF
    ENDIF
    
    //case LONG order
    IF LONGONMARKET THEN
    MAXPRICE = MAX(MAXPRICE, close) //saving the MFE of the current trade
    IF MAXPRICE - tradeprice(1) >= trailingStartLong * pointsize THEN //if the MFE is higher than the trailingstop then
    priceexit = MAXPRICE - trailingStartLong * 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
    
    //SAFE MODE
    if onmarket then
    NUMBAR=NUMBAR+1
    else
    NUMBAR=0
    endif
    
    IF NOT ONMARKET THEN
    SAFEMODE=0
    endif
    
    if (longonmarket and high<tradeprice(1)) or (shortonmarket and low>tradeprice(1)) then
    SAFEMODE=1
    endif
    
    if SAFEMODE=0 then
    SET TARGET %PROFIT takeProfit
    else
    SET TARGET PROFIT TPSAFE
    endif
    
    SET STOP %LOSS stopLoss
    
    
    graph SAFEMODE
    #67773 quote
    robertogozzi
    Moderator
    Master

    à la ligne 84, TPSAFE aura toujours une valeur nulle!
    Cela peut-il être la cause?

    #67880 quote
    Toto le Heros
    Participant
    Veteran

    Merci de ta réponse Roberto.

    En fait, c’est ce que je souhaite. Je souhaite que si on “bascule” en “SAFEMODE” du fait de la condition SAFEMODE=1, alors à ce moment là le TP initial ne s’applique plus mais qu’il se fige à 0.

    (“Sauver le trade en essayant de le faire clôturer FLAT si les cours ne partent pas dans le sens du trade).

    #67884 quote
    robertogozzi
    Moderator
    Master

    https://www.prorealcode.com/documentation/target/

    Comme vous pouvez le voir dans la documentation SET TARGET PROFIT X définit la cible à ce prix.
    Étant ZÉRO, il ne sera jamais atteint.

    #67886 quote
    Toto le Heros
    Participant
    Veteran

    On peut se tutoyer 😉

    je ne suis pas sûr de te suivre, mais te remercie de ta réponse.

    le TP n’est-il pas le gain (en points) espéré ? (la différence entre le prix atteint et le prix de la position initiale ?…) En tous cas, c’est toujours comme cela que je l’ai codé…

    Quelle serait une alternative possible ?

    #67890 quote
    robertogozzi
    Moderator
    Master

    La traduction littérale de la documentation anglaise dit Instruction pour définir un ordre cible au niveau de prix x.

    Pour indiquer les points cibles, vous devez écrire SET TARGET PPROFIT, au moins autant que je sache.

    Dans tous les cas, si votre instruction indique la différence de prix à utiliser comme cible, je ne sais pas si ZERO est accepté.

    Pour le seuil de rentabilité (breakeven) j’utilise le code écrit par @Nicolas.

    #67896 quote
    Toto le Heros
    Participant
    Veteran

    ???

    Merci quand même.

    #67933 quote
    Nicolas
    Keymaster
    Master

    Je n’ai pas testé, mais qu’est ce qui te fait penser que le takeprofit à 0, n’est jamais utilisé selon toi ? Puisque tu ne peux pas le voir justement ?

    #67939 quote
    Toto le Heros
    Participant
    Veteran

    Certains trades mal engagés (graph SAFEMODE à 1) se redressent et traversent le breakeven. Ils cloturent positifs, accompagnés par le trailing stop…

    #68621 quote
    Nicolas
    Keymaster
    Master

    Donc cela fonctionne ? puisque le takeprofit ne se déclenche pas, et que les ordres sont sortis grâce au trailing stop, c’est que le TP est à 0 ?

    #68652 quote
    Toto le Heros
    Participant
    Veteran

    Bonjour Nicolas,

    Merci de ta réponse.

    Eh bien non, il me semble. Un ordre est en perte, disons d’une dizaine de points (gain=-10) et son SAFE MODE est à 1. Il est sensé coupé à gain=0 si il refait son retard (TP=0) ou bien au Stop Loss défini.

    J’observe des cas où il remonte mais ne se coupe pas à 0. Il franchit le TP et est ensuite “pris en charge” par le TRAILING STOP.

    C’est positif du point de vue de trade en question, mais çà ne fait pas ce que je souhaite.

    Merci

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

"SAFE MODE"


ProOrder : Trading Automatique & Backtests

New Reply
Author
Summary

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

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