Code break of x periode of time after trade closed

Questions about MultiCharts and user contributed studies.
evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Code break of x periode of time after trade closed

Postby evdl » 16 Jul 2012

I saw some examples of suspending trading after a certain amount of loss or certain amount of trades.

What I would like is to suspend trading after a trade is closed (loss or profit, doesn't mind) for 15min or 30 min etc. I think I need to set a variable to the closing of a trade. So I can relate to that variable.

any ideas?

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Code break of x periode of time after trade closed

Postby evdl » 16 Jul 2012

Maybe the penny dropped:

Code: Select all

Input: suspend_time(15)
Variables: suspend_trigger(false), freeze_time(0);

If marketposition[1] <> 0 and marketposition[0] = 0 then begin
Freeze_time = time;
Suspend_trigger = true;

If time - freeze_time > suspend_time then
Suspend_trigger = false;
end;
Use the suspend_trigger = false in the entry conditions.

Will have to test this in my strategy.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: Code break of x periode of time after trade closed

Postby evdl » 17 Jul 2012

I noticed that marketposition(1) does not reference flat positions as the last position. So if the last position was flat and the position before that was short (-1), it will remain showing the short position as the last position and not the real last position (=flat position). You can say a flat position is no position of course, but I needed to add some code to get the suspend time to work properly.

This is the working code:

Code: Select all

Input: suspend_time(15)
Variables: suspend_trigger(false), freeze_time(0), mp_trigger(false);

If marketposition(1) <> 0 and marketposition(0)= 0 and not mp_trigger then begin
mp_trigger = true;
If mp_trigger then
Freeze_time = time;
Suspend_trigger = true;
end;

If mp_trigger then begin
If time - freeze_time >= suspend_time then
Suspend_trigger = false;
end;

If not suspend_trigger then begin
Freeze_time = 0;
mp_trigger = false;
end;
and put the suspend_trigger = false in the entry conditions of your strategy.


Return to “MultiCharts”