Demande de boucle pour pyramidage, trailing stop et breakeven
Forums › ProRealTime forum Français › Support ProOrder › Demande de boucle pour pyramidage, trailing stop et breakeven
- This topic has 28 replies, 2 voices, and was last updated 6 years ago by FREDNC.
-
-
01/17/2019 at 8:32 AM #88887
Bonjours à tous.
Après des heures recherche sur le site, de debugging et des dizaines d’essais infructueux, je passe la main….Si quelqu’un pouvait me coder ça, ce serait un grand merci. Il fort probable qu’il fasse tout reprendre à zéro pour obtenir un résultat correspondant à l’idée de départ mais je ne vois pas comment faire….
Je souhaite mettre en place un renforcement de position si le premier achat est arrivé à son niveau Trailing stop avec son Breakeven et le deuxième achat doit aussi avoir son Trailing stop avec son Breakeven
Le calcule du SL est basé sur Close-Donchian et Niveau de start du Trailing stop c’est abs(SL /2 ).
Le trailing stop est sur une base d’un de code @Nicolas que j’ai essayé d’adapter sans succès.
Soit je double mes positions, soit quand les conditions du renforcement deviennent valides, je coupe ma premier position au niveau d’entrée.
Voici le code qui me semble se rapprocher le plus du but. J’ai supprimé tous mes filtres pour simplifier la compréhension se qui explique le nombre de positions et les résultats très médiocre. Dans tous les cas les, la condition de Breakeven de la première position n’est pas respecté pour Pyramidé. La limite de 2 positions non plus. En rajoutant les conditions « onmarket » ou « not onmarket » on crée des conflits, J’ai même eu des résultats que je n’explique même pas….lol Bref, Je tourne en rond. Je pense qu’il faut une boucle, mais je ne sais pas faire HELP !
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220//Dax30 M1// Définition des paramètres du codeDEFPARAM CumulateOrders = true //false // Cumul des positions ACTIVEES***Voir option Pyramidage ***DEFPARAM Preloadbars = 20000//Nbr de contrats*******************N=2Spread=1//Pyramidage si Be + limitation de position************************//**Nonbre de Positions autorisées**NbrPosi=2if Pyra1=0 and Pyra2=0 and breakeven1=0 and breakeven2=0 and (abs(COUNTOFPOSITION)< NbrPosi) thenPyra1=1pyra2=0elsif Pyra1 and breakeven1>0 or (abs(COUNTOFPOSITION)>0) then//pyra2=1Pyra1=0elsif Pyra2 and breakeven2>0 or (abs(COUNTOFPOSITION)>NbrPosi) thenPyra1=0pyra2=0elsebreakeven1=0breakeven2=0endif//elsif Pyra1=0 and Pyra2=0 and breakeven1=0 and breakeven2=0 and (abs(COUNTOFPOSITION)< NbrPosi) then//Pyra1=1//pyra2=0//elsif Pyra1 and breakeven1>0 then////Pyra1=0//pyra2=1//elsif Pyra1=0 and Pyra2=0 and Breakeven2=0 and (abs(COUNTOFPOSITION)< NbrPosi) then//Pyra1=1//pyra2=0//endif//elsif Pyra1 and breakevenLevel1>0 and (abs(COUNTOFPOSITION)<NbrPosi) then////Pyra1=0//pyra2=1//elsif Pyra2 and breakevenLeve2 =0 and (abs(COUNTOFPOSITION)<NbrPosi) then//Pyra1=0//pyra2=1//elsif Pyra2 and breakevenLeve2>0 or (abs(COUNTOFPOSITION)>NbrPosi) then//Pyra1=0//pyra2=0//endif//elsif Pyra2 and breakevenLeve2>0 and (abs(COUNTOFPOSITION)>NbrPosi) then//Pyra1=0//pyra2=0//endif//Canal Donchian************************************DC=15//CDH=Highest[DC](high)CDB=Lowest[DC](low)//TDIlengthRSI = 13lengthband = 34lengthrsipl = 2lengthtradesl = 7r = rsi[lengthrsi](close)ma = average[lengthband](r)offs = (1.6185 * std[lengthband](r))up = ma+offsdn = ma-offsmid = (up+dn)/2TDIVert = average[lengthrsipl](r)TDIRouge = average[lengthtradesl](r)// "CROSS 1"******IF TDIVert crosses over TDIRouge and TDIVert > mid THENCROSSTa = 1elsif TDIVert crosses under TDIRouge and TDIVert < mid THENCROSSTb = 1elseCROSSTa=0CROSSTb=0ENDIF// "CROSS 2"*****************************IF TDIVert crosses over up THENCROSST2A = 1elsif TDIVert crosses under dn THENCROSST2V = -1elseCROSST2A=0CROSST2V=0ENDIF//Position 1***********************************************************************************************//Long1If Pyra1 and CROSSTa thenBUY N CONTRACT AT MARKETSL1 = abs (close-CDB)+(SPREAD/2)Bot1=3 //Pour graph la variable. Inutine quand tous fonctionneelseBot1=0 //Pour graph la variable. Inutine quand tous fonctionneendif//Short1if Pyra1 and CROSSTb thenSELLSHORT N CONTRACT AT MARKETSL1 = abs (CDH-close)+(SPREAD/2)Bot1=3 //Pour graph la variable. Inutine quand tous fonctionneelseBot1=0 //Pour graph la variable. Inutine quand tous fonctionneENDIF//Trail 1 ************************startBreakeven1 = SL1/2 //how much pips/points in gain to activate the breakeven function?PointsToKeep1= 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)//reset the breakevenLevel1 when no trade are on marketIF NOT ONMARKET THENbreakevenLeveL1=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven1" points alreadyIF LONGONMARKET and close-tradeprice(1)>=startBreakeven1*pipsize THEN//calculate the breakevenLevel1breakevenLeveL1 = tradeprice(1)+PointsToKeep1*pipsizeENDIF//place the new stop orders on market at breakevenLevel1IF breakevenLeveL1>0 THENSELL AT breakevenLeveL1 STOPBreakeven1=2//-----------------ATTENTION RAJOUTE DANS LE CODE------------------------------------SL1=0//------------------------ATTENTION RAJOUTE DANS LE CODE------------------------------------ENDIF// --- SHORT SIDE ---IF SHORTONMARKET and tradeprice(1)-close>startBreakeven1*pipsize THEN//calculate the breakevenLevel1breakevenLeveL1 = tradeprice(1)-PointsToKeep1*pipsizeENDIF//place the new stop orders on market at breakevenLevel1IF breakevenLeveL1>0 THENEXITSHORT AT breakevenLeveL1 STOPBreakeven1=2//-----------------ATTENTION RAJOUTE DANS LE CODE------------------------------------SL1=0//------------------------ATTENTION RAJOUTE DANS LE CODE------------------------------------ENDIF//Position 2***************************************************************************************************//Long2If Pyra2 and CROSST2A thenBUY N CONTRACT AT MARKETSL2 = abs (close-CDB)+(SPREAD/2)TP2 = SL2Bot2=5//Pour graph la variable. Inutine quand tous fonctionneelseBot2=0 //Pour graph la variable. Inutine quand tous fonctionneendif//Short2if Pyra2 and CROSST2V then//or CROSS1=-1 or CROSS2=-1SELLSHORT N CONTRACT AT MARKETSL2 = abs (CDH-close)+(SPREAD/2)TP2 = SL2Bot2=5//Pour graph la variable. Inutine quand tous fonctionneelseBot2=0 //Pour graph la variable. Inutine quand tous fonctionneendif//Trail 2 **********************startBreakeven2= SL2/2 //how much pips/points in gain to activate the breakeven function?PointsToKeep2 = 1 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)//reset the breakevenLevel1 when no trade are on marketIF NOT ONMARKET THENbreakevenLeveL2=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven2" points alreadyIF LONGONMARKET and close-tradeprice(1)>=startBreakeven2*pipsize THEN//calculate the breakevenLevel1breakevenLeveL2 = tradeprice(1)+PointsToKeep2*pipsizeENDIF//place the new stop orders on market at breakevenLevel1IF breakevenLeveL2>0 THENSELL AT breakevenLeveL2 STOPBreakeven2=2.5//-----------------ATTENTION RAJOUTE DANS LE CODE------------------------------------SL2=0//------------------------ATTENTION RAJOUTE DANS LE CODE------------------------------------//bot2=0ENDIF// --- SHORT SIDE ---IF SHORTONMARKET and tradeprice(1)-close>startBreakeven2*pipsize THEN//calculate the breakevenLevel1breakevenLeveL2 = tradeprice(1)-PointsToKeep2*pipsizeENDIF//place the new stop orders on market at breakevenLevel1IF breakevenLeveL2>0 THENEXITSHORT AT breakevenLeveL2 STOPBreakeven2=2.5//-----------------ATTENTION RAJOUTE DANS LE CODE------------------------------------SL2=0//------------------------ATTENTION RAJOUTE DANS LE CODE------------------------------------//bot2=0ENDIF//Stops et objectifsIf SL2=0 and SL1 > 0 ThenSL=SL1elsif Sl1=0 and SL2 > 0 thenSL=SL2endifSET STOP pLOSS SLSET TARGET pPROFIT TP2graph Breakeven1graph Breakeven2graph pyra1graph pyra2//graph SL1//graph SL2Graph Bot1graph Bot201/17/2019 at 5:22 PM #8897701/17/2019 at 11:15 PM #89003Merci, pour ta réponse Nicolas. Effectivement, à partir du moment ou une deuxième position est prise Il faut raisonner et terme de prix moyen pondéré. Je vais donc opter pour un seul trailing stop basé sur le PRU. Les heures de debugging ont fini pat altérer mon résonnement, no comment 😉 …..
Pourrais tu me trouver tu une solution pour gérer le renforcement (ou pyramidage) et quel type de trailing stop serait le plus adapté ? l’idée c’est : Si, Breakaven du prix moyen pondéré des positions en cours (que se soit une ou X positions) donne la possibilité d’ouvrir une position supplémentaire . Par avance merci.
01/18/2019 at 5:32 AM #89013Voilà ci-dessous ce que j’utilise actuellement. Le Trailing c’est le tien, le système de pyramidage, je l’ai écrit avec les posts que j’ai trouvé sur le sujet.
Peut-on améliorer ce concept ?
Comment le trailing va t-il se comporter sur les entrée suivantes compte tenue qu’actuellement c’est (TP/2) de la première position qui active le trail ?
A chaque nouvelles positions, nouveau TP et donc la variable “startBreakeven1” de la précédente devrait être recalculé et on perd le BE précédemment acquis … En cas de retournement et si la dernière position n’a pas pu activé son breakeven on peut redescendre au SL de la première position…
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051//Pyramidage si Be + limitation de position************************//**Nonbre de Position autorisé**NbrPosi=5If onmarket And (close>=startBreakeven1) and (abs(COUNTOFPOSITION)<NbrPosi) then//Pyra=1elsif not onmarket thenPyra=1elsePyra=0endif//Canal Donchian************************************DC=15//A optimiser de temps en tempsCDH=Highest[DC](high)CDB=Lowest[DC](low)If Pyra and C1 thenSL= abs (close-CDB)+(SPREAD/2)TP= SLBUY N CONTRACTS AT MARKETENDIF//Trail *****************************************************************startBreakeven1 = TP/2 //how much pips/points in gain to activate the breakeven function?PointsToKeep1= 1 //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 marketIF NOT ONMARKET THENbreakevenLevel=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven1" points alreadyIF LONGONMARKET and close-tradeprice(1)>=startBreakeven1*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)+PointsToKeep1*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPENDIF// --- SHORT SIDE ---IF SHORTONMARKET and tradeprice(1)-close>startBreakeven1*pipsize THEN//calculate the breakevenLevelbreakevenLevel = tradeprice(1)-PointsToKeep1*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENEXITSHORT AT breakevenLevel STOPENDIF01/18/2019 at 9:46 AM #89018A chaque nouvelles positions, nouveau TP et donc la variable “startBreakeven1” de la précédente devrait être recalculé et on perd le BE précédemment acquis … En cas de retournement et si la dernière position n’a pas pu activé son breakeven on peut redescendre au SL de la première position…
Ton raisonnement est correct. Peu importe où tu placeras ton SELL ou ton EXITSHORT, l’ensemble des positions sera liquidé. Je te conseillerai d’utiliser POSITIONPRICE qui est le prix moyen de tous les ordres ouverts au marché. Par exemple, dans le cas d’une série d’ordres LONG, si tu places le stop au dessus de POSITIONPRICE, tu seras en gain global sur ton panier même si certains ordres seront perdants.
1 user thanked author for this post.
01/19/2019 at 8:57 AM #89093Bonjour Nicolas,
J’ai donc fait les modifications au niveau du code du “traling stop” en remplacent traderprice par POSITIONPRICE. Ça fonctionne bien, j’ai graphé les variables tous est OK. Comme prévue, la deuxième position est autorisé uniquement pendant la durée du BE de la première position et si moins de x positions en cours.
Ça ne lui laisser pas assez de temps, donc j’ai du j’ai dût redescendre mon niveau d’entré du BE et gardé le strict minimum afin que le signal de la deuxième position arrive à se caler pendant l’espace temps du BE de la première.
Ca pourrait être rentable dans l’état, mais dans les faits on se retrouve à trailer le panier avec les paramètres de la première position et ce n’est pas rentable…
J’ai donc imaginer une astuce. A l’aide d’un deuxième Trailling “stop 3 bars trailing stop Williams” qui trail le “point to keept” . A l’aide de quelque ligne de code, on indique a ton trailling stop quelle “point to keep” à utiliser en fonction du nombre de position encours. Le résultat et très satisfaisant. (Au passage, merci à l’auteur du “stop 3 bars trailing stop Williams”)
Voici l’astuce pour “point to keep”
If abs(COUNTOFPOSITION)<2 then
PtK=TP/4
elsif abs(COUNTOFPOSITION)>1 then
PtK=ref//variable de “stop 3 bars trailing stop Williams”
EndifEt pour mémo voici le : “3 bars trailing stop Williams”
count=1
i=0
j=i+1
tot=0
while count<3 do// optimisable de temps en temps entre 2 et 10 pas de 1 ,
tot=tot+1
if (low[j]>=low[i]) and (high[j]<=high[i]) then
//inside bar
j=j+1
else
count=count+1
i=i+1
J=i+1
endif
wend
basso=lowest[tot](low)
alto=highest[tot](high)if close>alto[1] then
ref=basso
endif
if close<basso[1] then
ref=alto
endif01/19/2019 at 9:37 AM #8909601/20/2019 at 5:03 PM #89170Bon finalement après quelques heures de debugging et le rajout du PPJ et 2 filtres perso, la stratégie est rentable. J’ai résolu de nombreux bogs. Le principe du renforcement si BE est validé. La sortie se fait bien sur niveau BE de la première position. En général, le gain de la multiplication des positions est intéressant. Seul la dernière position de la série est parfois faiblement en perte et toutes les autre sont positives.
Pour autant il me reste 2 bogs que je n’explique pas…
-1er bog: Impossible de “grapher” le Bot1. J’ai tester, il fait bien des positions. Si conditions= buy et bot1=3 ne donne rien en “graph”.
En revanche, pour le “Bot2”, Si conditions= buy et bot2=5 tout fonctionne , il est bien “grapher”…..bizarre.
-2eme bog : Le BE de la première position initialise la variable “Pyra” pour autoriser le renforcement ou pyramidage. Ca fonctionne dans 90% des cas mais de temps en temps au sort sur le SL (de la première positions) et ce avec l’ensemble des positions, (ça fait mal voir le: 22 aout). Ce comportement ne devrait pas se produire car si “Pyra=1” ça veut dire que la première position est déjà à BE donc on doit sortir au BE avec ou sans renforcement. Je ne comprends pas….
@nicolas et les autres pouvez-vous tester et me faire part de vos suggestions ?Je n’ai pas réussi à importer le ITF donc voici le code final à appliquer sur Dax (1euro), M1 , 100 000 bouigie , spread 1
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215// Définition des paramètres du codeDEFPARAM CumulateOrders = true //false // Cumul des positions 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 position avant l'heure spécifiéenoEntryBeforeTime = 091500//080000//091500timeEnterBefore = time >= noEntryBeforeTime//Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 170000//2130000//170000timeEnterAfter = time < noEntryAfterTime//Jour de trading du lundi au vendredi inclusif DayOfWeek <= 5 thenTradeday=1elsif tradeday=1 and DayOfWeek > 5 thenTradeDay=0endifIF ONMARKET and (TIME>=171500 and close-tradeprice>1) THENSELL AT MARKETEXITSHORT AT MARKETENDIFSpread=1//Taille en Pips*******************TMini=9//7TMaxi=13//12TailleA = (abs(close-CDB))TailleV = (abs(CDH-close))PC=9//14// ***********************************Optimisable entre 10% et 40% admit Entre position/objectif/MM34If Abs (close[1]-close) < abs(tailleA*PC/100) thenDist=1elsif Abs (close[1]-close) < abs(TailleV*PC/100) thenDist=1elseDist=0endif//PPJPPJ= (DHigh(1) + DLow(1) + DClose(1))/3//Canal Donchian************************************DC=15//CDH=Highest[DC](high)CDB=Lowest[DC](low)//TDIlengthRSI = 13lengthband = 34lengthrsipl = 2lengthtradesl = 7r = rsi[lengthrsi](close)ma = average[lengthband](r)offs = (1.6185 * std[lengthband](r))up = ma+offsdn = ma-offsmid = (up+dn)/2TDIVert = 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 THENCROSSTa = 1elsif 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 THENCROSSTb = 1elseCROSSTa=0CROSSTb=0ENDIF// "CROSS 2"*****************************IF onmarket and r[1]<r or TDIVert[1]< TDIVert or TDIVert crosses over TDIRouge THEN//longonmarket andCROSST2A = 1elsif onmarket and r[1]<r or TDIVert[1]< TDIVert or TDIVert crosses under TDIRouge and TDIVert THEN//shortonmarket andCROSST2V = 1elseCROSST2A=0CROSST2V=0ENDIF//Bot1 ***********************************************************************************************//Long1If CROSSTa and TDIVert crosses over TDIRouge thenBot1=3 //Pour graph la variable. Inutine quand tous fonctionneBUY N CONTRACT AT MARKETSL = abs (close-CDB)+(SPREAD/2)TP = abs (close-CDB)+(SPREAD/2)endif//Short1if CROSSTb and TDIVert crosses under TDIRouge thenBot1=3 //Pour graph la variable. Inutine quand tous fonctionneSELLSHORT N CONTRACT AT MARKETSL = abs (CDH-close)+(SPREAD/2)TP = abs (CDH-close)+(SPREAD/2)ENDIFif not onmarket then//Pour graph la variable. Inutine quand tous fonctionneBot1=0endif//Bot2***************************************************************************************************//Long2If PyraA and CROSST2A thenBot2=5//Pour graph la variable. Inutine quand tous fonctionneBUY N CONTRACT AT MARKETSL = abs (close-CDB)+(SPREAD/2)endif//Short2if PyraV and CROSST2V then//or CROSS1=-1 or CROSS2=-1Bot2=5//Pour graph la variable. Inutine quand tous fonctionneSELLSHORT N CONTRACT AT MARKETSL = abs (CDH-close)+(SPREAD/2)endifif not onmarket then//Pour graph la variable. Inutine quand tous fonctionneBot2=0endif//3 bars trailing stop Williamscount=1i=0j=i+1tot=0while count<3 do//optimisable de tempts en tempstot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendif//Bascule "point to keep"If abs(COUNTOFPOSITION)<=1 thenStBe=tp/4PtK=TP/8elsif abs(COUNTOFPOSITION)>1 thenPtK=refendif//Trail************************************************************************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 marketIF NOT ONMARKET THENbreakevenLevelA=0breakevenLevelV=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-POSITIONPRICE>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevelA = POSITIONPRICE+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevelA>0 THENSELL AT breakevenLevelA STOPENDIF// --- SHORT SIDE ---IF SHORTONMARKET AND POSITIONPRICE-close>startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevelV = POSITIONPRICE-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevelV>0 THENEXITSHORT AT breakevenLevelV STOPENDIF//Pyramidage si Be + limitation de position************************NbrPosi=5if not onmarket thenPyraA=0Pyrav=0TP=0elsif abs(COUNTOFPOSITION)>NbrPosi thenPyraA=0PyraV=0TP=0endifIf (close-tradeprice(1))>0 and longonmarket then//PyraA=1elsif (tradeprice(1)-close)>0 and shortonmarket then//PyraV=1endifSET STOP pLOSS SL//SET TARGET pPROFIT TPgraph pyraAgraph pyraVgraph TP//graph (positionprice-close)>0graph Bot1graph Bot2//graph breakevenLevelA>0//graph breakevenLevelV>001/21/2019 at 8:03 AM #89196Voilà la dernière, l’autre était vraiment boguer , Pour autant de positions de sont pas parfaites. @Nicolas ou quelqu’un d’autre pourrais y jeter un œil et m’arranger ça. Par avance merci. voici le code:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227// Définition des paramètres du code: Dax M1 , 100 000 bougies, 1 de spread// Définition des paramètres du codeDEFPARAM CumulateOrders = true //false // Cumul des positions 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 position avant l'heure spécifiéenoEntryBeforeTime = 091500//080000//091500timeEnterBefore = time >= noEntryBeforeTime//Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 170000//2130000//170000timeEnterAfter = time < noEntryAfterTime//Jour de trading du lundi au vendredi inclusif DayOfWeek <= 5 thenTradeday=1elsif tradeday=1 and DayOfWeek > 5 thenTradeDay=0endifIF ONMARKET and (TIME>=171500 and close-tradeprice>1) THENSELL AT MARKETEXITSHORT AT MARKETENDIFSpread=1//Pyramidage si Be + limitation de position************************NbrPosi=10if not onmarket thenPyraA=0Pyrav=0TP=0elsif abs(COUNTOFPOSITION)>=NbrPosi thenPyraA=0PyraV=0TP=0endif//LongIf close > breakevenLevelA and longonmarket and abs(COUNTOFPOSITION)<=NbrPosi then//PyraA=1elsif close-positionprice<0 then//SELL AT close-positionprice<0 STOPPyraA=0endif//Shortif close < breakevenLevelV and shortonmarket and abs(COUNTOFPOSITION)<=NbrPosi then//breakevenLevelV>0PyraV=1elsif positionprice-close>0 then //EXITSHORT AT positionprice-close>0 STOPPyraV=0endif//Taille en Pips*******************TMini=9//Sert à la limite de 6 pips Mini chez IGTMaxi=13//sert à limité les tailles de positions et SLTailleA = (abs(close-CDB))TailleV = (abs(CDH-close))PC=9//14// Filtres***********************************Optimisable entre 10% et 40% admit Entre position/objectif/MM34If Abs (close[1]-close) < abs(tailleA*PC/100) thenDist=1elsif Abs (close[1]-close) < abs(TailleV*PC/100) thenDist=1elseDist=0endif//PPJPPJ= (DHigh(1) + DLow(1) + DClose(1))/3//Canal Donchian************************************DC=15//CDH=Highest[DC](high)CDB=Lowest[DC](low)//TDIlengthRSI = 13lengthband = 34lengthrsipl = 2lengthtradesl = 7r = rsi[lengthrsi](close)ma = average[lengthband](r)offs = (1.6185 * std[lengthband](r))up = ma+offsdn = ma-offsmid = (up+dn)/2TDIVert = average[lengthrsipl](r)TDIRouge = average[lengthtradesl](r)// "CROSS 1"******IF not onmarket and TMini<abs((CDB[0]-Close)+(SPREAD/2)) and TMaxi>abs((CDB[0]-close)+(SPREAD/2)) and Dist and close > Ppj and Tradeday AND timeEnterBefore AND timeEnterAfter and TDIVert > mid and TDIRouge > mid and mid > 5 THENCROSSTa = 1elsif not onmarket and TMini<abs((close-CDH[0])+(SPREAD/2)) and TMaxi>abs((close-CDH[0]+(SPREAD/2)))and Dist and close < Ppj and Tradeday and timeEnterBefore AND timeEnterAfter and TDIVert < mid and TDIRouge < mid and mid < 50 THENCROSSTb = 1elseCROSSTa=0CROSSTb=0ENDIF// "CROSS 2"*****************************IF longonmarket and r[1]<r or TDIVert[1]< TDIVert or TDIVert crosses over TDIRouge THEN//CROSST2A = 1elsif shortonmarket and r[1]>r or TDIVert[1]> TDIVert or TDIVert crosses under TDIRouge and TDIVert THEN//CROSST2V = 1elseCROSST2A=0CROSST2V=0ENDIFbot1=0//Reset Bot pour graph//Bot1 ***********************************************************************************************//Long1If CROSSTa and TDIVert crosses over TDIRouge thenSL = abs (close-CDB)+(SPREAD/2)TP = abs (close-CDB)+(SPREAD/2)BUY N CONTRACT AT MARKETBot1=3 //Pour graph la variable. Inutine quand tous fonctionneendif//Short1if CROSSTb and TDIVert crosses under TDIRouge thenSL = abs (CDH-close)+(SPREAD/2)TP = abs (CDH-close)+(SPREAD/2)SELLSHORT N CONTRACT AT MARKETBot1=3 //Pour graph la variable. Inutine quand tous fonctionneENDIFBot2=0//Reset Bot pour graph//Bot2***************************************************************************************************//Long2If PyraA and CROSST2A thenSL = abs (close-CDB)+(SPREAD/2)BUY N CONTRACT AT MARKETBot2=5//Pour graph la variable. Inutine quand tous fonctionneendif//Short2if PyraV and CROSST2V then//or CROSS1=-1 or CROSS2=-1SL = abs (CDH-close)+(SPREAD/2)SELLSHORT N CONTRACT AT MARKETBot2=5//Pour graph la variable. Inutine quand tous fonctionneendif//3 bars trailing stop Williamscount=1i=0j=i+1tot=0while count<3 do//4 optimisable de tempts en temps , original =4tot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendif//Trail************************************************************************//Bascule "point to keep"If abs(COUNTOFPOSITION)<=1 thenStBe=tp/4PtK=refelsif abs(COUNTOFPOSITION)>1 thenStBe=tp/2PtK=refendifstartBreakeven = 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 marketIF NOT ONMARKET THENbreakevenLevelA=0breakevenLevelV=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-tradeprice(1)>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevelA = positionprice+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevelA>0 THENSELL AT breakevenLevelA STOPENDIF// --- SHORT SIDE ---IF SHORTONMARKET AND tradeprice(1)-close>startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevelV = positionprice-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevelV>0 THENEXITSHORT AT breakevenLevelV STOPENDIFSET STOP pLOSS SL//SET TARGET pPROFIT TPgraph pyraAgraph pyraV//graph TP//graph (positionprice-close)>0graph Bot1graph Bot2//graph breakevenLevelA>0//graph breakevenLevelV>001/21/2019 at 11:21 AM #89225Désolé, mais qu’est ce qui n’est “pas parfait” et que faut-il “arranger” ? Difficile pour moi de m’investir complètement dans les projets de chacun sur le forum, donc il faut être très explicite pour me mettre sur la voie. Merci.
01/22/2019 at 8:03 AM #89303Bonjour @Nicolas,
Effectivement j’aurais dût être plus précis.
Ci dessous tu trouveras le new updabe du code à cette heure, j’ai encore des soucis et je t’ai fais un screen shot pour plus de compréhension .
C’est un cycle. On commence par faire un achat avec avec le bote1. Si breakeven+”Point to keep”+ conditions du bot2 on achète. Puis si breakeven+”Point to keep” du panier + conditions du bot2 on achète encore et ainsi de suite
La fin cycle c’est soit: (mono position) sortie à SL ou sortie à breakeven+”Point to keep” . Ou bien, si (Multi-positions) sortie à breakeven+”Point to keep” (du panier).
Dans le screen shot (14/11/2018 à 13h18):
1)On voit la position 1 et la 2, rien à dire jusque là… Concernant la position 3 j’ai un doute sur le fait que le panier soit à breakeven+”Point to keep” et la 4 et carrément en négative.
2)Dans le graph (des variables) le cycle n’est pas respecté non plus. (Pour info j’ai numéroté sur le graph Bot1=1 , Bot2=2, Pyra=3)
Le cycle devrait être celà: On commence toujours par le bot1 , ensuite si BE Pyra monte et autorise une position supplémentaire puis le bot2 et quand Pyra retombe c’est la fin du cycle .
Le seul moyen de refaire une position c’est de repartir du début de cycle. Dans ce cas , on voit clairement que Pyra retombe à zero mais d’autre positions du bot2 sont faites alors que Bot1 est inactif.
Voilà, peut tu me solutionner cela,
New Update du 22/1/2019123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241// Définition des paramètres du code*************** Dax M1, 100 000 bougies, spread 1******************DEFPARAM CumulateOrders = true //false // Cumul des positions 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 position avant l'heure spécifiéenoEntryBeforeTime = 091500//080000//091500timeEnterBefore = time >= noEntryBeforeTime//Empêche le système de placer des ordres pour entrer sur le marché ou augmenter la taille d'une position après l'heure spécifiéenoEntryAfterTime = 170000//2130000//170000timeEnterAfter = time < noEntryAfterTime//Jour de trading du lundi au vendredi inclusif DayOfWeek <= 5 thenTradeday=1elsif tradeday=1 and DayOfWeek > 5 thenTradeDay=0endifIF ONMARKET and (TIME>=171500 and close-tradeprice>1) THENSELL AT MARKETEXITSHORT AT MARKETENDIFSpread=1//Taille en Pips*******************TMini=9//7TMaxi=13//12TailleA = (abs(close-CDB))TailleV = (abs(CDH-close))PC=9//14// ***********************************Optimisable entre 10% et 40% admit Entre position/objectif/MM34If Abs (close[1]-close) < abs(tailleA*PC/100) thenDist=1elsif Abs (close[1]-close) < abs(TailleV*PC/100) thenDist=1elseDist=0endif//PPJPPJ= (DHigh(1) + DLow(1) + DClose(1))/3//Canal Donchian************************************DC=15//CDH=Highest[DC](high)CDB=Lowest[DC](low)//TDIlengthRSI = 13lengthband = 34lengthrsipl = 2lengthtradesl = 7r = rsi[lengthrsi](close)ma = average[lengthband](r)offs = (1.6185 * std[lengthband](r))up = ma+offsdn = ma-offsmid = (up+dn)/2TDIVert = 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 THENCROSSTa = 1elsif 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 THENCROSSTb = 1elseCROSSTa=0CROSSTb=0ENDIF// "CROSS 2"*****************************IF onmarket and r[1]<r or TDIVert[1]< TDIVert or TDIVert crosses over TDIRouge THEN//longonmarket andCROSST2A = 1elsif onmarket and r[1]>r or TDIVert[1]> TDIVert or TDIVert crosses under TDIRouge and TDIVert THEN //shortonmarket andCROSST2V = 1elseCROSST2A=0CROSST2V=0ENDIF//Bot1 ***********************************************************************************************//Long1Bot1=0If CROSSTa and TDIVert crosses over TDIRouge thenBot1=3 //Pour graph la variable. Inutine quand tous fonctionneBUY N CONTRACT AT MARKETSL = abs (close-CDB)+(SPREAD/2)TP = abs (close-CDB)+(SPREAD/2)endif//Short1if CROSSTb and TDIVert crosses under TDIRouge thenBot1=3 //Pour graph la variable. Inutine quand tous fonctionneSELLSHORT N CONTRACT AT MARKETSL = abs (CDH-close)+(SPREAD/2)TP = abs (CDH-close)+(SPREAD/2)ENDIF//Bot2***************************************************************************************************//Long2Bot2=0If PyraA and CROSST2A thenBot2=5//Pour graph la variable. Inutine quand tous fonctionneBUY N CONTRACT AT MARKETSL = abs (close-CDB)+(SPREAD/2)endif//Short2if PyraV and CROSST2V then//or CROSS1=-1 or CROSS2=-1Bot2=5//Pour graph la variable. Inutine quand tous fonctionneSELLSHORT N CONTRACT AT MARKETSL = abs (CDH-close)+(SPREAD/2)endif//3 bars trailing stop Williamscount=1i=0j=i+1tot=0while count<3 do//4 optimisable de tempts en temps , original =4tot=tot+1if (low[j]>=low[i]) and (high[j]<=high[i]) then//inside barj=j+1elsecount=count+1i=i+1J=i+1endifwendbasso=lowest[tot](low)alto=highest[tot](high)if close>alto[1] thenref=bassoendifif close<basso[1] thenref=altoendif//Trail Bascule "point to keep"************************************************************************//Mono positionIf abs(COUNTOFPOSITION) thenStBe=tp/4PtK=TP/3//Muti-poditionselsif abs(COUNTOFPOSITION)>1 and POSITIONPRICE > breakevenLevelA thenStBe=tp/4PtK=refendif//******************************************************************************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 marketIF NOT ONMARKET THENbreakevenLevelA=0breakevenLevelV=0breakeven=0ENDIF// --- BUY SIDE ---//test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET AND close-POSITIONPRICE>=startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevelA= POSITIONPRICE+PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevelA>0 THENSELL AT breakevenLevelA STOPBreakeven=1ENDIF// --- SHORT SIDE ---IF SHORTONMARKET AND POSITIONPRICE-close>startBreakeven*pipsize THEN//calculate the breakevenLevelbreakevenLevelV = POSITIONPRICE-PointsToKeep*pipsizeENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevelV>0 THENEXITSHORT AT breakevenLevelV STOPbreakeven=1ENDIF//Pyramidage si Be + limitation de position************************NbrPosi=50if not onmarket thenPyraA=0PyraV=0TP=0elsif abs(COUNTOFPOSITION)>NbrPosi thenPyraA=0PyraV=0endif//longif longonmarket and breakeven then //and breakevenLevelA>0PyraA=1endifIf longonmarket and POSITIONPRICE < breakevenLevelA or abs(COUNTOFPOSITION)>NbrPosi then//SELL AT breakevenLevelA STOPbreakevenLevelA=0breakeven=0PyraA=0endif//shortif shortonmarket and breakeven then//PyraV=1endifif shortonmarket and POSITIONPRICE > breakevenLevelV or abs(COUNTOFPOSITION)>NbrPosi then//EXITSHORT AT breakevenLevelV STOPbreakevenLevelV=0breakeven=0PyraV=0endifSET STOP pLOSS SL//SET TARGET pPROFIT TPgraph pyraAgraph pyraV//graph positionprice//graph TP//graph (positionprice-close)>0graph Bot1graph Bot2//graph breakevenLevelA>0//graph breakevenLevelV>0If bot1 thenelsif bot2 thenelsif ref thenendifNew update101/22/2019 at 5:05 PM #89351Pas été dans le détail mais il me semble qu’il y a une erreur à la ligne 151, en effet cette ligne retournera vrai dés que countofposition sera supérieure à 0:
1If abs(COUNTOFPOSITION) thenpar conséquent le eslif après ne sera jamais testé. Je pense que tu devrais réécrire l’ensemble comme ceci:
123456789//Mono positionIf abs(COUNTOFPOSITION)=1 thenStBe=tp/4PtK=TP/3//Muti-poditionselsif abs(COUNTOFPOSITION)>1 and POSITIONPRICE > breakevenLevelA thenStBe=tp/4PtK=refendif01/23/2019 at 3:27 AM #89385Merci, j’ai corrigé,
mais on est pas encore rendu ….
Encore plein de bogs, c’est dommage car l’idée est rentable (Screen shot joint), mais c’est il y a beaucoup de pièges quand il s’agit de l’écriture du code.
Du reste, j’aime pas l’utilisation “COUNTOFPOSITION” qui compte le nombre de contrats et non le nombre d’entrées. Quand on change le nombre de contrats à l’achat(valeur N) , il faut revoir tout les valeurs de “COUNTOFPOSITION” dans l’intégralité du code…. Existe t-il une fonction qui compte les entrées plutôt que les contrats ?
01/23/2019 at 10:52 AM #89410Existe t-il une fonction qui compte les entrées plutôt que les contrats ?
tu peux facilement incrémenter une variable dés que tu rentres en position et la reset quand tu n’es plus au marché.
01/23/2019 at 12:51 PM #89425Bonjour et merci pour ta réponse.
Si je comprends bien tu pense à une boucle dans lequel on comptabilise le nombre de 1 envoyé au moment de l’entrée en position des Bot 1 et Bot2 ?
Je ne suis pas un expert en boucle donc pourrais tu me corriger stp ?
J’ai écris cela mais quand je graph Nbr j’ai :0
1234567891011If not onmarket thenBot1=0Bot2=0Nbr=0endiffor i= 1 to 50if bot1=1 thenelsif bot2=1 thenNbr=i =i+1endifnext -
AuthorPosts
Find exclusive trading pro-tools on