Time based exit  [SOLVED]

Questions about MultiCharts and user contributed studies.
ravel44
Posts: 28
Joined: 05 Jul 2012
Has thanked: 7 times

Time based exit

Postby ravel44 » 19 Aug 2013

I'm trying to put a time based exit in my strategy, I want the strategy to exit a position 6 days after the entry, I didn't manage to find the vocabulary to do this.
Basically it would say:

IF marketposition(0)= 1 AND "it's been 6 days since the entry"
THEN Sell This Bar

Thank U for helping me to translate "it's been 6 days since the entry" in EasyLanguage

bstrader
Posts: 15
Joined: 25 Jul 2012
Has thanked: 5 times
Been thanked: 1 time

Re: Time based exit  [SOLVED]

Postby bstrader » 19 Aug 2013

You can use BarsSinceEntry to do that. However it will only work, if you use it on a daily chart.

Code: Select all

if BarsSinceEntry > 5
then begin
sell 5 contracts next bar at market;
end;
A workaround for use with e.g. 5minute bars would be.

Code: Select all

vars:
days_since_entry (0);

if marketposition=0 and days_since_entry > 0 then days_since_entry=0;

if marketposition <> 0
and date[0]>date[1]
then days_since_entry=days_since_entry+1;

if days_since_entry > 5
then begin
sell 5 contracts next bar at market;
end;

ravel44
Posts: 28
Joined: 05 Jul 2012
Has thanked: 7 times

Re: Time based exit

Postby ravel44 » 19 Aug 2013

Thank U !

Karax
Posts: 3
Joined: 04 May 2023
Has thanked: 1 time
Been thanked: 1 time

Re: Time based exit

Postby Karax » 04 May 2023

Searching I found this topic but thought it's a little bit complicated. I figured out that the following code does the same in just one line of code. Maybe it's helpful for someone.

Code: Select all

Floor(datetime) - Floor(entrydatetime)


Return to “MultiCharts”