Hi everyone,
I would like to insert in this code, that if after a certain amount of time i’m still in position, it is automatically closed,
I have tried but have not succeeded until now
if you can, thank you very much
Alex
a=endpointaverage[x] (close)
if a[1]<a then
alex=200
endif
if a[1]>a then
alex=100
endif
if longonmarket then
a=1
endif
if shortonmarket then
a=2
endif
if alex crosses over 150 and countofposition=0 then
exitshort at market
buy at market
b= currenttime
endif
if alex crosses under 150 and countofposition=0 then
sell at market
sellshort at market
b= currenttime
endif
SET TARGET $PROFIT 10
SET STOP $LOSS 200
if a=1 and b+010000 = currenttime then
sell at market
endif
if a=2 and b+010000 = currenttime then
exitshort at market
endif
Just add this to your code
if onmarket and (BarIndex - TradeIndex) >=barnumber then
sell at market
exitshort at market
endif
Insert instead of “bar number” your desired quantity; keeping in mind that based on the timeframe of the strategy you have to calculate how many “bar numbers” you need to preset the position stop.
i.e.: on a 5min strategy, 5 bar numbers will be equivalent to 25 minutes.