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=1
MA = 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
ENDIF
ENDIF
Try the setting 10/1 instead of 5/5.
Hi,
I tested with 5/1 and it not working.
trailingstart = 5 //trailing will start @trailinstart points profit
trailingstep = 5 //trailing step to move the "stoploss"
// Position Size
possize=1
MA = 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>=trailingstart*pointsize THEN
newSL = tradeprice+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
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
graph newsl
exit if newsl>0 from the condition