Hey guys!
I got this code for trailing, and it works as it should in index markets, but for forex, it has no affect, it doesn’t work, no matter whatever values you put in it.
Can someone please help me with this problem? I’d really appreciate it!
Heres the FULL code!
//trailing stop 1
trailingstop1 = 70
bottomTrailingStopValue1 = 30
TopTrailingStopValue1 = 70
//trailing stop 2
//trailingstop2 = 10
//bottomTrailingStopValue2 = 71
//TopTrailingStopValue2 = 150"
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE1 = 0
priceexit1 = 0
endif
a = close-tradeprice(1) > bottomTrailingStopValue1*pointsize
b = close-tradeprice(1) < TopTrailingStopValue1*pointsize
//case LONG order
if longonmarket then
MAXPRICE1 = MAX(MAXPRICE1,close) //saving the MFE of the current trade
if a and b then
if MAXPRICE1-tradeprice(1)>=trailingstop1*pointsize then //if the MFE is higher than the trailingstop then
priceexit1 = MAXPRICE1-trailingstop1*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit1>0 then
EXITSHORT AT priceexit1 STOP
SELL AT priceexit1 STOP
endif
//resetting variables when no trades are on market
//if not onmarket then
//MAXPRICE2 = 0
//priceexit2 = 0
//endif
//a2 = close-tradeprice(1) > bottomTrailingStopValue2*pointsize
//b2 = close-tradeprice(1) < TopTrailingStopValue2*pointsize
//case LONG order
//if longonmarket then
//MAXPRICE2 = MAX(MAXPRICE2,close) //saving the MFE of the current trade
//if a2 and b2 then
//if MAXPRICE2-tradeprice(1)>=trailingstop2*pointsize then //if the MFE is higher than the trailingstop then
//priceexit2 = MAXPRICE2-trailingstop2*pointsize //set the exit price at the MFE - trailing stop price level
//endif
//endif
//endif
//exit on trailing stop price levels
//if onmarket and priceexit2>0 then
//EXITSHORT AT priceexit2 STOP
//SELL AT priceexit2 STOP
//endif
This is a ProOrder question rather than a General Trading Discussion topic so I have moved it to that forum.
Also please use the ‘Insert PRT Code’ button when putting code in your post. I have tidied up your post for you 🙂
Try using pipvalue or pointvalue (instead of pointsize) and let us know how you get on … better, worse or same!? 🙂
Same, doesnt work unfortunately
Is there any code you are not showing above?
FX does not have volume with IG, that was the first thing I looked for. You are not using volume or an indicator that needs volume are you?
just tested it with a simple buy over bollinger cross, and realised it doesnt work..
Value in line 2 is too big, since it is = TopTrailingStopValue1, thus line 24 bwill never be true.
Try any value between 31 and 69.
“It doesn’t work, no matter whatever values you put in it”
I have tried this either on Dax h1 and Eur/Usd h1, and it always worked with a value of trailingstop1 = 40:
DEFPARAM CumulateOrders = False
trailingstop1 = 40
bottomTrailingStopValue1 = 30
TopTrailingStopValue1 = 70
if not onmarket then
MAXPRICE1 = 0
priceexit1 = 0
endif
a = close-tradeprice(1) > bottomTrailingStopValue1*pointsize
b = close-tradeprice(1) < TopTrailingStopValue1*pointsize
if longonmarket then
MAXPRICE1 = MAX(MAXPRICE1,close) //saving the MFE of the current trade
if a and b then
if MAXPRICE1-tradeprice(1)>=trailingstop1*pointsize then //if the MFE is higher than the trailingstop then
priceexit1 = MAXPRICE1-trailingstop1*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
endif
if onmarket and priceexit1>0 then
EXITSHORT AT priceexit1 STOP
SELL AT priceexit1 STOP
endif
IF close CROSSES OVER average[20,0](close) THEN
BUY AT MARKET
SET TARGET pPROFIT 250
SET STOP pLOSS 200
ENDIF
graph a
graph b
graph MAXPRICE1
graph priceexit1
graph MAXPRICE1-tradeprice
did you use GRAPH?
Roberto version code above works for me also on Dax h1 and Eur/Usd h1.
For interest, equity curve on the Dow over 10k bars attached.
but one the one i posted, u can have bottomtrail twice, on the one u sent, its bottomtrail once only. i want two different trail stops, can u add it for me on the one that works? 🙂