Demande de boucle pour pyramidage, trailing stop et breakeven

Viewing 14 posts - 16 through 29 (of 29 total)
  • Author
    Posts
  • #89443 quote
    FREDNC
    Participant
    Senior

    J’ai bien sur mis au ,moment de l’entré en position bot1=1 et idem pour le bot2=1

    #89446 quote
    Nicolas
    Keymaster
    Master

    Inutile de faire une boucle, puisque tu rentres directement au marché, tu sais précisément quand incrémenter la variable, donc à chaque instruction BUY ou SELLSHORT, tu peux faire :

    if buycondition then 
     buy 1596 shares at market //entre en position 
     pos = pos +1 //incrémente ma variable pos
    endif

    et n’oublie pas de reset pos à 0 quand tu n’es plus au marché.

    #89519 quote
    FREDNC
    Participant
    Senior

    Merci, effectivement c’est plus simple et tout aussi efficace.  Dois-je vraiment acheter 1596 shares at market hahahah 😉

    En attendant ta réponse, j’avais remplacé la condition “countofposition” par “breakeven” (Breakeven étant:” breakevenLevel>0″ ).

    Mais, même si on utilise des valeurs identiques, Il semblerait qu’à partir du moment ou l’on change les paramétrés du trail en cours de position on perd un petit peu. Rien de dramatique mais c’est un fait…

    Je te fais parts des prochains résultats.

    Cordialement

    #89592 quote
    FREDNC
    Participant
    Senior

    Bonjour @Nicolas.

    1)La stratégie avance bien , j’ai presque fini et je la posterais quand tout seras vraiment débugger….

    2)Juste une question, aujourd’hui j’ai eu l’occasion de voir une prise de position en direct d’un de mes robots.

    Le niveau de Startbreakeven  a était traversés plusieurs fois par le cours (des mèches),   Du coup , j’ai fini par sortit en manuel.

    Dans cette stratégie je sors sur le trail en extrême limite avant retournement et non sur un TP.

    Normalement,  j’aurais dût sortir à au minimum à  startbreakeven  et + Point to keep, si le court me favorise, vrai ou faut ?

    Le trail que j’utilise c’est le même que précédemment, C’est normal ou il y a eu un bog ?

    Je t’ais joins un Screenshots. PS: L’outil règle de PRT, délimite mon SL et mon startbreakeven (il est même plus haut).  Comme d’habitude mes règles sont simples SL = (close- Donchian) ,  startbreakeven = abs (MM34-CDH[0])   et je réduis la distance de startbreakeven par –  abs( MM34-close).

    voici le code d’entré et le Trail

    // Conditions pour ouvrir une position Short
    if (close CROSSES UNDER MM34) AND timeEnterBefore AND timeEnterAfter then//
    BE = abs (MM34-CDH[0])
    MinusBE = abs(MM34-close)
    //TP = abs (close-CDH[0])+(SPREAD/2)
    SL = abs (close-CDH[0])+(SPREAD/2)
    NBR= TEuro/SL//**************Mettre à 1 pour bactester****************
    SELLSHORT NBR CONTRACT AT MARKET
    ENDIF
    
    
    
    //************************************************************************
    startBreakeven = (BE-MinusBE) //how much pips/points in gain to activate the breakeven function?
    PointsToKeep = 10000 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    ENDIF
     
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
     
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    ENDIF
    // --- SHORT SIDE ---
    IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = tradeprice(1)-PointsToKeep*pipsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    EXITSHORT AT breakevenLevel STOP
    ENDIF
     
    //************************************************************************
    // Stops et objectifs
    SET STOP pLOSS SL//
    
    

     

    Merci

    Cordialement .

    Capture-3.png Capture-3.png
    #89596 quote
    Nicolas
    Keymaster
    Master

    Si tu testes le Close alors tu ne testes pas des High ou des Low. Logique. 😉

    N’oublie pas que le code est lu qu’à la fin de la barre également.

    #89599 quote
    FREDNC
    Participant
    Senior

    Je test, la distance entre close et CDH qui le Donchian haut donc le high des 15 dernière bougies. Je comprends pas ton raisonnement.

    Comment tester le High ?

    #89600 quote
    FREDNC
    Participant
    Senior

    @Nicolas, pourrait tu me corriger se code car je l’utilise dans presque toute mes stratégies et jusqu’à pressent ça toujours bien fonctionner.

    #89603 quote
    FREDNC
    Participant
    Senior

    Bon , au moment de cette position, le graph de la variable BE me donne 9,21765 et MinusBE 0.08235 ce qui nous donne un startbreakeven à 9,1353 .  De l’entrée en position (open) à la mèche la plus basse il y a 11,5 pips. Même en enlevant  1 pip de spread, le startbreakeven aurai dût ce mettre en route .  Ca toujours était le cas jusqu’à présent.  Après si tu me dit que l’écriture de mon code et source de bog, je suis très intéressé. Mais je ne comprends pas du tout, d’autant que le graph des variables démontre que ça aurait dût se déclenché….


    @nicolas
    : Peux tu être plus explicite car je suis dans le floue, mais je demande qu’à corriger

    Capture-4.png Capture-4.png
    #89618 quote
    Nicolas
    Keymaster
    Master

    Pour déclencher ton breakeven, tu ne testes pas les mèches, mais les Close: closetradeprice(1)

    Hors tu penses que si une mèches a traversé le niveau de déclenchement du breakeven, alors il aurait du fonctionner, c’est faux. Si tu veux tester une mèche, tu testes les Highs et les Lows, pas les Close.

    #89642 quote
    FREDNC
    Participant
    Senior

    Merci Pour ta réponse, effectivement je comprends mieux….

    Faut que je revois l’écriture du code du trailling-stop ….

    Mais je ne sais pas si tu as fait attention, on voit clairement que les closes sont au dessus breakevenlevel mais l’open d’après est plus bas. En refaisant mes calcules, l’open est pile poile sur le niveau mais c’est tellement serrer que le doute  existeras toujours. C’est quand même étrange d’avoir un open d’une bougie vert plus bas qu’un close de précédente bougie (rouge) . Micro slippage ?

    Bref je vais donc revoir l’écriture du trail à tête reposé.

    Si à ta connaissance il en existe déjà un trail qui tient comptes des highs et des lows à la place des closes, je suis preneur.

    je suis en over-coding 😉

    #89649 quote
    Nicolas
    Keymaster
    Master

    C’est quand même étrange d’avoir un open d’une bougie vert plus bas qu’un close de précédente bougie (rouge) .

    Non, ça s’appelle un “gap” 🙂

    Un gap est un écart haussier ou baissier entre le cours de clôture d’un chandelier et le cours d’ouverture du chandelier suivant. Un gap est du à un nombre important d’ordres allant dans le même sens entre les deux chandeliers.

    https://www.centralcharts.com/fr/gm/1-apprendre/5-trading/14-strategie/293-comment-trader-les-gaps

    #89722 quote
    FREDNC
    Participant
    Senior

    Exact, c’est un gap, un micro-gap… J’ai une stratégie en développement qui trade les gaps de 8h00 sur le Dax.

    En cours de journée, j’appelle plutôt ça “un trou de cotation” mais c’est de la rhétorique car un trou de cotation c’est un gap 😉

    #89918 quote
    FREDNC
    Participant
    Senior

    Bonjour Nicolas,

    J’ai enfin fini… Le concept du “Machin Gun ” est un succès.

    Voici les trois versions: Screenshots ci dessous

    Version N° 1:  la stratégie de base:

    Version N°2: stratégie avec le Multi-positions et démarrage du trailing sur close – traderprice. On observe que les gains fond plus que doubler. Le drawdown maîtrisé mais en augmentation en terme globale et non en terme de positions. L’augmentation du drawdonw est du au spread des positions supplémentaires qui sort à o

    Version N°3: stratégie avec le Multi-positions et démarrage du trailing sur High/Low -traderprice.  Le drawdown est moindre que la version originale (en euro) et on observe une belle progression par rapport à la version d’origine. Mais on observe que les gains sont moindre que la version N°3. A noté que sur la version N°3 ,j’ai supprimé “countofposition” à la faveur d’une variable suivant tes conseils. Ça  n’apporte rien en terme de performance mais ça évite de l’utilisation de “countofposition” qui est source d’erreurs.

    Je trouve que globalement, ça apport une belle amélioration et le concept mérite qu’on si attarde en tous cas. Avec l’arrivé de l’ ESMA l’année dernière faudrait faire attention à ne pas être en appel de marge dût au Multi-position. La fonction “limiter le nombre de positions” sera très utile en fonction des compte de chacun.

    Si tu souhaite la mettre en bibliothèque je ferai un post spécifique.

    Merci pour ton aide

    Ps: Si dessous la version N°3 (ma préférée)

    // Définition des paramètres du code*************** Dax M1, 100 000 bougies, spread 1******************
    DEFPARAM CumulateOrders =  true //false // Cumul des Entrytions ACTIVEES***Voir option Pyramidage Tout à la fin, sous le BreakEven***
    DEFPARAM Preloadbars = 20000
    //Nbr de contrats*******************
    N=2
    //**********************************
    // Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une Entrytion avant l'heure spécifiée
    noEntryBeforeTime = 091500//080000//091500
    timeEnterBefore = time >= noEntryBeforeTime
    
    //Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une Entrytion après l'heure spécifiée
    noEntryAfterTime = 170000//2130000//170000
    timeEnterAfter = time < noEntryAfterTime
    
    //Jour de trading du lundi au vendredi inclus
    if DayOfWeek <= 5 then
    Tradeday=1
    elsif tradeday=1 and DayOfWeek > 5 then
    TradeDay=0
    endif
    
    IF ONMARKET and (TIME>=171500 and close-positionprice>1) THEN
    SELL AT MARKET
    EXITSHORT AT MARKET
    ENDIF
    Spread=1
    
    //Canal Donchian**********************************************************************************
    DC=15//
    CDH=Highest[DC](high)
    CDB=Lowest[DC](low)
    
    //Taille des Entrytions autorisées en Pips*********************************************************
    TMini=7//7
    TMaxi=13//12
    TailleA = (abs(close-CDB))
    TailleV = (abs(CDH-close))
    PC=5//14// ***********************************Optimisable entre 10% et 40% admit Entre Entrytion/objectif/MM34
    If Abs (close[1]-close) < abs(tailleA*PC/100) then
    Dist=1
    elsif Abs (close[1]-close) < abs(TailleV*PC/100) then
    Dist=1
    else
    Dist=0
    endif
    
    //PPJ*********************************************************************************************
    PPJ= (DHigh(1) + DLow(1) + DClose(1))/3
    
    //TDI*********************************************************************************************
    lengthRSI = 13
    lengthband = 34
    lengthrsipl = 2
    lengthtradesl = 7
    
    r = rsi[lengthrsi](close)
    ma = average[lengthband](r)
    offs = (1.6185 * std[lengthband](r))
    up = ma+offs
    dn = ma-offs
    mid = (up+dn)/2
    TDIVert = average[lengthrsipl](r)
    TDIRouge = average[lengthtradesl](r)
    
    // "CROSS 1"**************************************************************************************
    IF not onmarket and TDIVert > mid and TDIRouge > mid and mid > 50 and TMini<abs((CDB[0]-Close)+(SPREAD/2)) and TMaxi>abs((CDB[0]-close)+(SPREAD/2)) and close >= PPJ and dist  and Tradeday  AND  timeEnterBefore AND  timeEnterAfter  THEN
    CROSSTa = 1
    elsif not onmarket  and TDIVert < mid and TDIRouge < mid and mid < 50 and TMini<abs((close-CDH[0])+(SPREAD/2)) and TMaxi>abs((close-CDH[0]+(SPREAD/2))) and close <= PPJ and dist  and Tradeday  AND  timeEnterBefore AND  timeEnterAfter THEN
    CROSSTb = 1
    else
    CROSSTa=0
    CROSSTb=0
    ENDIF
    
    // "CROSS 2"**************************************************************************************
    if Pyra and  TDIVert crosses over TDIRouge or r[1]<r or TDIVert[1]< TDIVert THEN//
    CROSST2A = 1
    elsif Pyra and  TDIVert crosses under TDIRouge or r[1]<r or TDIVert[1]< TDIVert THEN//
    CROSST2V = 1
    else
    CROSST2A=0
    CROSST2V=0
    ENDIF
    
    //Bot1 **************************************************************************************************
    If not onmarket then
    Entry=0
    endif
    //Long1
    Bot1=0
    If not onmarket and CROSSTa and TDIVert crosses over TDIRouge then
    Bot1=3 //Pour graph la variable. Inutine quand tous fonctionne
    BUY N CONTRACT AT MARKET
    SL = abs (close-CDB)+(SPREAD/2)
    TP = abs (close-CDB)+(SPREAD/2)
    Entry = Entry+1
    endif
    //Short1
    if not onmarket and CROSSTb and TDIVert crosses under TDIRouge then
    Bot1=3 //Pour graph la variable. Inutine quand tous fonctionne
    SELLSHORT N CONTRACT AT MARKET
    SL = abs (CDH-close)+(SPREAD/2)
    TP = abs (CDH-close)+(SPREAD/2)
    Entry = Entry+1
    ENDIF
    
    //Bot2********************************************************************************************
    On=1//********  1= Bot2 actif 0= Bots inactif  ********
    //Long2
    Bot2=0////Pour graph la variable. Inutine quand tous fonctionne
    If longonmarket and on and Pyra and CROSST2A then
    Bot2=5//Pour graph la variable. Inutine quand tous fonctionne
    BUY N CONTRACT AT MARKET
    SL = abs (close-CDB)+(SPREAD/2)
    Entry = Entry+1
    endif
    //Short2
    if shortonmarket and On and Pyra and CROSST2V  then
    Bot2=5//Pour graph la variable. Inutine quand tous fonctionne
    SELLSHORT N CONTRACT AT MARKET
    SL = abs (CDH-close)+(SPREAD/2)
    Entry = Entry+1
    endif
    
    //Trail Bascule "point to keep"*******************************************************************
    //Mono Entrytion
    If breakeven=0 then
    StBe=TP/1
    PtK= TP/3   //1000 pour sortir au plus haut. Aucune respiration posible. Peut être modifié (TP/X)
    
    //Muti-poditions et au delà de X pips
    elsif  Entry>1 then//
    StBe=TP/1
    PtK=1000// pour sortir au plus haut. Aucune respiration posible. Peut être modifié (TP/X)
    //**************************************
    endif
    
    // Trail et management **************************************************************************************************
    //définifition et bascule de "StartBreakeven" et "Point To Keep"
    startBreakeven = StBe//how much pips/points in gain to activate the breakeven function?
    PointsToKeep = PtK//ref //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
    //reset the breakevenLevel when no trade are on market
    IF NOT ONMARKET THEN
    breakevenLevel=0
    breakeven=0
    ENDIF
    //trail************
    
    // --- BUY SIDE ---
    //test if the price have moved favourably of "startBreakeven" points already
    IF LONGONMARKET AND high-POSITIONPRICE>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel= POSITIONPRICE+PointsToKeep*pipsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    SELL AT breakevenLevel STOP
    Breakeven=1
    ENDIF
    // --- SHORT SIDE ---
    IF SHORTONMARKET AND POSITIONPRICE-low>=startBreakeven*pipsize THEN
    //calculate the breakevenLevel
    breakevenLevel = POSITIONPRICE-PointsToKeep*pipsize
    ENDIF
    //place the new stop orders on market at breakevenLevel
    IF breakevenLevel>0 THEN
    EXITSHORT AT breakevenLevel STOP
    breakeven=1
    ENDIF
    
    //Pyramidage si Be + limitation de Entrytion************************
    NbrContrats=25
    if not onmarket and Pyra=1 then
    Pyra=0
    elsif onmarket and PYra=0 and  breakeven then //and breakevenLevelA>0
    Pyra=1
    elsif Pyra=1 and Entry>=NbrContrats or breakevenLevel<0 then
    Pyra=0
    endif
    
    SET STOP pLOSS SL
    //SET TARGET pPROFIT TP
    
    //graph pyra
    graph Entry
    //graph PtK
    //graph StBe
    //graph Entrytionprice
    //graph TP
    //graph (Entrytionprice-close)>0
    //graph Bot1
    //graph Bot2
    //graph breakeven
    //graph breakevenLevelA
    //graph breakevenLevelV>0
    If bot1 then
    elsif bot2 then
    elsif TP then
    endif
    
    Nicolas and Fantasio2020 thanked this post
    PRC1.png PRC1.png PRCV1.png PRCV1.png PRCV2.png PRCV2.png PRCV3.png PRCV3.png
    #89953 quote
    FREDNC
    Participant
    Senior

    @Nicolas

    Petite erreur dans la stratégie V3 (post précédent) la limitation de position, ne se faisait pas correctement. Il faut remplacer juste le code de “pyramidage” par celui ci-dessous:

    //Pyramidage si Be + limitation de Entrytion************************
    NbrEntry=25
    if not onmarket and Pyra=1 then
    Pyra=0
    elsif onmarket and PYra=0 and  breakeven and Entry<NbrEntry then
    Pyra=1
    elsif Entry>=NbrEntry or breakevenLevel<0 then
    Pyra=0
    endif

    Merci.

Viewing 14 posts - 16 through 29 (of 29 total)
  • You must be logged in to reply to this topic.

Demande de boucle pour pyramidage, trailing stop et breakeven


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
FREDNC @frednc Participant
Summary

This topic contains 28 replies,
has 2 voices, and was last updated by FREDNC
7 years, 1 month ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 01/17/2019
Status: Active
Attachments: 9 files
Logo Logo
Loading...