Hey guys, I have a quick question about SL and TP. Is it possible to have one SL/TP for the long side and one for the short side in the same code? 🙂
Like this:
// Stops and targets
SLL = 50
TPL = 50
if longonmarket then
SET STOP pLOSS SLL
sET TARGET pPROFIT TPL
ENDIF
SLS = 40
TPS = 40
if SHORTonmarket then
SET STOP pLOSS SLS
sET TARGET pPROFIT TPS
ENDIF
It is possible but you can not use the SET command. Look here:
SLL = 50
TPL = 50
if longonmarket then
sell at TPL limit
sell at SLL stop
ENDIF
SLS = 40
TPS = 40
if SHORTonmarket then
exitshort at TPS limit
exitshort at SLS stop
ENDIF
@Despair
Thanks for answering the Joachim’s question but I do not understand your code. The code Joachim shared in his post should work fine to me.
In your code:
SLL = 50
TPL = 50
if longonmarket then
sell at TPL limit
sell at SLL stop
ENDIF
the long orders will close at 50, which will never be possible if the current instrument quote at 13000 for instance. I think Joachim would like to set its takeprofit and stoploss in points, not in price.
You are correct Nicolas. I forgot to add the trade price. The think Joachim wanted to achieve is that he has different TP and SL for short and long.
SLL = 50*pipsize
TPL = 50*pipsize
if longonmarket then
sell at TPL+tradeprice(1) limit
sell at tradeprice(1)-SLL stop
ENDIF
SLS = 40*pipsize
TPS = 40*pipsize
if SHORTonmarket then
exitshort at tradeprice(1)-TPS limit
exitshort at tradeprice(1)+SLS stop
ENDIF