Trailing Stop code don’t work
Forums › ProRealTime English forum › ProOrder support › Trailing Stop code don’t work
- This topic has 5 replies, 3 voices, and was last updated 2 years ago by RichardVeen.
-
-
01/11/2022 at 8:30 PM #185186
Hi,
I don’t get it, I use the Trailing Stop code but it don’t work.
What did I wrong?
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the “stoploss”// Position Size
possize=1MA = average[50]
//profit & loss
SET TARGET PROFIT 20
SET STOP pLOSS 20//order launch (example) would be set to any other entry conditions
c1 = close>close[1]if c1 AND CLOSE>MA then
BUY 1 LOT AT MARKET//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pointsize THEN
newSL = tradeprice(1)+trailingstep*pointsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pointsize THEN
newSL = newSL+trailingstep*pointsize
ENDIF
ENDIF
endif//order launch (example) would be set to any other entry conditions
c2 = close<close[1]if c2 AND CLOSE<MA then
SELLSHORT 1 LOT AT MARKET//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pointsize THEN
newSL = tradeprice(1)-trailingstep*pointsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pointsize THEN
newSL = newSL-trailingstep*pointsize
ENDIF
ENDIF//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIFENDIF
01/11/2022 at 8:47 PM #18518701/11/2022 at 9:11 PM #185190Hi,
I tested with 5/1 and it not working.
01/11/2022 at 9:22 PM #18519112345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667trailingstart = 5 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"// Position Sizepossize=1MA = average[50]//profit & lossSET TARGET PROFIT 20SET STOP pLOSS 20//order launch (example) would be set to any other entry conditionsc1 = close>close[1]if c1 AND CLOSE>MA thenBUY 1 LOT AT MARKET//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice>=trailingstart*pointsize THENnewSL = tradeprice+trailingstep*pointsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pointsize THENnewSL = newSL+trailingstep*pointsizeENDIFENDIFendif//order launch (example) would be set to any other entry conditionsc2 = close<close[1]if c2 AND CLOSE<MA thenSELLSHORT 1 LOT AT MARKET//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pointsize THENnewSL = tradeprice(1)-trailingstep*pointsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pointsize THENnewSL = newSL-trailingstep*pointsizeENDIFENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFgraph newsl01/11/2022 at 9:27 PM #18519301/30/2022 at 2:43 PM #187071 -
AuthorPosts
Find exclusive trading pro-tools on