Code d'un stop suiveur
- This topic has 5 replies, 3 voices, and was last updated 4 years ago by .
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
Similar topics:
Forums › ProRealTime forum Français › Support ProOrder › Code d'un stop suiveur
Bonjour,
Je veux utiliser pour une de mes stratégies un stop suiveur qui, dès que le trade soit positif de “n” points (ts dans la strategie), soit toujours à une distance “n” du cours de clôture et qu’il soit donc remis à jour à chaque fois que ce cours de cloture fait un plus haut pour les longs ou un plus bas pour les shorts.
Les codes que j’ai pu trouver sur le site ne correspondant pas à cette manière de fonctionner, j’ai réécrit un code. Il fonctionne pour les longs.
Mais le même code, modifié pour les shorts, ne fonctionne pas. Les trades sont cloturés de suite avec une perte correspondant au spread.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
//------------------------------------------------------------------------- //ma strategie defparam cumulateorders = false defparam preloadbars = 10000 if not onmarket then sellshort 1 contract at market endif sl = 140 TS = 60 set stop ploss sl //trailing stop if not onmarket then newsl = 0 endif //ts court if shortonmarket then if newsl = 0 and tradeprice - close > ts then newsl = close + ts elsif newsl >0 then newsl =min(newsl,close + ts) endif endif exitshort at newsl stop |
En fait, j’ai trouvé sur le site le code qui va bien pour ce que je veux faire.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
// trailing stop trailingstop = 100 //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 (Maximum favorable excursion) of the current trade if tradeprice(1)-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 //case LONG order if longonmarket then MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then priceexit = MAXPRICE-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 |
Par contre, j’aimerais bien savoir pourquoi mon code ne fonctionne pas !
Find exclusive trading pro-tools on