Session Timing

True System Automation means you program your trading system to start and stop at designated times while you go play golf, right?

This means that in addition to having a Master Enable/Disable switch you need to automate the start and stop of your trading session. For example, you might want to start your session at 9:30 AM and have it automatically end at 4:00 PM.

The code below uses the ParamDate() and ParamTime() to set the session start and stop dates/times, and compares these parameters to the system Date and Time that are returned by the Now() function. It generates various session-states that are displayed in the Title, when you incorporate this code into your system you will use these states to perform specific actions, like Close all Positions, Cancel all Orders, etc. The BlinkText() is not really needed but was thrown in for fun.

function BlinkTextText )
{
ABAxisColor colorWhite;
if( Status("redrawaction") )
{
BlinkStateStaticVarGet("BlinkState");
if( IsNullBlinkState) ) StaticVarSet("BlinkState"False);
if( BlinkState )
{
Text EncodeColor(colorBrightGreen)+Text+EncodeColor(ABAxisColor);
StaticVarSet("BlinkState"False);
}
else
{
Text EncodeColor(ABAxisColor)+Text;
StaticVarSet("BlinkState"True);
}
}
return Text;
}
RequestTimedRefresh);
DisableSessionTiming ParamToggle("Auto Session Timing","ENABLED|DISABLED",1);
ParamDateNumber  ParamDate("Date"Now(1), 0);
ParamStartTime   ParamTime("Start","09:30:00");
ParamEndTime   ParamTime("End","15:59:00");
RTTimeNumber  Now(4);
RTDateNumber  Now(3);
InSessionDate  RTDateNumber == ParamDateNumber;
PreSessionTime  RTTimeNumber &ltParamStartTime;
PostSessionTime  RTTimeNumber &gtParamEndTime;
InSessionTime  NOT PreSessionTime OR PostSessionTime );
PrevInSession   StaticVarGet("InSession");
if( DisableSessionTiming )  InSession 1;
else     InSession InSessionDate AND InSessionTime;
StartSessionTrigger LastValue(InSession) &gtPrevInSession;
EndSessionTrigger LastValue(InSession) &ltPrevInSession;
StaticVarSet("InSession"InSession);
OutOfSessionColor  ParamColor("Out of Session",colorBlack);
PlotNOT InSession,"",colorBlack,styleArea|styleOwnScale|styleNoLabel,0,1);
Title "\n"+BlinkTextNow(0) )+"\n"+
"Session Status: "+
WriteIfDisableSessionTiming"Session Timing Disabled",
WriteIfNOT InSessionDate,"Out of Session date, ","")+
WriteIf(PreSessionTime AND InSessionDate,"Waiting for Start, ","")+
WriteIf(StartSessionTrigger"Start Trigger, ","")+
WriteIf(InSessionTime"In Progress, ","")+
WriteIf(EndSessionTrigger"End Trigger, ","")+
WriteIf(PostSessionTime"Completed",""));

Edited by Al Venosa

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.40 out of 5)
Loading...Loading...

Comments are closed.