Questions about MultiCharts and user contributed studies.
Posts: 50
Joined: 11 Nov 2005


Postby t123knight » 14 Mar 2010

I'm trying to get my signals to filter out trades for certain times of the day (I don't want my signals taking trades in pre of after markets). In my conditional statement I tried to do the following

if CurrentTime_s>=930000 and Current time and current time_s<1600000 and condition1 and condition2 then
Buy etc...

This doesn't seem to be working. Has anyone tried doing this?

Posts: 1976
Joined: 21 Jul 2007
Has thanked: 155 times
Been thanked: 395 times

Postby bowlesj3 » 14 Mar 2010

I think it is your extra if tests. Is this not what you want?

Code: Select all

if CurrentTime_s >= 93000 and CurrentTime_s < 160000 then
    If whateverOtherConditions = true then
        {Buy/Sell or whatever go below this comment before the end}

Also note that 1600000 has one too many zeros. It has to be 6 digits in total for the currenttime_S command and 4 digits for the currenttime command. Programs do not like errors like that. I fixed it in my code.

I just noticed as well that you had an extra zero in the 930000 so I dropped it down to the correct number. Currenttime_s is a numeric field so leading zeros are removed unless there is only one zero in the time.

So just pretend it is 09:30:00 or HH:MM:SS with the colons removed then you can remove the leading zeros if you want.

Posts: 100
Joined: 17 Jul 2009
Location: Germany

Postby geektrader » 14 Mar 2010

Yes, I do it this way:

Add To Inputs Section:

Code: Select all

input:   Pause_Start( 1650 );
input:     Pause_End( 1739 );
input:     Pause_Start2 ( 2350 );
input:     Pause_End2 ( 2359 );
input:     Pause_Start3 ( 0000 );
input:     Pause_End3 ( 0039 );
var: Trade(false);

Before your current code you add:

Code: Select all

Trade=( Time < Pause_Start Or Time > Pause_End ) And ( Time < Pause_Start2 Or Time > Pause_End2 ) And ( Time < Pause_Start3 Or Time > Pause_End3 );

if Trade then begin

// Your Existing Code Starts Here //

At the end of your existing code you add:

Code: Select all

// Your Existing Code Ends Here //


if Trade=false then begin
if MarketPosition = 1 Then Sell ( "TimeExitLX" ) next bar at market;
if MarketPosition = -1 Then Buy To Cover ( "TimeExitSX" ) next bar at market;

What this will do is to NOT trade during the "Pause_Start" and "Pause_End" times. It will also exit any open trades at the time each Pause starts.

You can of course also extend this with more pause times if you need to. In my example I trade Forex with IB and exist right before session end as well as before midnight since IB server does maintenance then. To exit before midnight and not trade after midnight you have to use 2 pause times, since Easylanguage can´t accept a pause-time starting before midnight and ending after midnight. Hence the 2 pause-times directly tight together.

Posts: 50
Joined: 11 Nov 2005

Postby t123knight » 14 Mar 2010

Hey Guys,

Thank you both for the input. The pause and start worked the best for what I'm doing. It you didn't tell me about easy-language not allowing a pause that runs before and after mid night, I would have spent days working on it before I figured it out.


User avatar
Bruce DeVault
Posts: 438
Joined: 19 Jan 2010
Location: Washington DC
Been thanked: 2 times

Postby Bruce DeVault » 15 Mar 2010

You can have one time range that begins before and ends after midnight - you just have to check for the sequence of the start being after the end as an additional consideration.

As an example, "if starttime > endtime and (time >= starttime or time < endtime) then ...".

In this way, starttime might be set to 2300 and endtime might be set to 0100, and times between those two will be detected correctly.

Return to “MultiCharts”