Need a trailing stop loss that moves more dynamic
Forums › ProRealTime English forum › ProOrder support › Need a trailing stop loss that moves more dynamic
- This topic has 18 replies, 4 voices, and was last updated 6 years ago by tob107.
-
-
02/22/2018 at 1:06 PM #63514
When i place the usual SL instruction at the end of the code, it does not get any funktion.
What am i doing wrong?
<pre class=”lang:probuilder decode:true “>// trailing stop function
trailingstep = 6 //5 trailing step to move the “stoploss” after BreakEven
startBreakeven = 2 //5 pips in gain to activate the breakeven function
PointsToKeep = 2 //3 pips to keep in profit above/below entry price when the breakeven is activated
//
//reset the stoploss value
IF NOT ONMARKET THEN
newSL = 0
breakevenLevel = 0
ENDIF
//******************************************************************************************************
// —– BREAKEVEN code
//
//reset the breakevenLevel when no trade are on market
// — LONG side
IF LONGONMARKET AND (close – tradeprice(1)) >= (startBreakeven * pipsize) AND breakevenlevel = 0 THEN
breakevenLevel = tradeprice(1) + (PointsToKeep * pipsize) //calculate the breakevenLevel
ENDIF
// — SHORT side
IF SHORTONMARKET AND (tradeprice(1) – close) >= (startBreakeven * pipsize) AND breakevenlevel = 0 THEN
breakevenLevel = tradeprice(1) + (PointsToKeep * pipsize) //calculate the breakevenLevel
ENDIF
//Set new Stop Loss
IF breakevenLevel > 0 THEN
newSL = BreakEvenLevel
ENDIF
//******************************************************************************************************
// —– TRAILING STOP code
//
//manage long positions
IF LONGONMARKET AND BreakEvenLevel THEN
//next moves after BreakEven
IF newSL > 0 AND ((close – newSL) >= (trailingstep * pipsize)) THEN
newSL = newSL + (trailingstep * pipsize)
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET AND BreakEvenLevel THEN
//next moves after BreakEven
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
SELL AT newSL STOP
EXITSHORT AT newSL STOPSET STOP LOSS 32
ENDIF
02/22/2018 at 3:59 PM #63540To write code, please use the <> “insert PRT code” button.
Thank you.
02/22/2018 at 4:15 PM #63543You shouldn’t place your SL there! That code is made to handle customized trailing stops/breakeven and is ready-to-use, so you’d better not change it unless you are aware of what you are doing.
Put where else you want, usually at the end of your strategy.
Just search any strategy in the library and study where other members place their code, you’ll learn how it is structured.
02/22/2018 at 9:18 PM #63582Hi,
Just a quick visit now, so I haven’t read the entire thread. But I wrote this a while ago, I hope it might help:
Dynamic SL12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697SL = 20 // Initial SLTP = 30TSL = 1 // Use TSL?TrailingDistance = 20 // Distance from close to TSLTrailingStep = 3 // Pips locked at start of TSL//************************************************************************IF TSL = 1 THEN//reset the stoploss valueIF NOT ONMARKET THENnewSL = 0CAND = 0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL = 0 AND CLOSE - TRADEPRICE(1) >= TrailingDistance*PipSize THENnewSL = TRADEPRICE(1) + TrailingStep*PipSizeENDIF//next movesCAND = BarIndex - TradeIndexIF newSL > 0 AND CLOSE[1] >= HIGHEST[CAND](CLOSE) THENnewSL = CLOSE[1] - TrailingDistance*PipSizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL = 0 AND TRADEPRICE(1) - CLOSE[1] >= TrailingDistance*PipSize THENnewSL = TRADEPRICE(1) - TrailingStep*PipSizeENDIF//next movesCAND = BarIndex - TradeIndexIF newSL > 0 AND CLOSE[1] <= LOWEST[CAND](CLOSE) THENnewSL = CLOSE[1] + TrailingDistance*PipSizeENDIFENDIF//stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFSET STOP pLOSS SLENDIFSL = 20 // Initial SLTP = 30TSL = 1 // Use TSL?TrailingDistance = 20 // Distance from close to TSLTrailingStep = 3 // Pips locked at start of TSL//************************************************************************IF TSL = 1 THEN//reset the stoploss valueIF NOT ONMARKET THENnewSL = 0CAND = 0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL = 0 AND CLOSE - TRADEPRICE(1) >= TrailingDistance*PipSize THENnewSL = TRADEPRICE(1) + TrailingStep*PipSizeENDIF//next movesCAND = BarIndex - TradeIndexIF newSL > 0 AND CLOSE[1] >= HIGHEST[CAND](CLOSE) THENnewSL = CLOSE[1] - TrailingDistance*PipSizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL = 0 AND TRADEPRICE(1) - CLOSE[1] >= TrailingDistance*PipSize THENnewSL = TRADEPRICE(1) - TrailingStep*PipSizeENDIF//next movesCAND = BarIndex - TradeIndexIF newSL > 0 AND CLOSE[1] <= LOWEST[CAND](CLOSE) THENnewSL = CLOSE[1] + TrailingDistance*PipSizeENDIFENDIF//stop order to exit the positionsIF newSL > 0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFSET STOP pLOSS SLENDIFI hope it might help you!
-
AuthorPosts
Find exclusive trading pro-tools on