Time between trades

Questions about MultiCharts and user contributed studies.
paulc
Posts: 59
Joined: 26 Sep 2012
Has thanked: 13 times
Been thanked: 2 times

Time between trades

Postby paulc » 18 Apr 2013

I'm trying to create a minimum gap between trades being triggered in a strategy. The following is supposed to stop 2 trades occurring within a 5 minute interval but it doesn't work; i.e trades can be triggered one minute after the previous trade. There is no exit trade, a trade is always open, either long or short.

Code: Select all

if currenttime > starttime and currenttime - value1 > 4 and currenttime < lastordertime then begin

[buy/sell trigger code]

end;
Thanks.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Time between trades

Postby Henry MultiСharts » 19 Apr 2013

Hello paulc,

Please provide a complete code for replicating the behavior. Attach a full sized screenshot and detailed description of how do you expect the code to work and what does not work exactly.
Specify your chart resolution and whether you are using IOG or not.

paulc
Posts: 59
Joined: 26 Sep 2012
Has thanked: 13 times
Been thanked: 2 times

Re: Time between trades

Postby paulc » 19 Apr 2013

Sorry, value1=entrytime. the instrument is set to exchange time so i expect that is where the issue is arising. i need to offset the time.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Time between trades

Postby Henry MultiСharts » 30 Apr 2013

If your chart is in exchange time then in the code you are operating with time values in exhcange time timezeone.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Re: Time between trades

Postby SUPER » 01 May 2013

paulc,

Maybe you can use "BarsSinceEntry"

if MarketPositon<>1 and condition1 then buy next bar at market; // your first entry

if MarketPosition > 0 and BarsSinceEntry >= 1 {what ever gap} and condition1 then buy next bar at market; // your additional entries

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Time between trades

Postby JoshM » 08 May 2013

I'm trying to create a minimum gap between trades being triggered in a strategy. The following is supposed to stop 2 trades occurring within a 5 minute interval but it doesn't work; i.e trades can be triggered one minute after the previous trade. There is no exit trade, a trade is always open, either long or short.

Code: Select all

if currenttime > starttime and currenttime - value1 > 4 and currenttime < lastordertime then begin

[buy/sell trigger code]

end;
The problem with using 'currenttime' and 'lastordertime' is that these are in HHmm or HHmmss format, which means that you can not perform mathematical operations on these (i.e., 1002 [10:02 am] - 5 [minute] = 997 instead of 957 [9:57 am]).

To solve this, you'll need to convert this to DateTime. See the wiki for the related reserved words for this: Date & Time routines.

Edit: In this context, also see the PosTradeExitDateTime reserved word.


Return to “MultiCharts”