Do you need to insert a time slot for a Tradestation or MultiCharts indicator or trading system? With StartTime and EndTime in EasyLanguage, it will be straightforward.

We create a simple indicator that draws a histogram within a given time session.

EasyLanguage StartTime EndTime Indicator Tradestation Multicharts basic code

The code is straightforward:

Inputs:
StartTime(2300),
EndTime(1200);

If Time > StartTime and Time < EndTime then
Plot1(1);
End;

We have received many emails because many users do not know how to solve the problem of a StartTime < EndTime.

For example, suppose we want to start a session from 22:00 to 12:00 in the next day.

In this case, our code would not work because StartTime is bigger than EndTime.

EasyLanguage StartTime EndTime Indicator Tradestation Multicharts

 

There are various ways to solve this problem; we have created this simple code:

 

// EasyLanguage StartTime EndTime 

Inputs:
StartTime(2300),
EndTime(1200);

If StartTime > EndTime then Begin
If (Time > StartTime and Time < 2359) or (Time >= 000 and Time < EndTime) then
Plot1(1);
End;

If StartTime < EndTime then Begin
If Time > StartTime and Time < EndTime then
Plot2(1);
End;

What if we wanted to use this code to open positions or for something else?

You will need to create a handy true false function.

// EasyLanguage StartTime EndTime 

inputs:
StartTime(numericsimple),
EndTime(numericsimple);

If StartTime > EndTime then Begin
If (Time > StartTime and Time < 2359) or (Time >= 000 and Time < EndTime) then
BoxTime=true
Else
BoxTime=False;
End;

If StartTime < EndTime then Begin
If Time > StartTime and Time < EndTime then
BoxTime=true
Else
BoxTime=False;
End;

This function can be used both for an indicator and for a strategy.

Here’s how the indicator becomes simple using the function:

// EasyLanguage StartTime EndTime 

Inputs:
StartTime(2300),
EndTime(1200);

If BoxTime(StartTime,EndTime) Then
Plot1(1);

With this function we can, for example, create a strategy that buys and sells at a certain time.

We can use the function both as a filter to allow us to open new positions only in a certain period.

For example, we will write:
If RSI> 90 and BoxTime = True then ……

This function allows for endless uses. Remember that creating a special function is always the optimal choice.

The code of your indicator or strategy will remain cleaner and more understandable.

EasyLanguage Bar DateTime

BarDateTime is an EasyLangauge Reserved Word that references the DateTime object properties for a specific bar.

BarDateTime[BarsAgo].FieldName

You can use all this FieldName:

ELDate
ELDateTimeEx
ELTime
Hour
Minute
Second

Print(BarDateTime.Hour:4:0, ” “,BarDateTime.Minute:4:0, ” ” ) ;

 

 

Do you want to learn EasyLanguage & PowerLanguage for TradeStation and MultiCharts? Start here:

 

More resources Click Here

Leave a Reply