Time filter for trade frequency

Questions about MultiCharts and user contributed studies.
User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Time filter for trade frequency

Postby MAtricks » 30 Oct 2012

I'd like some help on creating time constraints on the frequency of how often a trade can be entered on tick based bars.

During the news, things can get pretty wacko on tick based bars.

I'd like the strategy to only be allowed to enter a trade every 10 minutes. Any suggestions on how to start this?

Thanks ahead of time!!

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 557 times

Re: Time filter for trade frequency

Postby Andrew MultiCharts » 31 Oct 2012

Hello MAtricks,

You can record the time when your MarketPosition_at_Broker changes, then compare it to your current time and if the current time is >= 10 minutes, then *your script*.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Re: Time filter for trade frequency

Postby MAtricks » 31 Oct 2012

Thank you Andrew.

My problem is isolating the time when an entry is engaged and comparing it to the 10min increment.

if marketposition[1] = 0 and marketposition <> 0 then
//Start the timer - not sure how to do this

if starttime and currenttime >=10 then begin //no clue if I'm thinking right here

//strategy entry code begins here

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Re: Time filter for trade frequency

Postby MAtricks » 01 Nov 2012

Does anyone else have an idea how to get this started?

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Time filter for trade frequency

Postby TJ » 01 Nov 2012

MAtricks wrote:Thank you Andrew.

My problem is isolating the time when an entry is engaged and comparing it to the 10min increment.

if marketposition[1] = 0 and marketposition <> 0 then
//Start the timer - not sure how to do this

if starttime and currenttime >=10 then begin //no clue if I'm thinking right here

//strategy entry code begins here


I would approach the project in these steps:

1. Read the section on Date and Time.
see Post #12: viewtopic.php?f=16&t=6929
eg. You will need to know how to add 10 minute to TIME when the time is 1055.

2. In the strategy, create a counter to hold the time.

3. After each trade, add 10 min to the counter.

4. Start trading again when time is up.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Re: Time filter for trade frequency

Postby MAtricks » 01 Nov 2012

This is what I have and it's compiling, but not doing what I want it to do.

Code: Select all


Variables:
   TimeFilter( false ),
   starttime( 0 ) ;
   
if marketposition[1] = 0 and marketposition = 1 then
      currenttime = starttime ;
      
   if (currenttime - starttime) > 10 then
      timefilter = true ;
   if (currenttime - starttime) < 10 then
      timefilter = false ;

if timefilter = true then begin

{Strategy entry code goes here}


User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Time filter for trade frequency

Postby TJ » 01 Nov 2012

MAtricks wrote:This is what I have and it's compiling, but not doing what I want it to do.

Code: Select all


Variables:
   TimeFilter( false ),
   starttime( 0 ) ;
   
if marketposition[1] = 0 and marketposition = 1 then
      currenttime = starttime ;
      
   if (currenttime - starttime) > 10 then
      timefilter = true ;
   if (currenttime - starttime) < 10 then
      timefilter = false ;

if timefilter = true then begin

{Strategy entry code goes here}



If it is not doing what you want, then why are you using it?

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Re: Time filter for trade frequency

Postby MAtricks » 01 Nov 2012

This thread is a request for help to get this code working as I've stated I want it to work.

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Time filter for trade frequency

Postby TJ » 01 Nov 2012

MAtricks wrote:This thread is a request for help to get this code working as I've stated I want it to work.

Help was given in post #5.
Do you think I wrote that to torture you?
You have totally ignored step #1. If that can be eliminated, please feel free to make it work.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Re: Time filter for trade frequency

Postby MAtricks » 01 Nov 2012

I understand the steps and I thank you for attempting to help, but my problem comes with the EL syntax that I'm not proficient with.

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Time filter for trade frequency

Postby TJ » 01 Nov 2012

MAtricks wrote:I understand the steps and I thank you for attempting to help, but my problem comes with the EL syntax that I'm not proficient with.


I am not a programmer, neither are 99% of the people here.

If you have read the manual and do not understand the operation, we can talk about it.
If you do not want to read and would rather have someone code it for you, that can be arranged too.

User avatar
MAtricks
Posts: 789
Joined: 09 Apr 2012
Has thanked: 286 times
Been thanked: 277 times

Re: Time filter for trade frequency

Postby MAtricks » 01 Nov 2012

Did I offend you?

Code: Select all

Working with Times
In EasyLanguage, times are expressed as numeric expressions in the form HHMM, where
HH is the hour and MM is the minutes. The hours are managed in what is commonly called
24-hour or military format, so 1:30pm is represented as 1330 and 10:05am is represented
as 1005.
In addition, when you work with time, to facilitate mathematical operations such as addition
and subtraction, you can refer to the time as minutes past from midnight. For instance,
1:00am is 60 (60 minutes after midnight), and 10:30am is 630 (630 minutes after midnight).
For example, if the current time is 10:30am (or 1030), and you want to add 60 minutes to
the current time, you may think that you simply add 60 to 1030:
1030 + 60
However, doing so results in a total of 1090, which is not a valid time. Therefore, to add 60
minutes to a time, use minutes after midnight. You would write:
630 + 60
Doing so results in 690. When you convert this number back into time in 24-hour format,
the result is 1130, which is the desired value. Reserved words are provided for you to convert
times back and forth automatically.
The reserved words used to reference and manipulate times are listed next.
This reserved word returns a numeric expression representing the EasyLanguage time
(HHMM format) of the closing price of the current bar.
Syntax:
Time
Parameters:
None.
Example:
For example, you can write your trading signal, analysis technique, or function such that
it only evaluates the EasyLanguage instructions when the trade time is less than 11:00am:
If Time < 1100 Then
{ EasyLanguage instruction } ;
Time
This reserved word returns a numeric value representing the number of minutes elapsed
since midnight for the EasyLanguage time (HHMM format) specified.
Syntax:
TimeToMinutes(eTime)
Parameters:
eTime is a numeric expression representing the EasyLanguage time to be converted into
minutes past midnight.
Example:
The following statement converts the current bar’s time into minutes past midnight, and assigns
the numeric value to a variable (in this case, Value1):
Value1 = TimeToMinutes(Time);
This reserved word returns a numeric expression representing the EasyLanguage time
(HHMM format) equivalent to a specific number of minutes from midnight.
Syntax:
MinutesToTime(mTime)
Parameters:
mTime is a numeric expression representing the minutes past midnight to be converted into
the equivalent EasyLanguage time.
Example:
The following statement converts the current time into minutes past midnight, adds 20 to
it, and then converts the resulting number back into an EasyLanguage time:
Value1 = MinutesToTime(TimeToMinutes(Time) + 20);
The expression within parentheses is evaluated first (the reserved word
TimeToMinutes). It converts the time of the current bar to minutes past midnight. Then,
20 is added to the minutes past midnight, and the resulting number is used as the
parameter for the reserved word MinutesToTime, which converts the number back into
an EasyLanguage time (HHMM format).
This reserved word returns a numeric value representing the EasyLanguage time (HHMM
format) corresponding to the time of your computer (or datafeed, if you are connected to a
datafeed).
Syntax:
CurrentTime
TimeToMinutes(eTime)
MinutesToTime(mTime)
CurrentTime
Parameters:
None.
Example:
To have a trading signal, analysis technique, or function perform its calculations only if
it is before 2:00pm, you can write:
If CurrentTime < 1400 Then Begin
{ EasyLanguage instruction(s) }
End;


I read the manual that you posted. I read it 4 times. It didn't seem relevant to this nor did it give me what I wanted. I was hoping for someone more experienced to reply with a little help. I'm not looking for free code nor do I want to waste anyone's time.

I posted my code and as far as I've gotten. If there is anyone that has tried this before or sees me doing something wrong, I'd appreciate, but not obligate a little help on this.

My goal is to create a filter that filters trades on tick-based bars to only enter after 10 minutes has passed since that last entry.

Here's what I have so far:

Code: Select all


Variables:
   TimeFilter( false ),
   starttime( 0 ) ;
   
if marketposition[1] = 0 and marketposition = 1 then
      currenttime = starttime ;
      
   if (currenttime - starttime) > 10 then
      timefilter = true ;
   if (currenttime - starttime) < 10 then
      timefilter = false ;

if timefilter = true then begin

{Strategy entry code goes here}

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 557 times

Re: Time filter for trade frequency

Postby Andrew MultiCharts » 02 Nov 2012

MAtricks wrote:Thank you Andrew.

My problem is isolating the time when an entry is engaged and comparing it to the 10min increment.

if marketposition[1] = 0 and marketposition <> 0 then
//Start the timer - not sure how to do this

if starttime and currenttime >=10 then begin //no clue if I'm thinking right here

//strategy entry code begins here

You cannot use marketposition[1], you should use it this way:

Code: Select all

var1 = MarketPosition_at_Broker
if var1[1] <> 0 then
*your script*
These users thanked the author Andrew MultiCharts for the post:
MAtricks


Return to “MultiCharts”