PaulParticipant
Master
Hi
If I run a intraday strategy it has to perform with a stoploss of 1%
Still I like to reduce that, but not with standard optimisation.
An idea I thought of is reducing it based on time.
But if a trade continues to a new day, it starts again using the wrong stoploss.
What is the best way to prevent that?
Perhaps this may not be a good idea because it creates variables, but still I’am interested to see how it works out.
set stop %loss sl
if reducestoploss then
If onmarket and barindex > tradeindex then
if time = 100000 and (positionperf*100) > sl-(x*2) then
set stop %loss sl-(x*2)
endif
if time = 113000 and (positionperf*100) > sl-(x*3) then
set stop %loss sl-(x*3)
endif
if time = 133000 and (positionperf*100) > sl-(x*4) then
set stop %loss sl-(x*4)
endif
if time = 150000 and (positionperf*100) > sl-(x*5) then
set stop %loss sl-(x*5)
endif
endif
endif
What is the best way to prevent that?
Flag the date in a variable the first time you change the stoploss, and check if it has changed when you are on market.
PaulParticipant
Master
Thanks for the usefull feedback! I was wrong in my approach.
The code below should do the job.
reducestoploss=1 ( 0=disabeld)
// build-in exit
if not onmarket then
flag=0
endif
sl=1.00
x=0.1
if reducestoploss then
If onmarket then
if flag=0 and time = 100000 then
set stop %loss sl-(x*2)
flag=1
endif
if flag=1 and time = 113000 then
set stop %loss sl-(x*3)
flag=2
endif
if flag=2 and time = 133000 then
set stop %loss sl-(x*4)
flag=3
endif
if flag=3 and time = 150000 then
set stop %loss sl-(x*5)
flag=4
endif
endif
else
set stop %loss sl
endif