Code d'un stop suiveur
Forums › ProRealTime forum Français › Support ProOrder › Code d'un stop suiveur
- This topic has 5 replies, 3 voices, and was last updated 5 years ago by
Nicolas.
-
-
03/07/2020 at 3:22 PM #121439
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.
stop suiveur position courtes12345678910111213141516171819202122232425262728293031323334353637//-------------------------------------------------------------------------//ma strategiedefparam cumulateorders = falsedefparam preloadbars = 10000if not onmarket thensellshort 1 contract at marketendifsl = 140TS = 60set stop ploss sl//trailing stopif not onmarket thennewsl = 0endif//ts courtif shortonmarket thenif newsl = 0 and tradeprice - close > ts thennewsl = close + tselsif newsl >0 thennewsl =min(newsl,close + ts)endifendifexitshort at newsl stop03/07/2020 at 4:12 PM #12144103/07/2020 at 9:20 PM #12144903/09/2020 at 10:29 AM #12152503/09/2020 at 9:57 PM #121618En fait, j’ai trouvé sur le site le code qui va bien pour ce que je veux faire.
12345678910111213141516171819202122232425262728293031// trailing stoptrailingstop = 100//resetting variables when no trades are on marketif not onmarket thenMAXPRICE = 0MINPRICE = closepriceexit = 0endif//case SHORT orderif shortonmarket thenMINPRICE = MIN(MINPRICE,close) //saving the MFE (Maximum favorable excursion) of the current tradeif tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price levelendifendif//case LONG orderif longonmarket thenMAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current tradeif MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop thenpriceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price levelendifendif//exit on trailing stop price levelsif onmarket and priceexit>0 thenEXITSHORT AT priceexit STOPSELL AT priceexit STOPendifPar contre, j’aimerais bien savoir pourquoi mon code ne fonctionne pas !
03/11/2020 at 11:49 AM #121804 -
AuthorPosts
Find exclusive trading pro-tools on