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.
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.

There are various ways to solve this problem; we have created this simple code:
Input:
MA_length(20);
vars:
MA(0),
color(white);
MA = average(Close, MA_length);
If MA>MA[1] and MA[1]>MA[2] then
color = Green;
If MA<MA[1] and MA[1]<MA[2] then
color = Red;
Plot1( MA, “MA”,color,0,3 );
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, ” ” ) ;
More from Finance Strategy System
- EasyLanguage & PowerLanguage Master Tutorial
- The American Association of Individual Investors (AAII)
- BOLLINGER BANDS FORMULA and CALCULATION
- TradeStation Strategy – Bollinger Bands Reversal Price Exit Setup
- New Highs New Lows Indicator || Technical Analysis Tutorial
- The TRIX || Triple Exponential Average Indicator || Tutorial
- All about the Trend in Technical Analysis || Essential Tutorial
- Graphic Technical Analysis – How to read a stock market charts
- Intermarket Analysis || Stocks, Bonds & Commodities – Tutorial
- Free TradeStation Indicators
- Stochastic Indicator | Technical Analysis Tutorial
- Breakout and Pullback in Technical Analysis
- More resources Click Here