Trailing stop – aggiunta steps breakeven + steps incremento
Forums › ProRealTime forum Italiano › Supporto ProOrder › Trailing stop – aggiunta steps breakeven + steps incremento
- This topic has 2 replies, 2 voices, and was last updated 1 year ago by Simon.
-
-
01/22/2023 at 4:19 PM #207881
Buongiorno Roberto,
sarebbe possibile aggiungere al tuo codice di trailing stop un primo step che porta a breakeven (es. al raggiungimento di 30 punti di guadagno = sl a breakeven +1 punto, lasciando la variabile PointsToKeep )
successivamente solo al raggiungimento step2 (es. + 60 punti) inizia il trailing stop con step di n. punti (es. 20 punti)
successivamente al raggiungimento step3 (es. + 120 punti) modifica il trailing stop con step di n. punti (es. 10 punti)
Ti ringrazio anticipatamente per l’aiuto e per il grande lavoro per il forum.
//trailing stop function
IF NOT ONMARKET THEN
TrailingStart = 20 //20 trailing will start @trailinstart points profit
TrailingStep = 5 //5 trailing step to move the “stoploss”
Distance = 7 //7 pips Distance from caurrent price (if required by the broker)
PointsToKeep = 1 //1 pips to be gained when breakeven is set
//reset the stoploss value
newSL=0
ENDIF
IF (BarIndex – TradeIndex) >= 0 THEN //0
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND high-TradePrice(1)>=(TrailingStart*PipSize+PointsToKeep*PipSize) THEN
newSL = TradePrice(1)+TrailingStep*PipSize+PointsToKeep*PipSize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=TrailingStep*PipSize THEN
newSL = newSL+TrailingStep*PipSize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND TradePrice(1)-low>=(TrailingStart*PipSize+PointsToKeep*PipSize) THEN
newSL = TradePrice(1)-TrailingStep*PipSize+PointsToKeep*PipSize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=TrailingStep*PipSize THEN
newSL = newSL-TrailingStep*PipSize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
IF LongOnMarket THEN
IF (close + Distance) > newSL THEN
SELL AT newSL STOP
ELSIF (close – Distance) < newSL THEN
SELL AT newSL LIMIT
ELSE
SELL AT Market
ENDIF
ELSIF ShortOnmarket THEN
IF (close + Distance) < newSL THEN
EXITSHORT AT newSL STOP
ELSIF (close – Distance) > newSL THEN
EXITSHORT AT newSL LIMIT
ELSE
EXITSHORT AT Market
ENDIF
ENDIF
ENDIF
ENDIF
//**************************************
01/24/2023 at 11:14 AM #208065Eccolo (non l’ho provato):
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465//trailing stop functionIF NOT ONMARKET THENTrailingStart = 20 //20 trailing will start @trailinstart points profitTrailingStep = 5 //5 trailing step to move the "stoploss"Distance = 7 //7 pips Distance from caurrent price (if required by the broker)PointsToKeep = 1 //1 pips to be gained when breakeven is setnewSL = 0 //reset the stoploss valueStep2 = 0Step3 = 0ELSEPips = PositionPerf * PositionPrice / PipSizeIF (Pips >= 60) AND (Step2 = 0) THEN //15 punti di step dopo 60 di profittoTrailingStep = 15Step2 = 1ENDIFIF (Pips >= 120) AND (Step3 = 0) THEN //30 punti di step dopo 120 di profittoTrailingStep = 30Step3 = 1ENDIFENDIFIF (BarIndex - TradeIndex) >= 0 THEN //0//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND high-TradePrice(1)>=(TrailingStart*PipSize+PointsToKeep*PipSize) THENnewSL = TradePrice(1)+TrailingStep*PipSize+PointsToKeep*PipSizeENDIF//next movesIF newSL>0 AND close-newSL>=TrailingStep*PipSize THENnewSL = newSL+TrailingStep*PipSizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND TradePrice(1)-low>=(TrailingStart*PipSize+PointsToKeep*PipSize) THENnewSL = TradePrice(1)-TrailingStep*PipSize+PointsToKeep*PipSizeENDIF//next movesIF newSL>0 AND newSL-close>=TrailingStep*PipSize THENnewSL = newSL-TrailingStep*PipSizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENIF LongOnMarket THENIF (close + Distance) > newSL THENSELL AT newSL STOPELSIF (close - Distance) < newSL THENSELL AT newSL LIMITELSESELL AT MarketENDIFELSIF ShortOnmarket THENIF (close + Distance) < newSL THENEXITSHORT AT newSL STOPELSIF (close - Distance) > newSL THENEXITSHORT AT newSL LIMITELSEEXITSHORT AT MarketENDIFENDIFENDIFENDIF//**************************************01/25/2023 at 10:47 AM #208180Trailing stop – aggiunta steps breakeven + steps incremento1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768IF TS<>0 THEN//trailing stop functionIF NOT ONMARKET THENTrailingStart = TS //20 trailing will start @trailinstart points profitTrailingStep = 5 //5 trailing step to move the "stoploss"Distance = 50 //7 pips Distance from caurrent price (if required by the broker)PointsToKeep = 1 //1 pips to be gained when breakeven is setnewSL = 0 //reset the stoploss valueStep2 = stp2 //60Encr2 = Enc2 //15Step3 = Stp3 //90Encr3 = Enc3 //10ELSEPips = PositionPerf * PositionPrice / PipSizeIF (Pips >= Step2) THEN //15 punti di step dopo 60 di profittoTrailingStep = Encr2ENDIFIF (Pips >= step3) THEN //30 punti di step dopo 120 di profittoTrailingStep = Encr3ENDIFENDIFIF (BarIndex - TradeIndex) >= 0 THEN //0//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND high-TradePrice(1)>=(TrailingStart*PipSize+PointsToKeep*PipSize) THENnewSL = TradePrice(1)+TrailingStep*PipSize+PointsToKeep*PipSizeENDIF//next movesIF newSL>0 AND close-newSL>=TrailingStep*PipSize THENnewSL = newSL+TrailingStep*PipSizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND TradePrice(1)-low>=(TrailingStart*PipSize+PointsToKeep*PipSize) THENnewSL = TradePrice(1)-TrailingStep*PipSize+PointsToKeep*PipSizeENDIF//next movesIF newSL>0 AND newSL-close>=TrailingStep*PipSize THENnewSL = newSL-TrailingStep*PipSizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENIF LongOnMarket THENIF (close + Distance) > newSL THENSELL AT newSL STOPELSIF (close - Distance) < newSL THENSELL AT newSL LIMITELSESELL AT MarketENDIFELSIF ShortOnmarket THENIF (close + Distance) < newSL THENEXITSHORT AT newSL STOPELSIF (close - Distance) > newSL THENEXITSHORT AT newSL LIMITELSEEXITSHORT AT MarketENDIFENDIFENDIFENDIF//**************************************ENDIFGrazie Roberto,
gentilissimo!
Allego codice modificato con variabili, lo sto testando.
Buona giornata
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on