Hi , Anyone can help with the below code please??
the idea is to not exit a position if it is still going your way. So if longonmarket and it is in profit (+15 points) then update the target profit to 50 and only exit when the candle finishes lower than the previous candle.
if longonmarket and close[0]-positionprice>15 then
set target profit 40
if close[0]<lowest[1] then
sell countofposition contracts at market
endif
endif
Not sure what is wrong, but it only changes the target profit and the second condition doesnt work.
Try this:
if not OnMarket then
flag = 0
endif
if longonmarket and close[0]-positionprice>15 then
set target profit 40
flag = 1
endif
if close[0]<lowest[1] and flag then
sell countofposition contracts at market
endif
Intressting topic. An active TP need an active SL too.
How do u manage SL in ur strategy Amin1233?
Hi Roberto. Still not working. I try to only add the second part to test and it just doesnt make any difference to the result which is impossible.
if not OnMarket then
flag = 0
endif
if longonmarket and close[0]-positionprice>15 then
flag = 1
endif
if close[0]<lowest[1] and flag then
sell countofposition contracts at market
endif
Murre, I dont change the SL.In this strategy you wouldnt need Stop loss because when the price goes below the last bar it should exit.
Hi, “candle finishes lower than previous candle” is close[0]<low[1], not close[0]<lowest[1]
Hi,
The code above is a great idea but it is not working for me.
Below the code I testen and the target is not moving despite of the fact that the close(0) – positionprice > 5
What is wrong with the code?
//profit & loss
SET TARGET PROFIT 40
SET STOP pLOSS 20
if not OnMarket then
flag = 0
endif
if longonmarket and close[0]-positionprice>5 then
set target profit 50
flag = 1
endif
if close[0]<low[1] and flag then
sell countofposition contracts at market
endif
JSParticipant
Senior
Hi @RichardVeen
Remove the “Set Target Profit 40” at the top of your code.
(Otherwise it will reset every time to 40)
Yes, you are right, it is working!
Thanks!