CurrentTime_s

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

CurrentTime_s

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?

bowlesj3
Posts: 2016
Joined: 21 Jul 2007
Has thanked: 171 times
Been thanked: 402 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
    begin
    If whateverOtherConditions = true then
        begin
        {Buy/Sell or whatever go below this comment before the end}
        end;
    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.

geektrader
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 //

end;

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;
End;


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.

t123knight
Posts: 50
Joined: 11 Nov 2005
Contact:

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.

THANK YOU!!!

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

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”